Is there a way to program the motors to spin, and stop when they stall?

Hello, I am wondering if there is a way for you to program the motors to spin and stop when they stall.

A good way to do this would be to turn off the motor if the velocity goes below a certain level.

2 Likes

Just make sure to make the code wait fir a few seconds before testing for velocity. Otherwise the motor won’t go because it would start at 0 velocity.

You could also just let the motors stall because, you know, motors don’t move when they’re stalled :slight_smile:
(this is a joke don’t do this)

How do you do that? Can you send a sample code?

What program do you use?

C++(regular)

A simple example in pseudocode would be
motor.move(forward)
wait(0.5_sec)
while(abs(motor.velocity) > 0){
motor.move(forward)
}
motor.stop

So pros? Or VexCode?

vex Code

Ya I can send some sample code but not until I get access to a laptop. Try out the pseudocode above.

ok sure

That didn’t work any other advice?

can you post what you tried? Kind of hard to debug what we can’t see

1 Like

XD well I tried the psudeocode if you look up, (but put in the proper motors)

well if you spelled something wrong or your syntax is wrong and you just write it off as ‘oh, that didn’t work, give me more code’ then there’s nothing we can do.

vex::motor ClawMotor = vex::motor(vex::PORT16);
vex::motor LeftMotor = vex::motor(vex::PORT18);
vex::motor RightMotor = vex::motor(vex::PORT1);
vex::motor Motor1 = vex::motor(vex::PORT9, true);
vex::motor Motor2 = vex::motor(vex::PORT15, true);
vex::controller Controller1 = vex::controller();
int main() {
LeftMotor.setVelocity(50, vex::velocityUnits::pct);
RightMotor.setVelocity(50, vex::velocityUnits::pct);

LeftMotor.rotateFor(3, vex::rotationUnits::rev,false);
RightMotor.rotateFor(3, vex::rotationUnits::rev);

LeftMotor.setVelocity(10, vex::velocityUnits::pct);
RightMotor.setVelocity(10, vex::velocityUnits::pct);

LeftMotor.rotateFor(2, vex::rotationUnits::rev,false);
RightMotor.rotateFor(2, vex::rotationUnits::rev,false);

ClawMotor.spin(directionType::fwd, 50, velocityUnits::pct);
task::sleep(500);
while(abs(ClawMotor.velocityUnits::pct() > 0){
ClawMotor.spin(directionType::fwd, 50, velocityUnits::pct);
}
ClawMotor.stop(brakeType::hold);

}

There is my code

This doesn’t get you the motor’s velocity, I think you are looking for ClawMotor.velocity(pct)
Additionally, you are missing an end parentheses, so the while loop is interpreted as part of the parameters. Also, brakeType hold tries to keep the motor exactly where it was, it doesn’t just stop the motor. This might make it look like the motor is still trying to move when it is actually just holding its position. brakeType coast might be better.

3 Likes

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