I have a certain point where I want the motor to know as its home position. How do I program it so that the motor returns back to that specific spot and then resets that to zero point? Using encoders and blocks by the way
You could rotate the unpowered motor axle to the desired physical position manually (literally by hand if safe/feasible or with a large handwheel for convenience),
OR
rotate the powered motor axle with joystick control (using your TeleOp OpMode or a simple utility OpMode for this purpose only).
Then you may run your actual competition OpMode (TeleOp or Auto), starting with a Stop_and_Reset_Encoder
Block for that motor.
This would be followed of course by your choice of:
Run_Using_Encoder
, or- the proper sequence for
Run_To_Position
==========
There’s a nice automated short-cut available, if your motor’s zero position is at one end of the mechanism’s range of motion, with a hard mechanical stop. (If it’s not, consider whether it could be.)
In that case, some teams initialize the OpMode by running the motor into the hard stop, at very low power, for a very short amount of time, under the RunMode called Run_Without_Encoder
. Then apply Stop_and_Reset_Encoder
, followed by RUE or RTP as described above.
This can give a fairly repeatable starting position, with little or no manual set-up.
Note: the motor should already be somewhat close to the hard stop, to reach it and press gently, within the short time limit.
The latter is the way we do it. We use a viper slide arm with a motor with encoder. In autonomous period, the OpModes call methods that manipulate the arm in RTP mode. When we switch to teleop, the motor is initialized to RUE, but we don’t really know the current position, so resetting the encoder to zero makes little sense.
In teleop, the position is controlled with a joystick through a proportional controller with limits. So when we initially start teleop, the driver has to hit one button that basically overrides the limits, then retract the arm visually back to zero position while listening for the tell-tale clicks of the overrun on the viper-slide belt. The driver then hits a second button to reset the encoder position on the motor to zero and restore the limit protections. This procedure can be done surprisingly quickly, and with two drivers, usually can be accomplished while the robot is driven to the first scoring opportunity.