Dpadcontrols and the installed Touch Sensor to control the arm. However, the focus of this section is using code to limit the range of motion of the arm.
Dpadon the gamepad inputs Boolean
FALSE/TRUE. In order to tell the arm to move when
Dpad Downare selected, an
if/else ifstatement needs to be used. Select an
Dpadis to help delineate which direction the arm needs to move in. In this case, should
Dpadthe motor continued to run in the selected direction. The current
FALSE/TRUEbinary. When the touch sensors is not pressed the
if/elsestatement must first be edited back into an
RUN_TO_POSITIONthe following three blocks need to be added to both sections of the
DpadUpis pressed, the arm should move to the the 90 degree position. When
DpadDownis pressed the arm should move back to the starting position. To do this set the first
DpadDownto return the arm to the starting position, keeping the
RUN_TO_POSITIONis a Closed Loop Control, which means that if the arm does not perfectly reach the target position, the motor will continue to fluctuate until it does. When motors continue to oscillate and never quite reach the target position this may be a sign that the factors determining tolerances and other aspects of the closed loop are not tuned to this particular motor or mechanism. There are ways to tune the motor, but for now we want to focus on working with the arm and expanding on how limits and positions work with regards to the mechanism.
GEAR_REDUCTIONvariables to the initialization section of the op mode.
COUNTS_PER_GEAR_REV)is the same formula used in Encoder Navigation for our
COUNTS_PER_WHEEL_REVvariable. So to get this variable we can multiple
COUNTS_PER_GEAR_REVvariable by 360.
Basic Op Modeand add the constant variables from the Calculating Target Position section to the op mode.
minPositionand one called
maxPosition. Add both of these to the initialization section of the op mode.
minPositionset as our starting position and the
maxPositionset to our 90 degree position. Set
if/else ifstatement so that the limits are built in. If
DpadUpis selected and the position of the arm is less than the
maxPositionthen the arm will move to the
DpadDownis selected and the position of the is greater that the
minPositionthen the arm will move towards the
abutton is pressed the arm will move toward the starting position. When the arm reaches and presses the touch sensor we want to
truewhen its not pressed and
falsewhen it is, we will need to use the
false(or is pressed) the motor run mode
STOP_AND_RESET_ENCODERwill be activated causing the motor encoder to reset to 0 ticks.