Lift Motor with Limit Switches
Last updated
Was this helpful?
Last updated
Was this helpful?
Lift/Arm with Push-Button End Stops
The Touch Sensor
The REV Touch Sensor is a digital sensor that is wired to the N+1 channel on our standard 4-pin JST PH connector. In other words, the REV Expansion Hub digital ports are grouped with two input/output channels per port: 0-1, 2-3, 4-5, 6-7. In general we refer to each channel as N and N+1. When pressed, the touch sensor pulls the digital channel low from its default high state.
Before mounting the push-buttons on your robot, it may be wise to simply plug them in and test their function. Once you are confident in this, you can mount them on your device such that they impede the arm from exceeding its limits.
Plug your touch sensors into your robot controller, being sure to place the negative wire in the correct side of the port. Also take note of which port you plugged it into.
Next, edit your configuration file to create objects for each of your pushbuttons.
Now that your sensors are plugged in and configured, you will want to add your lift motor and your sensors to the object initialization of your TeleOpMode. Again, create a new TeleOp Mode but copy/paste your old code over… (just make sure the main class has the correct name!)
Inside the runOpMode() method, tell your robot controller where to find your touch sensors and lift motor… (be careful not to blindly name things what I name them… (remember what name you gave the sensor in your configuration file!)
Now you are ready for the main loop control code. This can simply be added below the drive code, but above the closing curly-brace of the while loop.
This code allows the directional pad of your controller to control the up and down movement of the lift AS LONG AS the upper/lower touch sensors are not pushed. If they are, we use a “for loop” to give the motor several short pulses in the opposite direction. This moves it just inside the limit.