void directionButtonControl()
The last called function of the sketch is the function for controlling the TaskBot
using the PS4 controller’s direction pad. In the main loop, this function is called
from within the third while loop and is executed when one of the buttons from
Button Group 2 is pressed.
Because this function is called from within a while loop, it is necessary to include
the ps4.getPS4() command to update the status of the PS4 controller’s buttons,
joysticks and sensors.
Next, the function includes an if statement to determine if the value of the touch
pad has changed. If the user is using the touch pad to adjust the motor speed, then
the touchPadControl() function is called to adjust the crawl, normal, and turbo
mode speeds.
After that, the adjustMotorPowers() function is called to adjust the
powerMultiplier based on if the TaskBot is in crawl mode, turbo mode, or normal
mode.
Finally, the function uses eight if statements to determine which buttons from the
directional pad are pressed and to adjust the motors accordingly. The
ps4.buttons_2 command is used to get the uniquely assigned value based on
what button or buttons are pressed on the direction pad.
TETRIX Tele-Op Control Module Activity 2
11