Here you can find the source of normalize(double wheelSpeeds[])
Parameter | Description |
---|---|
wheelSpeeds | the array of wheel speeds to normalize |
public static void normalize(double wheelSpeeds[])
//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; } } } }