Configure a Sensor-Controlled Base
A sensor-controlled
base supports a robotic base with feedback control from a movement sensor.
Requirements
In order to use feedback control, you must provide a movement sensor that implements AngularVelocity() and LinearVelocity(). This will enable feedback control for SetVelocity().
In order to use feedback control for Spin(), you must also provide a movement sensor that implements Orientation().
In order to use feedback control for MoveStraight(), you must also provide a movement sensor that implements Position(). Additionally, heading feedback control while moving straight can be used by providing a movement sensor that implements Orientation() or CompassHeading().
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.
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:
Name | Type | Required? | Description |
---|---|---|---|
movement_sensor | array | Required | Array with the name s 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 control_frequency_hz . A higher frequency will generally result in more stable behavior because the base control loop that adjusts the machine’s behavior runs more frequently. |
base | string | Required | String with the name of the base you want to wrap with sensor control. |
control_parameters | object | Optional | A 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. |
control_frequency_hz | float | Optional | Adjusts the frequency that the base control loop runs at. A higher frequency will generally result in more stable behavior because the base control loop that adjusts the machine’s behavior runs more frequently, provided the movement sensors can support the higher frequency. The default base control loop frequency is 10Hz. |
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 use 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.
Note
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.
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, open the base’s TEST panel on the CONFIGURE or CONTROL tabs to view the controls to enable keyboard or discrete control over your machine’s movement.
In the Quick move section, 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.
Caution
Ensure that your robot has sufficient space to drive around without hitting anyone or anything.
You can also move straight or spin from the base panel.
If you do not see the base card in the TEST panel, 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:
Next steps
For more configuration and development info, see:
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.
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!