How to slow down base in driving control period

Our robot has a four motor 200rpm drive and we really like it in auton… no so much for driving. Is there any way I can press a button to slow down my base in driving control period.

There’s my code

You can use the controller’s pressed() method to call a certain method when a given button is pressed. If you want to make it so that you can switch between the “slow mode” and the “fast mode” you can use this to reverse your multiplier variable.

Here’s some example code:

#include "vex.h"
using namespace vex;

//instantiation of motors
vex::motor topLeftDrive = vex::motor(PORT1);
vex::motor bottomLeftDrive = vex::motor(PORT2);
vex::motor topRightDrive = vex::motor(PORT3);
vex::motor bottomRightDrive = vex::motor(PORT4);

//instantiation of controller
vex::controller Controller1 = vex::controller();

//this is your multiplier variable
double multiplier = 1;

//this is the variable to reduce the speed
//of your motors. for example, this will run
//your motors at 50%. It can be changed
double percentageSpeedReduction = 0.5;

//this is the method that is called when the given button is clicked.
//any code inside of it will be executed.
void virtualTransmission() {
  //this is basically switching multiplier between the two modes with the ternary operator
  multiplier = ((multiplier == 1) ? (multiplier * percentageSpeedReduction) : (1)); 

int main() {
  //calls the virtualTransmission() method whenever "A" is clicked
  //do the drive stuff
  while(true) {
    topLeftDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct) * multiplier, velocityUnits::pct);
    bottomLeftDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct) * multiplier, velocityUnits::pct);
    topRightDrive.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct) * multiplier, velocityUnits::pct);
    bottomRightDrive.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct) * multiplier, velocityUnits::pct);  

This can be done in many ways, but I hope this helps

1 Like

Thanks! That actually helped a lot, I didn’t have a clue how to do it. Now we can finally not worry about driving so much

1 Like

Glad I could help. I implemented the exact same thing for our team and found it very useful (even adding a super slow mode for when we’re stacking 10+).

For next time when you are posting your code try using the [code] starting tag and the [ /code] closing tag (without space) to post your formatted code. It’s simple to add but helps a lot when trying to read the code.

Good luck

1 Like