Java Array Normalize normalize(double wheelSpeeds[])

Here you can find the source of normalize(double wheelSpeeds[])

Description

Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.

License

Open Source License

Parameter

Parameter Description
wheelSpeeds the array of wheel speeds to normalize

Declaration

public static void normalize(double wheelSpeeds[]) 

Method Source Code

//package com.java2s;
/* /*from   ww w. ja v a2s. c om*/
 * Copyright (c) 2015 RobotsByTheC. All rights reserved.
 *
 * Open Source Software - may be modified and shared by FRC teams. The code must
 * be accompanied by the BSD license file in the root directory of the project.
 */

public class Main {
    /**
     * Normalize all wheel speeds if the magnitude of any wheel is greater than
     * 1.0.
     *
     * @param wheelSpeeds the array of wheel speeds to normalize
     */
    public static void normalize(double wheelSpeeds[]) {
        double maxMagnitude = Math.abs(wheelSpeeds[0]);
        int i;
        // Loops through each number to find the beggest absolute value.
        for (i = 1; i < wheelSpeeds.length; i++) {
            double temp = Math.abs(wheelSpeeds[i]);
            if (maxMagnitude < temp) {
                maxMagnitude = temp;
            }
        }
        // If the maximum is greater than 1.0, reduce all the values down
        // proportionally so the maximum becomes 1.0.
        if (maxMagnitude > 1.0) {
            for (i = 0; i < wheelSpeeds.length; i++) {
                wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude;
            }
        }
    }
}

Related

  1. normaliseHeaders(String[] headers)
  2. normaliseSum(double[] a)
  3. normaliseUnicode(String unicodeText, char[] mappings)
  4. normalize(byte[] data, byte maximum, byte minimum)
  5. normalize(double arr[])
  6. normalize(double[] a)
  7. normalize(double[] a)
  8. normalize(double[] a)
  9. normalize(double[] a)