Previous
Movement sensor
The power sensor API allows you to give commands to your power sensor components for getting measurements of voltage, current, and power consumption.
The power sensor component supports the following methods:
Method Name | Description |
---|---|
GetVoltage | Return the voltage reading of a specified device and whether it is AC or DC. |
GetCurrent | Return the current of a specified device and whether it is AC or DC. |
GetPower | Return the power reading in watts. |
GetReadings | Get the measurements or readings that this power sensor provides. |
Reconfigure | Reconfigure this resource. |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. |
GetResourceName | Get the ResourceName for this power sensor with the given name. |
Close | Safely shut down the resource and prevent further use. |
Return the voltage reading of a specified device and whether it is AC or DC.
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:
my_power_sensor = PowerSensor.from_robot(robot=machine, name='my_power_sensor')
# Get the voltage reading from the power sensor
voltage, is_ac = await my_power_sensor.get_voltage()
print("The voltage is", voltage, "V, Is AC:", is_ac)
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:
true
) or DC (false
).Example:
// Get the voltage from device in volts.
voltage, isAC, err := myPowerSensor.Voltage(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
Example:
const powerSensor = new VIAM.PowerSensorClient(
machine,
'my_power_sensor'
);
const [voltage, isAc] = await powerSensor.getVoltage();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
var voltageObject = await myPowerSensor.voltage();
double voltageInVolts = voltageObject.volts;
bool isItAC = voltageObject.isAc;
For more information, see the Flutter SDK Docs.
Return the current of a specified device and whether it is AC or DC.
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:
my_power_sensor = PowerSensor.from_robot(robot=machine, name='my_power_sensor')
# Get the current reading from the power sensor
current, is_ac = await my_power_sensor.get_current()
print("The current is ", current, " A, Is AC: ", is_ac)
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:
true
) or DC (false
).Example:
// Get the current reading from device in amps.
current, isAC, err := myPowerSensor.Current(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
Example:
const powerSensor = new VIAM.PowerSensorClient(
machine,
'my_power_sensor'
);
const [current, isAc] = await powerSensor.getCurrent();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
var currentObject = await myPowerSensor.current();
double amps = currentObject.amperes;
bool isItAC = currentObject.isAc;
For more information, see the Flutter SDK Docs.
Return the power reading in watts.
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:
my_power_sensor = PowerSensor.from_robot(robot=machine, name='my_power_sensor')
# Get the power reading from the power sensor
power = await my_power_sensor.get_power()
print("The power is", power, "Watts")
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:
// Get the power measurement from device in watts.
power, err := myPowerSensor.Power(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
Example:
const powerSensor = new VIAM.PowerSensorClient(
machine,
'my_power_sensor'
);
const power = await powerSensor.getPower();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
var power = await myPowerSensor.power();
For more information, see the Flutter SDK Docs.
Get the measurements or readings that this power sensor provides. If a sensor is not configured to have a measurement or fails to read a piece of data, it will not appear in the readings dictionary.
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:
my_power_sensor = PowerSensor.from_robot(robot=machine, name='my_power_sensor')
# Get the readings provided by the sensor.
readings = await my_power_sensor.get_readings()
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:
// Get the readings provided by the sensor.
readings, err := mySensor.Readings(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra
(None) (optional)callOptions
(CallOptions) (optional)Returns:
Example:
const powerSensor = new VIAM.PowerSensorClient(
machine,
'my_power_sensor'
);
const readings = await powerSensor.getReadings();
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.
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 power sensor and want to add features that have no corresponding built-in API method, you can implement them with DoCommand
.
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:
my_power_sensor = PowerSensor.from_robot(robot=machine, name="my_power_sensor")
command = {"cmd": "test", "data1": 500}
result = await my_power_sensor.do_command(command)
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:
myPowerSensor, err := power_sensor.FromRobot(machine, "my_power_sensor")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myPowerSensor.DoCommand(context.Background(), command)
For more information, see the Go SDK Docs.
Parameters:
command
(Struct) (required): The command to execute.callOptions
(CallOptions) (optional)Returns:
Example:
import { Struct } from '@viamrobotics/sdk';
const result = await resource.doCommand(
Struct.fromJson({
myCommand: { key: 'value' },
})
);
For more information, see the TypeScript SDK Docs.
Get the ResourceName
for this power sensor with the given name.
Parameters:
name
(str) (required): The name of the Resource.Returns:
Example:
my_power_sensor_name = PowerSensor.get_resource_name("my_power_sensor")
For more information, see the Python SDK Docs.
Parameters:
name
String (required)Returns:
Example:
final myPowerSensorResourceName = myPowerSensor.getResourceName("my_power_sensor");
For more information, see the Flutter SDK Docs.
Safely shut down the resource and prevent further use.
Parameters:
Returns:
Example:
my_power_sensor = PowerSensor.from_robot(robot=machine, name="my_power_sensor")
await my_power_sensor.close()
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.Returns:
Example:
myPowerSensor, err := powersensor.FromRobot(machine, "my_power_sensor")
err = myPowerSensor.Close(context.Background())
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!