Motor.spinFor() stopping whole code

In my autonomous code, to get the triball out of the corner, I need to lift it up a certain amount so it can get past the bar but also not hit the robot itself and have it fall out. I used the Motor.spinFor() function to do this but it sometimes just gets stopped in the middle of spinning the motor and seems to halt the rest of the code with it. I am pretty sure this happens because there is too much force on the motor and something gets called to stop the robot as a failsafe.
Here is a picture of it where it stops.


I set the torque limit of the motor to max but that doesn’t change anything, this is the point of the autonomous that it stops at.

Drivetrain.driveFor(forward, 375, mm);
// Moves onto the bar to grab the tirball

SpinTime(Intake, -70, 1.25);
// Slams intake down on tribal to grab it

Intake.setMaxTorque(100, percent);
// Attempt to avoid motor stopping during next function

Intake.spinFor(forward, 0.85, turns);
// Problem area, meant to lift triball over bar

Intake.stop(hold);
// Holds intake in place

Drivetrain.driveFor(reverse, 210, mm);
// Backs up robot
1 Like

Forgot to mention but it’s not a mechanical issue since it can do it fine when told to just spin at 100 percent, problem is it isn’t accurate

If this doesn’t manage to turn 0.85 turns, then the code will block.
add a timeout for the Intake motor, perhaps 2 seconds.

4 Likes

Is there another way to add a timeout other than making the waitforCompletion boolean false and a wait(2, seconds) after it?

well obviously, otherwise I would not have suggested it.

from the documentation

/** 
 * @brief Sets the timeout for the motor. If the motor does not reach its' commanded position prior to the completion of the timeout, the motor will stop.
 * @param time Sets the amount of time.
 * @param units The measurement unit for the time value.
 */
void  setTimeout( int32_t time, timeUnits units );
Intake.setTimeout(2, seconds);
2 Likes

Thanks for the help man :pray:

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