Base remote control service

Used with

* Required for use

** Input controller is required hardware + related Viam component

The base remote control service implements an input controller as a remote control for a base. This uses the input API to make it easy to add remote drive controls for your rover or other mobile robot with a controller like a gamepad.

Add the base remote control service after configuring your machine with a base and input controller to control the linear and angular velocity of the base with the controller’s button or joystick controls.

Control mode is determined by the configuration attribute "control_mode", for which there are five options. Each mode reads only the input controller controls listed for it and ignores the rest. Which physical button or stick sends each control depends on your input controller model.

control_modeControls readWhat they do
"arrowControl" (default)AbsoluteHat0Y, AbsoluteHat0X (arrow pad)AbsoluteHat0Y drives forward or backward and AbsoluteHat0X turns, each at full speed while held.
"triggerSpeedControl"AbsoluteZ, AbsoluteRZ, AbsoluteXEach AbsoluteRZ event (usually the right trigger) raises the speed by 5% of the maximum, up to full forward. Each AbsoluteZ event (usually the left trigger) lowers it by 5%, down to full reverse. The speed stays where the triggers leave it. AbsoluteX (left stick, left and right) turns.
"buttonControl"ButtonNorth, ButtonSouth, ButtonEast, ButtonWestWhile held, ButtonNorth drives forward and ButtonSouth backward at full speed, and ButtonEast turns right and ButtonWest left. Holding both buttons of a pair cancels them out.
"joystickControl"AbsoluteY, AbsoluteX (left stick)AbsoluteY sets the forward or backward speed and AbsoluteX the turn, in proportion to how far the stick is pushed. A stick pushed less than about a quarter of the way counts as centered.
"droneControl"AbsoluteX, AbsoluteY, AbsoluteRX, AbsoluteRY (two sticks)Left stick: AbsoluteX spins and AbsoluteY moves up or down. Right stick: AbsoluteRY moves forward or backward and AbsoluteRX moves sideways. As with joystickControl, a stick pushed less than about a quarter of the way counts as centered.

When both max_linear_mm_per_sec and max_angular_deg_per_sec are set, the service sets the base’s velocity as a fraction of those maximums. Otherwise it sets the base’s power as a fraction of full power.

You can monitor the input from these controls in the CONTROL tab.

Configuration

You must configure a base with a movement sensor as part of your machine to be able to use a base remote control service.

First, make sure your base is physically assembled and powered on. Then, configure the service:

Navigate to the CONFIGURE tab of your machine’s page. Click the + icon next to your machine part in the left-hand menu and select Blocks. Select the base remote control type. Enter a name or use the suggested name for your service and click Add to machine.

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": "<your-controller-name>"
}

Edit the attributes as applicable to your machine, according to the table below.

For example:

An example configuration for a base remote control service.

{
  "name": "<your-base-remote-control-service>",
  "api": "rdk:service:base_remote_control",
  "model": "rdk:builtin:builtin",
  "attributes": {
    "base": "<your-base-name>",
    "input_controller": "<your-controller-name>"
  }
}
{
  "name": "gamepad_service",
  "api": "rdk:service:base_remote_control",
  "model": "rdk:builtin:builtin",
  "attributes": {
    "base": "my-base",
    "input_controller": "my-input-controller",
    "control_mode": "arrowControl"
  }
}

Edit and fill in the attributes as applicable. The following attributes are available for base remote control services:

NameTypeRequired?Description
basestringRequiredThe name of the base you have configured for the base you are operating with this service.
input_controllerstringRequiredThe name of the input controller you have configured for the base you are operating with this service.
control_modestringOptionalThe mode of remote control you want to use.
Options:
  • "arrowControl"
  • "triggerSpeedControl"
  • "buttonControl"
  • "joystickControl"
  • "droneControl"

Default: "arrowControl"
max_angular_deg_per_secfloatOptionalThe max angular velocity for the base in degrees per second.
max_linear_mm_per_secfloatOptionalThe max linear velocity for the base in millimeters per second.

API

The base remote control service supports the following methods:

Method NameDescription
ControllerInputsGet a list of inputs from the controller that are being monitored for that control mode.
ReconfigureReconfigure this resource.
DoCommandExecute model-specific commands that are not otherwise defined by the service API.
GetResourceNameGet the ResourceName for this instance of the generic service with the given name.
CloseClose out of all remote control related systems.

ControllerInputs

Get a list of inputs from the controller that are being monitored for that control mode.

Parameters:

  • None.

Returns:

  • ([]input.Control): A list of inputs from the controller that are being monitored for that control mode.

Example:

// Get the list of inputs from the controller that are being monitored for that control mode.
inputs := baseRCService.ControllerInputs()

For more information, see the Go SDK Docs.

Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • deps (Dependencies): The resource dependencies.
  • conf (Config): The resource configuration.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

DoCommand

Execute model-specific commands that are not otherwise defined by the service API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own base remote control service and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.

Parameters:

Returns:

Example:

myBaseRemoteControlSvc, err := baseremotecontrol.FromProvider(machine, "my_base_remote_control_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myBaseRemoteControlSvc.DoCommand(context.Background(), command)

For more information, see the Go SDK Docs.

GetResourceName

Get the ResourceName for this instance of the generic service with the given name.

Parameters:

  • None.

Returns:

Example:

baseRCService, err := baseremotecontrol.FromProvider(machine, "my_baseRCService_svc")

err := baseRCService.Name()

For more information, see the Go SDK Docs.

Close

Close out of all remote control related systems.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error): An error, if one occurred.

Example:

baseRCService, err := baseremotecontrol.FromProvider(machine, "my_baseRCService_svc")

err := baseRCService.Close(context.Background())

For more information, see the Go SDK Docs.