When I input some control input to the robot then stop inputting sometimes the motors continues going even if though I had stopped giving it input into the controller can someone give me an example of how to fix this? Someone previously explained to me that I should create deadzones for the joystick because the actual value is not hitting 0. How do I do that? I am not an experienced programmer. Here is my driver code:
int slowmode = 0;
double arcadeSpeedLeft;
double arcadeSpeedRight;
void usercontrol(void) {
// User control code here, inside the loop
while(1){
if(slowmode == 0){
arcadeSpeedLeft = -0.55Controller1.Axis4.position(percent)-Controller1.Axis3.position(percent);
arcadeSpeedRight = -0.55Controller1.Axis4.position(percent)+Controller1.Axis3.position(percent);
}
else if(slowmode == 1){
arcadeSpeedLeft = 0.5(-0.55Controller1.Axis4.position(percent)-Controller1.Axis3.position(percent));
arcadeSpeedRight = 0.5(-0.55Controller1.Axis4.position(percent)+Controller1.Axis3.position(percent));
}
FrontLeft.setStopping(coast);
FrontRight.setStopping(coast);
BackLeft.setStopping(coast);
BackRight.setStopping(coast);
FrontLeft.setVelocity(-arcadeSpeedLeft,percent);
FrontRight.setVelocity(arcadeSpeedRight,percent);
BackLeft.setVelocity(-arcadeSpeedLeft,percent);
BackRight.setVelocity(arcadeSpeedRight,percent);
FrontLeft.spin(forward);
BackLeft.spin(forward);
BackRight.spin(forward);
FrontRight.spin(forward);
if(Controller1.ButtonY.pressing()){
Controller1.Screen.print("Drivetrain: %.2f." , FrontLeft.temperature(percent));
Controller1.Screen.newLine();
Controller1.Screen.print("Manipulator: %.2f." , Manipulator.temperature(percent));
Controller1.Screen.newLine();
Controller1.Screen.print("Forklift: %.2f." , Forklift.temperature(percent));
Controller1.Screen.newLine();
Controller1.Screen.print("Lift: %.2f." , FourbarLeft.temperature(percent));
Controller1.Screen.newLine();
wait(0.5,sec);
Controller1.Screen.setCursor(1,1);
Controller1.Screen.clearScreen();
}
if(Controller1.ButtonUp.pressing()){
slowmode = 1;
FrontLeft.setVelocity(50,percent);
FrontRight.setVelocity(50,percent);
BackLeft.setVelocity(50,percent);
BackRight.setVelocity(50,percent);
}
if(Controller1.ButtonX.pressing()){
Manipulator.setVelocity(-100,percent);
Manipulator.spin(forward);
}
else if(Controller1.ButtonB.pressing()){
Manipulator.setVelocity(100,percent);
Manipulator.spin(forward);
}
else{
Manipulator.stop(hold);
}
if(Controller1.ButtonR2.pressing() && Forklift.position(degrees)>= -685){
Forklift.setVelocity(-75,percent);
Forklift.spin(forward);
}
else if(Controller1.ButtonR1.pressing() && Forklift.position(degrees)<=1){
Forklift.setVelocity(75,percent);
Forklift.spin(forward);
}
else{
Forklift.stop(hold);
if(Controller1.ButtonL1.pressing()){
FourbarLeft.setVelocity(-70,percent);
FourbarLeft.spin(forward);
FourbarRight.setVelocity(70,percent);
FourbarRight.spin(forward);
}
else if(Controller1.ButtonL2.pressing()){
FourbarLeft.setVelocity(70,percent);
FourbarLeft.spin(forward);
FourbarRight.setVelocity(-70,percent);
FourbarRight.spin(forward);
}
else{
FourbarLeft.stop(hold);
FourbarRight.stop(hold);
}
}
}
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}