I am in a rookie team and we are having a couple of problems regarding v5 text code.
When programming the arms of our robot, we had some trouble making the motors stop moving suddenly in one place. When we program our arms to go up, the weight of the arms make the arms fall right back down.
Is there any way to fix this through the design of the robot or through coding?
A lot of great posts here but to add more detail you can use the motor hold which will stop the motors and have them hold their position even if gravity or some other force tries to move them.
Sample code:
controller Controller1;
motor LLift = motor(PORT1, false);
motor RLift = motor(PORT2, true);
void usercontrol(void) {
// User control code here, inside the loop
while (1) {
if(Controller1.ButtonR1.pressing()){
RLift.spin(directionType::fwd, 70,velocityUnits::pct);
LLift.spin(directionType::fwd, 70,velocityUnits::pct);;
} else if(Controller1.ButtonR2.pressing()){
RLift.spin(directionType::rev, 70,velocityUnits::pct);
LLift.spin(directionType::rev, 70,velocityUnits::pct);
} else {
//The brake mode can be set to coast, brake, or hold.
RLift.stop(brakeType::hold);
LLift.stop(brakeType::hold);
}
//Add your other driver code here
wait(20, msec);
}
}
This does cause a problem if the motors are working hard to keep the lift in the same position - they tend to overheat and will eventually stall.
Best practice is to use rubber bands or some other counter-weight to put the least amount of load on the motors. You want the arms to naturally stay in their position while the motors are not running. To solve that problem do a search on rubber bands.
This second article is a favorite but the photos are missing.