sensor-controlled
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:
{
"components": [
{ ... INSERT MOVEMENT SENSOR CONFIGURATION },
{ ... INSERT BASE CONFIGURATION },
{
"name": "my-sensor-controlled-base",
"model": "sensor-controlled",
"api": "rdk:component:base",
"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 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 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.
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!