Previous
Motor
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.
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 |
To get started using Viam’s SDKs to connect to and control your movement sensor and the rest of your machine, go to your machine’s page on the Viam app, Navigate to the CONNECT tab’s Code sample page, select your preferred programming language, and copy the sample code.
To show your machine’s API key in the sample code, toggle Include API key.
We strongly recommend that you add your API key and machine address as an environment variable. Anyone with these secrets can access your machine, and the computer running your machine.
When executed, this sample code creates a connection to your machine as a client.
The following examples assume you have a movement sensor called "my_movement_sensor"
configured as a component of your machine.
If your movement sensor has a different name, change the name
in the code.
Import the movement sensor package for the SDK you are using:
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
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:
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Report the current compass heading in degrees.
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Report the current orientation of the sensor.
Supported by IMU models.
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
o_x
, o_y
, o_z
, and theta
, which together represent a vector pointing in the direction that the sensor is pointing, and the angle (theta
) in degrees of the sensor’s rotation about that axis.Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Report the current GeoPoint (latitude, longitude) and altitude (in meters).
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Get the supported properties of this sensor.
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
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:
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
(*Accuracy): The precision and reliability metrics of the movement sensor, which vary depending on model. This type contains the following fields:
AccuracyMap
(map[string]float32): A mapping of specific measurement parameters to their accuracy values.
The keys are string identifiers for each measurement (for example, “Hdop”, “Vdop”), and the values are their corresponding accuracy levels as float32.Hdop
(float32): Horizontal Dilution of Precision (HDOP) value.
It indicates the level of accuracy of horizontal measurements.
Lower values indicate improved reliability of positional measurements.Vdop
(float32): Vertical Dilution of Precision (VDOP) value.
Similar to HDOP, it denotes the accuracy level of vertical measurements.
Lower values indicate improved reliability of positional measurements.NmeaFix
(int32): An integer value representing the quality of the NMEA fix.
See Novatel documentation for the meaning of each fix value.CompassDegreeError
(float32): The estimated error in compass readings, measured in degrees.
This signifies the deviation or uncertainty in the sensor’s compass measurements.
A lower value implies a more accurate compass direction.(error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
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:
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
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:
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:
Example:
For more information, see the Python SDK Docs.
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:
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:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
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:
For more information, see the Go SDK Docs.
Execute model-specific commands that are not otherwise defined by the component API.
If you are implementing your own movement sensor and add features that have no built-in API method, you can access 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:
Raises:
Example:
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd
(map[string]interface{}): The command to execute.Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
command
(Struct) (required): The command to execute.callOptions
(CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Get the ResourceName
for this movement sensor with the given name.
Parameters:
name
(str) (required): The name of the Resource.Returns:
Example:
For more information, see the Python SDK Docs.
Safely shut down the resource and prevent further use.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.Returns:
Example:
For more information, see the Go SDK Docs.
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!