Hello,
I am using V5 with VCS and am trying to make a flipper/de-scorer that will rotate to a set angle with a button using the “rotateTo” command, however if the mecanism gets stuck on something, for example another robot, my robot becomes completely useless because the motor never finished the command, hence it won’t allow further movement. Is there any way to do this with some kind of override that will allow the motor to stop trying to finish its rotation and allow further movement?
Thanks
You could go out of your program and back into it during a match.
You can use
motor.setTimeout()
to stop the motor if it doesn’t reach its target before the timeout.
I’m not familiar with VCS yet. Can you do a command that powers a motor until it reaches that point? In RobotC logic, it would look something like:
If(buttonPressed)
{
While[potLessThan] “value”
{
Motor[motor]=127;
}
}
Do as @eggplant said. That’s basically the point of motor.setTimeout().
I’m somewhat new to VCS as well. How is the timeout supposed to be implemented? Or if you can point me to a previous thread that discusses how this is done, that would also be fine. Thanks
@dabdoue23880A
Here is an example:
#include "robot-config.h"
vex::competition Competition;
vex::controller Controller;
vex::motor flipper(vex::PORT1);
void pre_auton( void ) {
//set timeout on motor to 1 second
//figure out what a good timeout time is for you
flipper.setTimeout(1, vex::timeUnits::sec);
}
void autonomous( void ) {
//auton code
}
void usercontrol( void ) {
if (Controller.ButtonL1.pressing()){
//if it doesn't rotate to 90 degrees within one second it will stop the motor and move on
flipper.rotateTo(90, vex::rotationUnits::deg);
}
}
int main() {
pre_auton();
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );
while(1) {
vex::task::sleep(100);
}
}
If you have any questions feel free to ask
Thank you so much. I’m trying to get as much experience as possible with coding so this is very helpful. Thanks again
np
Also if you want to be able to do other stuff like drive when the motor is rotating you could switch out
rotateTo
with
startRotateTo
and a very useful resource is the VCS API Reference
That’s also very helpful thank you. I will also be taking a closer look at that as it seems very good to know