Is this is right way to write the code to make my drivetrain have a set speed and brake type? I don’t really know what the right way is and if it is going to work. And for the axis on the controller is there anything that can specify the exact position of the joystick on the axis?
Here is my original code:
leftFront.spin(directionType::fwd, Controller1.Axis3.position(), pct);
leftBack.spin(directionType::fwd, Controller1.Axis3.position(), pct);
rightFront.spin(directionType::fwd, Controller1.Axis2.position(), pct);
rightBack.spin(directionType::fwd, Controller1.Axis2.position(), pct);
And this is what I want it to be but I don’t know if it’s the best way to write it:
if(Controller1.Axis3.position()) {
leftFront.setBrake(brakeType::coast);
leftBack.setBrake(brakeType::coast);
leftFront.spin(directionType::fwd, 75, velocityUnits::pct);
leftBack.spin(directionType::fwd, 75, velocityUnits::pct);
}
if(Controller1.Axis2.position()) {
rightFront.setBrake(brakeType::coast);
rightBack.setBrake(brakeType::coast);
rightFront.spin(directionType::fwd, 75, velocityUnits::pct);
rightBack.spin(directionType::fwd, 75, velocityUnits::pct);
}
And would this code work as well?
if(Controller1.Axis3.position()) {
leftFront.spin(directionType::fwd, 75, velocityUnits::pct);
leftBack.spin(directionType::fwd, 75, velocityUnits::pct);
} else {
leftFront.stop(brakeType::coast);
leftBack.stop(brakeType::coast);
if(Controller1.Axis2.position()) {
rightFront.spin(directionType::fwd, 75, velocityUnits::pct);
rightBack.spin(directionType::fwd, 75, velocityUnits::pct);
} else {
rightFront.stop(brakeType::coast);
rightBack.stop(brakeType::coast);
The reason why I want to have a set speed and have a specific brake type is because my robot keeps abruptly tilting back and forth when I’m moving the joysticks back and forth without giving the robot time to stop. For example, when I’m driving the robot forward and then I quickly drive backward, the robot will tilt forward a lot, and vice versa for when I’m driving the robot backward and quickly drive forward.