Expert Robot Config with Competition template

My team wanted to use the 4 motor drivetrain function with the new vexcode v5 Pro, but you can’t reverse the motors with the basic function, you have to enable expert motor config. This seams to introduce so many problems. Has anyone been successful doing this? My issue currently is I did all my usual usercontrol code in the robotconfig.cpp because a lot I used vexcode controller feature where you can assign motors to buttons. Now when trying to write an auton it’s all messed up beacuse the code in robotconfig.cpp is running at the same time. I tried moving all that over to usercontrol in main.cpp and simplfying it down to basic if statments, but now it doesn’t recongize any of the additional motors/sensors I added manually in robotconfig.cpp. If I try to #include robotconfig.cpp it says everything is a duplicate.

I will try and add the motors and sensors I added to the robotconfig.h file, but I dont know if it will work. Does anyone have experience with expert robot config mode competition template?

Can you post your robot-config.cpp as well as your main.cpp? It would help.

1 Like

In general I don’t recommend using the built in 4 motor drivetrain object. It’s much more reliable, flexible, and educational to just program your own drivetrain, and it’s not very complicated to do.

Also, don’t put usercontrol code in the robot configuration file.

2 Likes

Like what @ashatoolsidas said, it is extremely beneficial to program your own drivetrain. I just created a function with the parameters I want, such as rotation and velocity.

void driveFunction(double rotation, double velocity){
    ///spin motors based on parameters
}
1 Like

Okay i’ll make my own functions. For a turning function where it turns to a certain heading with the gyro. Would it look something like this? Do voids run forever, like once it is done turning how do I make it move on?

void autoturn(int anglez){
  Gyro.setHeading(0, degrees); 
  while (Gyro.heading(degrees) > anglez-3 && Gyro.heading(degrees) < anglez+3)
  if (Gyro.heading(degrees) > anglez) {
    FrontLeft.spin(directionType::fwd,50,velocityUnits::pct); 
    BackLeft.spin(directionType::fwd,50,velocityUnits::pct); 
    FrontRight.spin(directionType::rev,50,velocityUnits::pct); 
    BackRight.spin(directionType::rev,50,velocityUnits::pct);
  }
  else if(Gyro.heading(degrees) < anglez) {
    FrontLeft.spin(directionType::rev,50,velocityUnits::pct); 
    BackLeft.spin(directionType::rev,50,velocityUnits::pct); 
    FrontRight.spin(directionType::fwd,50,velocityUnits::pct); 
    BackRight.spin(directionType::fwd,50,velocityUnits::pct);
  }
  else {
    autoDriveDistance(0,0);
  }
}

This is my function to move forward a certain amount of inches:

void autoDriveDistance(int Speed, int Distance){
  FrontLeft.setVelocity(Speed, percent); 
  FrontRight.setVelocity(Speed, percent); 
  BackRight.setVelocity(Speed, percent); 
  BackLeft.setVelocity(Speed, percent); 

  FrontLeft.spinFor(forward, Distance/(4*3.141592654), turns);
  FrontRight.spinFor(forward, Distance/(4*3.141592654), turns); 
  BackLeft.spinFor(forward, Distance/(4*3.141592654), turns); 
  BackRight.spinFor(forward, Distance/(4*3.141592654), turns); 
}
1 Like

The function will end when the code exits the while loop

1 Like

For the spin for function, you have to call a parameter which makes sure that the program doesn’t wait until one line is fully executed before executing the next step. So, it should be:

FrontLeft.spinFor(forward, Distance/(4*3.141592654), turns, false);
FrontRight.spinFor(forward, Distance/(4*3.141592654), turns, false);
BackLeft.spinFor(forward, Distance/(4*3.141592654), turns, false);
BackRight.spinFor(forward, Distance/(4*3.141592654), turns);

Also, since you are dividing distance by 3.141592654, I would recommend having distance as a double rather than an integer.

2 Likes

How do I turn off the motors when it’s done

The motors will stop spinning after the while loop has been stopped. In this case, it would stop after the motor no longer is greater than anglez-3 or no longer less than anglez+3

1 Like

No they won’t because the function is turning them on and then they will continue until there is a piece of code that turns them off. But I am struggling on where to put that.

Just put that after the while statement is completed.

I tried that and then it just doesn’t turn at all.

Can you print out the value of the heading on the screen of the brain?

this is what I have right now and its not moving. Also I have the gyro calibrate in the beginning of auton because I wasn’t sure if it ran pre auton when running a “timed run” on the controller.

void autoTurn(int anglez){
  Gyro.setHeading(0, degrees); 
  while (Gyro.heading(degrees) > anglez-3 == false && Gyro.heading(degrees) < anglez+3 == false ){
    if (Gyro.heading(degrees) > anglez) {
      FrontLeft.spin(directionType::fwd,20,velocityUnits::pct); 
      BackLeft.spin(directionType::fwd,20,velocityUnits::pct); 
      FrontRight.spin(directionType::rev,20,velocityUnits::pct); 
      BackRight.spin(directionType::rev,20,velocityUnits::pct);
    }
    else if(Gyro.heading(degrees) < anglez) {
      FrontLeft.spin(directionType::rev,20,velocityUnits::pct); 
      BackLeft.spin(directionType::rev,20,velocityUnits::pct); 
      FrontRight.spin(directionType::fwd,20,velocityUnits::pct); 
      BackRight.spin(directionType::fwd,20,velocityUnits::pct);
    }
      Brain.Screen.print(Gyro.heading(degrees));
  }
}

What are you inputting in as anglez? That could lead to the whileLoop not even executing.

haha no thats just be “angle” has a built in definition. My problem is the while loop arguments.

assuming that you want to turn with the angle provided, I would put the argument as

while(Gyro.heading(degrees) < anglez){
/*dostuff*/
}
1 Like

I figured it out, now I am going to incorpate a P loop so it doesn’t over shoot

1 Like

When I do this not all the motors start at the same time and therefore it turns a little bit right from the beginning.