Movement sensor API | Component APIs
Movement sensor API
The movement sensor API allows you to give commands to your movement sensor components for getting a GPS location, linear velocity and acceleration, angular velocity and acceleration, and heading.
Different movement sensors provide different data, so be aware that not all of the methods below are supported by all movement sensors.
Tip
You can run GetProperties on your sensor for a list of its supported methods.
| Method Name | Description | Models That Support This Method | viam-micro-server Support |
|---|---|---|---|
GetPosition |
Get the current latitude, longitude, and altitude. | GPS models, wheeled-odometry |
|
GetLinearVelocity |
Get the current linear velocity as a 3D vector. | GPS models, wheeled-odometry |
|
GetAngularVelocity |
Get the current angular velocity as a 3D vector. | IMU models, gyro-mpu6050, and wheeled-odometry |
|
GetLinearAcceleration |
Get the current linear acceleration as a 3D vector. | IMU models, accel-adxl345, and gyro-mpu6050 |
|
GetCompassHeading |
Get the current compass heading in degrees. | GPS models | |
GetOrientation |
Get the current orientation. | IMU models, wheeled-odometry |
|
GetProperties |
Get the supported properties of this sensor. | all models | |
GetAccuracy |
Get the accuracy of the various sensors. | GPS models | |
GetReadings |
Obtain the measurements/data specific to this sensor. | all models | |
DoCommand |
Send or receive model-specific commands. | all models | |
Close |
Safely shut down the resource and prevent further use. | all models |
API
GetLinearVelocity
Report the current linear velocity in the x, y, and z directions (as a 3D vector) in meters per second.
Supported by GPS models.
Supported by viam-micro-server.
Parameters:
extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- ( viam.components.movement_sensor.Vector3): : The linear velocity in m/sec.
Example:
Copy
For more information, see the Python SDK Docs.
GetAngularVelocity
Report the current angular velocity about the x, y, and z axes (as a 3D vector) in degrees per second.
Supported by IMU models and by gyro-mpu6050.
Supported by viam-micro-server.
Parameters:
Returns:
- ( viam.components.movement_sensor.Vector3): : The angular velocity in degrees/sec.
Example:
Copy
For more information, see the Python SDK Docs.
GetCompassHeading
Report the current compass heading in degrees.
Supported by GPS models.
Supported by viam-micro-server.
Parameters:
Returns:
- ( float): : The compass heading in degrees.
Example:
Copy
For more information, see the Python SDK Docs.
GetOrientation
Report the current orientation of the sensor.
Supported by IMU models.
Parameters:
Returns:
- ( viam.components.movement_sensor.Orientation): : The orientation.
Example:
Copy
For more information, see the Python SDK Docs.
GetPosition
Report the current GeoPoint (latitude, longitude) and altitude (in meters).
Supported by GPS models.
Supported by viam-micro-server.
Parameters:
Returns:
- (Tuple[viam.components.movement_sensor.GeoPoint, float]): : The current lat/long, along with the altitude in m.
Example:
Copy
For more information, see the Python SDK Docs.
GetProperties
Get the supported properties of this sensor.
Supported by viam-micro-server.
Parameters:
Returns:
- ( viam.components.movement_sensor.movement_sensor.MovementSensor.Properties): : The properties.
Example:
Copy
For more information, see the Python SDK Docs.
GetAccuracy
Get the reliability metrics of the movement sensor, including various parameters to assess the sensor’s accuracy and precision in different dimensions.
Supported by GPS models and imu-wit.
Parameters:
Returns:
- ( MovementSensor.Accuracy): : The accuracies of the movement sensor.
Example:
Copy
For more information, see the Python SDK Docs.
GetLinearAcceleration
Report the current linear acceleration in the x, y, and z directions (as a 3D vector) in meters per second per second.
Supported by IMU models, accel-adxl345, and gyro-mpu6050.
Supported by viam-micro-server.
Parameters:
Returns:
- ( viam.components.movement_sensor.Vector3): : The linear acceleration in m/sec^2.
Example:
Copy
For more information, see the Python SDK Docs.
GetGeometries
Get all the geometries associated with the movement sensor in its current configuration, in the frame of the movement sensor. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.
Parameters:
Returns:
- ( List[viam.proto.common.Geometry]): : The geometries associated with the Component.
Example:
Copy
For more information, see the Python SDK Docs.
GetReadings
Get all the measurements/data from the sensor. Results depend on the sensor model and can be of any type. If a sensor is not configured to take a certain measurement or fails to read a piece of data, that data will not appear in the readings dictionary. Supported by viam-micro-server.
Parameters:
Returns:
- (Mapping[ str, viam.utils.SensorReading]): : The readings for the MovementSensor. Can be of any type.
Example:
Copy
For more information, see the Python 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 component 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 movement sensor and want to add features that have no corresponding built-in API method, you can implement them with DoCommand. Supported by viam-micro-server.
Parameters:
command(Mapping[ str, ValueTypes]) (required): The command to execute.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Mapping[ str, viam.utils.ValueTypes]): : Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
Copy
For more information, see the Python SDK Docs.
GetResourceName
Get the ResourceName for this movement sensor.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): : The ResourceName of this Resource.
Example:
Copy
For more information, see the Python SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example: