Default claw setting to open on Clawbot

Just starting with Robot C and could not find out if there was a way to set the claw on the claw bot to open? For example, how do I set the motor for the claw to be in the open position automatically. I can program the motor to using moveMotor but how would I know what starting position it is in? Sometimes its open sometimes its closed. Is there a way to check so that if it’s closed, it can be opened automatically.

Try starting the robot with the claw either fully open or fully closed. Always start the claw in the same position.

There are two possible approaches, state-less and stateful.
The stateless one, typically used in a remote-control scenario, is to just assign a movement direction to a button. One button triggers the movement one way, the other back, regardless of the current state. In other words, you won’t have “open” and “close” commands, but a “keep opening” and “keep closing” commands, such as (inside the control loop):


    armControl(clawMotor, BtnEUp, BtnEDown, 100);

The stateful one needs to know this initial state somehow. That’s possible to gain in 3 different ways:
a) The operator moves the robot to a known initial state before running the program.
b) The program, upon start, runs the motor toward a physical limit, then reset the counter
c) The program continuously adjust the reference position based on the moves it achieved

a) is error prone. If the operator fails to prepare the robot correctly, the program might misbehave.
b) You can use advanced RobotC functions, such as setting the motor current limit and checking the motor for stall to carefully attain and calibrate the initial state without self-destructing the robot, though there are some limits to this approach. Claw would be generally OK, but in case of a screw drive, or a high gear ratio in general, you may not recognize the hard stop. My students have also experienced some reliability issues before, when relying on self-calibration and then repeated moves between, say, 0 and 200 degrees using moveMotorTarget/setMotorTarget commands.
The problem, I personally think, is that for example, the claw might not push with enough force unless you’re instructing it to overshoot the zero position. For claw, you want it to push closed, not just to move to the closed position.
c) This is the most complex approach, so I won’t get into details here. The idea is for the motor to keep applying the torque (force) when closed (regardless of the object size), yet open properly.

For autonomous claw(-like mechanisms), my students often used a simple variant of the stateless approach, either overshooting the actual physical range of the mechanism (moveMotor(-1000)/moveMotor(1000)) or actually just setting the direction of the motor (setMotor(-100)/setMotor(100)), in both cases effectively keeping the motor pushing in given direction. Not optimal (wastes battery and available power), but often good enough.

What jrp62 and nenik mention are both great. For a claw, it might also be worth looking into the servo-like functionality of the IQ motors, I know some of my students have used that approach for claws.

At the start of match, the student closes the claw. Then within the program we reset the motor’s encoder at some point (usually when initializing.) To open the claw students would have to determine the “open” number of degrees and use that number.


resetMotorEncoder(motor1);

...

setServoTarget(motor1, 500, 50);


I believe my students ended up writing a sort of toggle function that would set the claw to “open” if the encoder value was within ~25 degrees of closed and set the claw to closed (0) if it was any value above that. Then they could simply call “ToggleClaw()” as needed throughout the program.