Sensors Service

The sensors service is a built-in service that provides a central interface to all of your robot’s sensors, regardless of the sensor model. With it you can obtain readings from multiple sensors on your robot at once.

API

The sensors service supports the following methods:

Method NameDescription
GetSensorsReturn a list of names of the available sensors.
GetReadingsReturn a list of readings from a given list of sensors.

GetSensors

Returns a list containing the name of each available sensor.

Parameters:

Returns:

  • (List[ResourceName]): Names of the available sensors of the robot.

For more information, see the Python SDK Docs.

# Access the sensors service
sensors_svc = SensorsClient.from_robot(robot=robot, name="builtin")

# Get available sensors
sensors = await sensors_svc.get_sensors()

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:

For more information, see the Go SDK Docs.

// Access the sensors service
sensorsService, err := sensors.FromRobot(robot, "builtin")
if err != nil {
  logger.Fatal(err)
}

// Get available sensors
sensor_names, err := sensorsService.Sensors(context.Background(), nil)

GetReadings

Returns a list of sensor readings from a given list of sensors.

Parameters:

Returns:

  • ([Mapping[ResourceName, Any]]): A list of readings from the requested sensors.

For more information, see the Python SDK Docs.

# Access the sensors service
sensors_svc = SensorsClient.from_robot(robot=robot, name="builtin")

# Get available sensors
sensors = await sensors_svc.get_sensors()
# Get readings for sensors
readings = await sensors_svc.get_readings(sensors)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

  • sensorNames ([]resource.Name): An array of sensor names for which to return readings.

  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • ([]Readings): A list of readings from the requested sensors.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

// Access the sensors service
sensorsService, err := sensors.FromRobot(robot, "builtin")
if err != nil {
  logger.Fatal(err)
}

// Get readings from all available sensors
sensor_names, err := sensorsService.Sensors(context.Background(), nil)
readings, err := sensorsService.Readings(context.Background(), sensor_names, nil)


Have questions, or want to meet other people working on robots? Join our Community Discord.