Drive a Rover (like SCUTTLE or Yahboom) Using a Gamepad

This tutorial teaches you how to add a Bluetooth gamepad controller to your wheeled robot. By the end of this tutorial, you’ll be able to drive your rover around like an RC car.

Requirements

You will need the following hardware to complete this tutorial:

Set up the hardware

If your gamepad has a dongle, plug the gamepad Bluetooth dongle into a USB port on the rover’s board. Then turn on power to the rover.

Click here if your gamepad does not have a dongle for bluetooth pairing instructions.

Add the controller to the rover’s config

Go to your rover’s CONFIGURE tab on the Viam app.

Configure a gamepad:

Click the + icon next to your machine part in the left-hand menu and select Component. Select the input_controller type, then select the gamepad model. Enter a name or use the suggested name for your input controller and click Create.

An example configuration for a linux-based gamepad input controller component in the Viam App config builder

You can set the auto_reconnect attribute to true.

If instead of using the config builder, you prefer to write raw JSON, switch to JSON mode on the CONFIGURE tab. Inside the components array of your config, add the following configuration for your gamepad:

{
  "name": "my-gamepad",
  "model": "gamepad",
  "type": "input_controller",
  "namespace": "rdk",
  "attributes": { "auto_reconnect": true },
  "depends_on": []
}

The controller config adds the gamepad controller to your machine. However, it is not functional yet. To link the controller input to the base functionality, you need to add the base remote control service.

Add the base remote control service

Services are software packages that provide robots with higher level functionality. To link the controller’s input to the base functionality, you need to configure the base remote control service:

Click the + icon next to your machine part in the left-hand menu and select Service. Select the base remote control type. Enter a name or use the suggested name for your service and click Create.

In your base remote control service’s configuration panel, copy and paste the following JSON object into the attributes field:

{
  "base": "<your-base-name>",
  "input_controller": "my-gamepad"
}

For example:

An example configuration for a base remote control service in the Viam app Config Builder.

Add the following configuration for your base remote control service, replacing <your-base-name> with your base’s name:

  "services": [
    {
      "name": "gamepad_service",
      "type": "base_remote_control",
      "attributes": {
        "input_controller": "my-gamepad",
        "base": "<your-base-name>"
      }
    }
  ]

If you already have a "services" array with other services configured, add just the contents of the square brackets above to that array, rather than creating two different "services" arrays.

Click Save, then go to the CONTROL tab.

You should see the panel for the gamepad and its connection indicator:

Gamepad input UI showing a “connected” indicator and a list of inputs from all the buttons, for example X=0.0, RY=0.0 and East=0.

Try moving the left joystick or pressing the D-pad to move the rover using the gamepad.

The ESM-9101 controller has different modes that allow you to use either the joystick or the D-pad. If you are in the mode that allows you to use the joystick (#7), it will change the X and Y values on the Control tab gamepad panel:

"X
0.0000
Y
0.0000"

If you are in the mode that allows you to use the D-pad (#8), it will change the Hat0X and Hat0Y values:

"Hat0X
0.0000
Hat0Y
0.0000"

Testing these attributes tells you which mode you are in.

EasySMX ESM-9101 wireless controller information

Here is a diagram of the gamepad.

gamepad diagramgamepad legend

To change the movement/direction control on the gamepad between the D-pad and the joystick, press and hold the Home button (#11) until it displays the lighted segment combination for the gamepad configuration you need. Each red color arrangement allows you to control the gamepad in the Viam app:

LED 1 and 3: Use the D-Pad
Led 1 and 3 are lit
LED 3 and 4: Use the D-Pad
Led 3 and 4 are lit
LED 1 and 2: Use the D-Pad
Led 1 and 4 are lit
LED 1 and 4: Use the Joystick
Led 1 and 4 are lit

Next steps

You can now drive your rover with a wireless controller. If you’d like to do more with your rover, check out one of these tutorials:

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.