Motor Breaking VexCode

When I raise the arm of my robot during driver control, it slowly falls because of the weight of it. It is controlled through one of the sticks and I want it to not fall no matter how high or low it is. Is there any code I can use to get it to break in the middle? I am using the newest version of VexCode on V5 motors.

Simple solution is to set the brake type to hold (see the VEX API). Better solution is to use a p loop of some sort.

3 Likes

Why would a p loop be better for holding compared to brake type hold? I can understand it’s a little more complex and “technically correct” as you are coding the actual staying in place, but I don’t exactly see the benefit past that.

1 Like

Isn’t brake type hold already controlled by a PID?

As for your lift, i’d suggest starting with rubber bands. Using break type lift without the lift being able to hold itself up will cause the motor to overheat.

3 Likes
ArmMotorRight.spin(vex::directionType::rev, Controller2.Axis3.position()*0.5, vex::velocityUnits::pct);
ArmMotorLeft.spin(vex::directionType::rev, Controller2.Axis3.position()*0.5, vex::velocityUnits::pct);

This is what I have right now, is there any way to make this maybe into an if else statement, where the if is if the stick is moved then follow the code I currently have, else apply brakes to the motors. I did something similar with buttons. Is it possible to do it with one of the sticks? I think that would be the easiest method, I just can’t find a way online to do it.

Here is what I mean with me doing it with the button (I just want to know if this is possible with sticks):

if(Controller2.ButtonR1.pressing()) {
  // Spin the claw motors forward
  ClawMotor1.spin(vex::directionType::fwd, clawSpeedPCT, vex::velocityUnits::pct);
  ClawMotor2.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
}
// Else if button R2 is pressed
else if(Controller2.ButtonR2.pressing()) {
  // Spin the claw motors backward
  ClawMotor1.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
  ClawMotor2.spin(vex::directionType::fwd, clawSpeedPCT, vex::velocityUnits::pct);
}
// Else if neither button R1 or button R2 is pressed
else {
  // Stop the claw motors
  ClawMotor1.stop(vex::brakeType::brake);
  ClawMotor2.stop(vex::brakeType::brake);

You can use what u originally had, but before it do a deadzone check and if it is within the deadzone, brakeType hold the motor

1 Like

just use two other buttons for your arms instead of joystick. If there any reason you have to use joystick for the arms.

Yes, you can do it with the sticks. Assign a variable to the value of the joystick. Brake if the value is 0 (or use a small range) and run the motor using the joystick value otherwise.

Int clawSpeedPCT = Controller1.Axis1.position(percent); 
ClawMotor1.setStopping(hold); //can also use .braketype

if (clawSpeedPCT != 0){ 
ClawMotor1.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
//runs the motor at joystick value if the joystick is something other than zero
}

else {
ClawMotor1.stop(); //stop and hold if joystick is at zero
}

If you use Controller.Axis.position() don’t forget to add deadband/deadzone detection like @thorstenl312 said.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.