Configure a Sensor-Controlled Base

A sensor-controlled base supports a robotic base with feedback control from a movement sensor.

To configure a sensor-controlled base as a component of your machine, first configure the model of base you want to wrap with feedback control and each required movement sensor. To see what models of movement sensor report which feedback, reference the appropriate column in Movement Sensor API.

Configure a sensor-controlled base as follows:

Navigate to the CONFIGURE tab of your machine’s page in the Viam app. Click the + icon next to your machine part in the left-hand menu and select Component. Select the base type, then select the sensor-controlled model. Enter a name or use the suggested name for your base and click Create.

An example configuration for a sensor-controlled base in the Viam app config builder

Edit and fill in the attributes as applicable.

{
  "components": [
    { ... INSERT MOVEMENT SENSOR CONFIGURATION },
    { ... INSERT BASE CONFIGURATION },
    {
      "name": "my-sensor-controlled-base",
      "model": "sensor-controlled",
      "type": "base",
      "namespace": "rdk",
      "attributes": {
        "movement_sensor": [
          "<your-orientation-or-velocity-movement-sensor-1>",
          "<your-orientation-or-velocity-movement-sensor-2>"
        ],
        "base": "<your-base>"
      },
      "depends_on": []
    }
  ]
}

The following attributes are available for sensor-controlled bases:

NameTypeInclusionDescription
movement_sensorarrayRequiredArray with the names of any movement sensors on your base you want to gather feedback from. The driver will select the first movement sensor providing appropriate feedback for either the SetVelocity() or the Spin() endpoint.
If your sensor has an adjustable frequency or period, set the frequency to something greater than or equal to the default base control loop frequency of 10Hz, or set the period to something less than or equal to the corresponding period of 100msecs.
basestringRequiredString with the name of the base you want to wrap with sensor control.
control_parametersobjectOptionalA JSON object containing the coefficients for the proportional, integral, and derivative terms for linear and angular velocity. If you want these values to be auto-tuned, you can set all values to 0: [ { "type": "linear_velocity", "p": 0, "i": 0, "d": 0 }, { "type": "angular_velocity", "p": 0, "i": 0, "d": 0 } ], and viam-server will auto-tune and log the calculated values. Tuning takes several seconds and spins the motors. Copy the values from the logs and add them to the configuration once tuned for the values to take effect. If you need to auto-tune multiple controlled components that depend on the same hardware, such as a sensor controlled base and one of the motors on the base, run the auto-tuning process one component at a time. For more information see Feedback control.

Feedback control

SetVelocity

If you want to control your base by specifying a desired velocity in terms of distance/time, for example 5 m/s, and you have a movement sensor that measures the actual velocity, you can make use of the sensor to adjust the velocity. Alternatively, if your base has position reporting motors, you can use the wheeled odometry movement sensor to get an estimate of the necessary velocities.

Setting the control_parameters attribute sets up a PID control loop. Setting the control_parameters will automatically set up the required PID loop for a sensor controlled base. For more information on PID or to set up a more complex control loop, see the controls package

If you want these values to be auto-tuned, you can set all values to 0: [ { "type": "linear_velocity", "p": 0, "i": 0, "d": 0 }, { "type": "angular_velocity", "p": 0, "i": 0, "d": 0 } ], and viam-server will auto-tune and log the calculated values. Tuning takes several seconds and spins the motors. Copy the values from the logs and add them to the configuration once tuned for the values to take effect.

Spin

When the control_parameters attribute is set, Spin implements a form of feedback control that polls the provided movement sensor and corrects any error between the desired angular velocity and the actual angular velocity using a PID control loop. Spin also monitors the angular distance traveled and stops the base when the goal angle is reached.

MoveStraight

When control_parameters is set, MoveStraight calculates the required velocity to reach the desired velocity and distance. It then polls the provided velocity movement sensor and corrects any error between this calculated velocity and the actual velocity using a PID control loop. MoveStraight also monitors the position and stops the base when the goal distance is reached. If a compass heading movement sensor is provided, MoveStraight will attempt to keep the heading of the base fixed in the original direction it was faced at the beginning of the MoveStraight call.

Test the base

After you configure the base, go to the CONTROL tab and expand the base component to view the controls to enable keyboard or discrete control over your machine’s movement. If your base makes use of a camera component, the CONTROL tab for your base will also display a Live Feeds section. This section contains buttons to toggle cameras on or off and to arrange how you view the camera feeds.

The base component in control tab

On the Keyboard tab, you can toggle the keyboard control to active. With the Keyboard toggle active, use W and S to go forward and back, and A and D to arc and spin.

Try driving your base around using the WASD keyboard controls.

If you navigate to the Discrete tab, you can use movement modes such as Straight and Spin and different movement types such as Continuous and Discrete and directions such as Forwards and Backwards.

If you do not see the base card in the CONTROL tab, check the LOGS tab for possible setup or configuration errors.

The following base control API methods are available on a sensor-controlled base:

  • SetVelocity(): available if base is configured to receive angular and linear velocity feedback.
  • Spin(): available if base is configured to receive orientation feedback.
  • MoveStraight(): available if base is configured to receive position feedback.

For example, a Viam Rover using sensor-controlled base following both an angular and linear velocity command:

The position, orientation, and linear and angular velocity of the rover changing as it moves, as measured by a movement sensor:

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.