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

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.

Make sure your bluetooth controller is in pairing mode. For an 8bitdo controller, set the mode switch to S, hold down Start for a few seconds, and when the LED underneath the controller changes to green, press the pair button for 3 seconds. For more information about the controller buttons and Bluetooth modes, consult the manual included with the controller.

Run sudo bluetoothctl scan on to list all Bluetooth devices within reach of your machine. As you do this, make sure you run this command on the machine that runs viam-server which may be a different machine to your laptop.

This command scans all bluetooth devices. Find your gamepad. For an 8bitdo controller, the MAC address begins with E4:17:D8.

A screenshot of a Raspberry Pi terminal with the following command: sudo bluetoothctl scan on. The results of the command are displayed: a list of device MAC addresses.

Once you find your controller, pair with the controller by running the following command: sudo bluetoothctl pair <8bitdo-mac-address>. Do not forget to take the < and > symbols out as you paste your address.

Then connect the controller: sudo bluetoothctl connect <8bitdo-mac-address>

To make reconnecting easier in the future, trust the controller by running the following command: sudo bluetoothctl trust <8bitdo-mac-address>

To confirm the connection, you can list connected devices with: sudo bluetoothctl devices | cut -f2 -d| while read uuid; do sudo bluetoothctl info $uuid; done|grep -e "Device\|Connected\|Name"

A screenshot of a Pi terminal showing the above bluetoothctl commands and their outputs.

If you would like a stronger understanding of bluetoothctl and managing Bluetooth devices in Linux, we recommend How to Manage Bluetooth Devices on Linux Using bluetoothctl.

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.