Previous
Build a Flutter App
By the end of this tutorial, you’ll be able to drive your rover around like an RC car.
After following this tutorial, you will be able to use the input controller component to control your machine using a gamepad.
You will need the following hardware to complete this tutorial:
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.
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.
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.
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:
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:
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.
Here is a diagram of the gamepad.
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 3 and 4: Use the D-Pad |
LED 1 and 2: Use the D-Pad | LED 1 and 4: Use the Joystick |
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:
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!