Changing drivetrain Speed during driver control in vexcode c++

With lots of help from members here, I figured out how to adjust the drivetrain speed of a robot with a drivetrain set up and during driver control. I figured I would post it here so that maybe someone else won’t have to spend hours trying to figure it out! Below is a picture of the code that I added. It is configured for a 2 motor tank drive, but could be easily put in 4 motor or arcade. You will have to set up your drivetrain, add a controller, put it on the joysticks, press the plus sign beside pragma at the top to access this section of the code, then key it in to your desired affect. I have mine start at 100% drivetrain speed, then I press a button to change it to either 50 %, 20%, or 100% speed. These values can be changed to whatever you want, and you can even add more if desired. On the picture, the sections that show “//AAAAAAAA” are sections I added as well as the highlighted portions. If you have any questions, I will do my best to answer!!

Unexpected problem. When I close the program and reopen it, it is deleting the code that I add. Is there a way to prevent this from happening?

Are you saving your project before closing VEXcode?

Yes I am. I made sure.

1 Like

in vexcode v5, it deletes when I close and reopen. If I do it in vexcode v5 pro, it will leave it, but I have to enable expert robot configuration.

It’s auto-generated code, you are not supposed to change that. VEXcode will regenerate it as necessary.

1 Like

Is there a way to make it not auto-generate? to keep the changes I make to the robot configuration? Vexcode pro keeps the changes, but I want to be able to do it in vexcode v5 since I primarily use a chromebook and pro is not available on the chromebook.

Don’t use the Devices > Controller configruation to link the Drivetrain to the controller. Code that manually (or cut and paste the code you had above).

void userControl(void) {
  Brain.Screen.clearScreen();
  float rate = 1.0;
  while (true) {
    if(Controller1.ButtonA.pressing()) rate = 0.5;
    if(Controller1.ButtonB.pressing()) rate = 0.75;
    if(Controller1.ButtonX.pressing()) rate = 1.0;

    LeftMotors.setVelocity(Controller1.Axis3.position() * rate, pct);
    RightMotors.setVelocity(Controller1.Axis2.position() * rate, pct);
    wait(20, msec);
  }
}
2 Likes

while this would make coding the rate easier, you would lose the more accurate coding for the drivetrain. Instead of driving forward for 21.5 inches, you would have to rotate both motors forward for a specific degree. Turns and headings also become more difficult without the drivetrain function.

1 Like

So, hypothetically, could we not use this same idea to alter the max torque output in a driver match? I know most people either leave it at the default or max it out, but I have found that the max setting can make the movements jerky and anything less makes going up the platform difficult.

I suppose if I were to add into this format something like

LeftMotors.setMaxTorque(100*rate, percent);
RightMotors.setMaxTorque(100*rate, percent);
1 Like

I was simply following his code pattern. I started with a Drivetrain but reverted to motor groups following the OP example. Also this is Driver Control which wouldn’t need any distance methods.

1 Like