We generally use two methods to drive robots, tank control and arcade control. When we drive the robot using tank control, we use both joysticks, and when we use arcade control, we can choose to use either the left or the right joystick. Do take note of the labels on your controller that correspond to the channels we will use in our programs. All remote control programs need to be in forever loops, because we need to check the joysticks and button values constantly. In this simple tank control program, we set the drive motors to the joystick values directly. joysticks give values from zero to plus 100 when you push them forward and from zero to negative 100.
When you push them backwards. These values are sent to the motors and will control both the speed and direction The trouble you will find with this setup is that the robot will almost never come to a complete stop when you let go of the joysticks, because joysticks are imperfect and don't always return to zero. To solve this problem, we need to include threshold values in the command. In this example, we included the threshold 10. This threshold will exclude joysticks values from negative 10 to positive 10. And therefore, the robot won't move when the joysticks are in those areas.
If you find that the robot still moves, increase the threshold. In arcade control, one joystick is used instead of two. But seeing as the joystick has two axes, we can still drive the robot in all directions. In the forward and reverse direction, the same value gets sent to both modes. But in the left right direction, one motor is set to the opposite direction. The combination of these values get divided by two and saved as the variables left speed and right speed.
Then we add the threshold before we set the motor speeds. If the joysticks are in the threshold area, the motor speeds are set to zero.