RobotC

We moved into programming in RobotC, Modkit just was not working out for the students on this. We have a question, hoping for a little insight:

Is there a specific code to create a hold/brake on the motor. For example, we want our claw to hold but it releases as soon as the code ends.

Example:

setMotorSpeed(leftMotor, 100);
setMotorSpeed(rightMotor, 100);
sleep(1500);
setMotorSpeed(leftMotor, 0);
setMotorSpeed(rightMotor, 0);

resetMotorEncoder(leftMotor);
resetMotorEncoder(rightMotor);
moveMotorTarget(clawMotor,100000, 75);
waitUntilMotorStop(clawMotor);
}

That code should do it.

When the program ends, it will release the motor. You may want to make sure the program doesn’t end. Add a sleep(??) to the end. Or, a put a while loop at the end.

Has the code above worked in v4.06? These methods did not work and do not step in during debugging. None of the encoder or target methods worked. But I was in the emulator mode. Maybe it has to be plugged in. Thank you.

//If the brake mode of motor 1 is not set to ‘Hold’ mode, //set it to Hold mode if(getBrakeMode(motor1) != motorHold) { setBrakeMode(motor1, motorHold); } Should do it. If you go to robotC program you will see some sample code. It worked for me.