Adjust drivetrain speed in driver control

Been coding with blocks for years and am converting to vexcode text c++.
There is one thing that I cannot figure out how to do and cannot find the topic here even though I am sure it has been answered somewhere.

I using the drivetrain function so that autonomous coding is easier, but I also want to be able to adjust the speed of the drivetrain in driver control. If someone can show me how to reference the individual motors in driver control so that I can either adjust the drivetrain speed down or be able to change speed during the match, that would be awesome!

1 Like

So, I am assuming you are coding in VexCode. When you define the motors for the drivetrain, the first motor you define is called leftMotorA, the second one is leftMotorB, the third is rightMotorA, and the last one is rightMotorB. You can control these indepent of the drivetrain as long as you know what the ports are for each of those.

If you just want to change the speed for the drivetrain code then seeing the code would be helpful.

1 Like

show your code first please


image

Here is a basic code with an auton and my device setup.

So, if you just want to change the speed in driver control, then you do exactly what you did in autonomous. (I think). If that doesn’t work there are other solutions but I would try that.

1 Like

I have tried that, but the setDrivetrain only works in autonomous.

Ok, so up at the top, where you see the # pragma, hit the plus button next to that. From there you should be able to find the spot where it is setting up your drive train drive. if you multiply the axis values by 0.95, that will reduce the speed to 95 percent, and 0.85 is 85 and so on.

Should look something like this

1 Like

Usually you control the drive speed with joystick, which you can achieve with controller configuration. @EH-Coder gives example for the arcade drive. You can choose arcade or tank drive.

I am able to set the drivetrain control to arcade or tank. That is not the problem. I want to be able to change the max velocity of the drivetrain in driver control.

I will give that a shot next period. Thank you! I don’t remember ever seeing the motors themselves as options before today!

This worked to slow down the drivetrain!! Thank you! Can you think of a way to change the decimal during a match? We want to be able to have a fast drivetrain during the first part of the match, but slow it down to 20% when we are trying to balance our robot on top of the platform for tipping point.

possibly running a mapping the two modes to a button? Such as, if

if (ButtonA.pressing()){
//set the velocity to 20% as  shown before
}
else{
//have the default settings up
}

This is a simple solution, but as long as you don’t need to alter speed a lot it works fine

1 Like

You could do what EH-Coder said

More specifically, you could have a variable

double drivetrainMultiplier = 0.95;

and say in the screenshot area from EH-Coder in this post (above)

while (true) {
  if (RemoteControlCodeEnabled) {
    int drivetrainLeftSideSpeed = Controller1.Axis3.position*drivetrainMultiplier;
    // etc.
  }
}
// And the driver control area
void userControl(void) {
  while (true) {
    if (ButtonA.pressing()) {
      drivetrainMultiplier = 0.2;
    }
    else {
      drivetrainMultiplier = 0.95;
    }
  }
}

And also, in IQ, if you want to edit the #pragma area, you have to copy it and paste it outside of said area, and then take out your configure buttons. Otherwise every time you save your program, VEXcode IQ rewrites your #pragma area according to your configuration. I don’t know for sure about V5, though.

1 Like