Our second team’s robot’s speed is much too high for the robot to be controlled during the manual period, any help would be appreciated. We have no clue on how to change the motor speed under the while (true) statement.
I don’t know what language/interface you’re using, but the changes are all roughly the same. Make approximately the following change:
get rid of
motorSet(1,joystickGetAnalog(1,2));
// That is PROS. The first 1 is the motor’s port. The second 1 indicates primary joystick, not partner. The 2 is the joystick axis.
replace with this (at the beginning):
int motor1Value = 0;
and (in the while loop):
motor1Value = joystickGetAnalog(1,2);
motor1Value = motor1Value/2;
// motor1Value/2 could be any function of motor1Value that does what you desire.
motorSet(1,motor1Value);
As you can see, what you do it take in the input from the joystick’s axis as before, but place it in a variable. Change the variable based on what you want done (half power, power-squared method, etc.). Set the motor to that variable instead of the joystick’s axis.
Basically what @callen said, but in RobotC, as it is the most popular language. When you set your motor speed, instead of writing
motor[chassis_l] = VexRT[Ch3]
, do something like
motor[chassis_l] = VexRT[Ch3] / 2
. That will half the speed of the motor, because the joystick value (
VexRT[Ch3]
) is being divided by two.
If you want to be able to be able to easily change the factor (the number you’re dividing by), declare it in a variable outside of your while loop, e.g.
int motor_factor = 2;
while (true) {
// do stuff here
}
Now you would set the power of your motors with
motor[chassis_l] = VexRT[Ch3] / motor_factor
.
If you are using buttons to control the motors, then ignore everything above and use
motor[chassis_l]
= 64
instead of
motor[chassis_l] = 127
. Just use a number from -127 to 127 (0 being off) to control the power of the motor.
As general good form in coding, I would avoid putting the calculation straight into motor]. If just dividing by an integer, you’re safe. But you can get really wacky behavior with more complex functions, and that includes the relatively simple functions for arcade control. You’re safer only running VexRT] one time for any given channel, storing it, and applying your functions to the stored values.