I’m trying to scale the speed of my motors using the joysticks. I’ve seen other post about this but when I try implementing it in to my code errors keep showing up. Any ideas or thoughts are welcome. I’m using C++ and Vex code.
Welcome to the forum. For coding issues it is useful to post the code that is not working so we can better see problems.
When you post code, use three ` before and after to have it
if(`3==true){ formatted as code }
1 Like
from what iv’e seen, and used the forum in the past, no matter what your doing, send pictures and/or videos.
Here’s the code I was using.
JoystickValue = vexRT ;
JoystickValue = vexRT ;
// Use 70% of joystick value as the motor drive value
DT.Value = JoystickValue * 7 / 10;
// Limit to half speed (fwd or rev)
if ( MotorValue) {64}
( MotorValue > 64 )
MotorValue = 64;
if( MotorValue < -64 )
MotorValue = -64;
// Set the motor output
motor DT = MotorValue;```
Sorry, I've haven't been able to get to the laptop with the code on it.
One way is to introduce a variable to set the max speed percentage maxRatio
and multiply that by your controller position.
double maxSpeed = .64;
int leftSpeed = 0;
int rightSpeed = 0;
while (true) {
leftSpeed = ( Controller1.Axis2.position() + Controller1.Axis1.position()) * maxSpeed;
rightSpeed = ( Controller1.Axis2.position() - Controller1.Axis1.position()) * maxSpeed;
LeftMotors.setVelocity(leftSpeed, percent);
RightMotors.setVelocity(rightSpeed, percent);
}