Skip to content

Commit

Permalink
DOCS-2035: Add example snippets to movement sensor, power sensor, sen…
Browse files Browse the repository at this point in the history
…sor (#230)
  • Loading branch information
JessamyT authored Jun 17, 2024
1 parent 7059814 commit 542e18b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 18 deletions.
59 changes: 50 additions & 9 deletions lib/src/components/movement_sensor/movement_sensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,72 @@ abstract class MovementSensor extends Resource {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'movement_sensor');

/// Obtain the measurements/data specific to this [MovementSensor]
/// 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.
/// 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.
///
/// ```
/// var readings = await myMovementSensor.readings();
/// ```
Future<Map<String, dynamic>> readings({Map<String, dynamic>? extra});

/// Get the current [GeoPoint] (latitude, longitude) and altitude (mm)
/// Get the current [GeoPoint] (latitude, longitude) and altitude (mm).
///
/// ```
/// var position = await myMovementSensor.position();
/// ```
Future<Position> position({Map<String, dynamic>? extra});

/// Get the current linear velocity as a [Vector3] with x, y, and z axes represented in mm/sec
/// Get the current linear velocity as a [Vector3] with x, y, and z axes represented in mm/sec.
///
/// ```
/// var linVel = await myMovementSensor.linearVelocity();
/// ```
Future<Vector3> linearVelocity({Map<String, dynamic>? extra});

/// Get the current angular velocity as a [Vector3] with x, y, and z axes represented in radians/sec
/// Get the current angular velocity as a [Vector3] with
/// x, y, and z axes represented in radians per second.
///
/// ```
/// var angVel = await myMovementSensor.angularVelocity();
/// ```
Future<Vector3> angularVelocity({Map<String, dynamic>? extra});

/// Get the current linear acceleration as a [Vector3] with x, y, and z axes represented in mm/sec^2
/// Get the current linear acceleration as a [Vector3] with
/// x, y, and z axes represented in mm/sec^2.
///
/// ```
/// var linAccel = await myMovementSensor.linearAcceleration();
/// ```
Future<Vector3> linearAcceleration({Map<String, dynamic>? extra});

/// Get the current compass heading in degrees
/// Get the current compass heading in degrees.
///
/// ```
/// var compassHeading = await myMovementSensor.compassHeading();
/// ```
Future<double> compassHeading({Map<String, dynamic>? extra});

/// Get the current orientation as an [Orientation]
/// Get the current orientation as an [Orientation].
///
/// ```
/// var orientation = await myMovementSensor.orientation();
/// ```
Future<Orientation> orientation({Map<String, dynamic>? extra});

/// Get the supported properties of this sensor
/// Get the supported properties of this sensor.
///
/// ```
/// var props = await myMovementSensor.properties();
/// ```
Future<Properties> properties({Map<String, dynamic>? extra});

/// Get the accuracy of the various sensors
/// Get the reliability metrics of the movement sensor,
/// including various parameters to assess the sensor’s
/// accuracy and precision in different dimensions.
///
/// ```
/// var accuracy = await myMovementSensor.accuracy();
/// ```
Future<Accuracy> accuracy({Map<String, dynamic>? extra});

/// Get the [ResourceName] for this [MovementSensor] with the given [name]
Expand Down
36 changes: 29 additions & 7 deletions lib/src/components/power_sensor/power_sensor.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '../../components/sensor/sensor.dart';
import '../../gen/common/v1/common.pb.dart';
import '../../gen/component/powersensor/v1/powersensor.pb.dart';
import '../../resource/base.dart';
Expand All @@ -11,25 +10,48 @@ typedef Current = GetCurrentResponse;
abstract class PowerSensor extends Resource {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'power_sensor');

/// Obtain the measurements/data specific to this [Sensor]
/// 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.
/// Get the measurements or readings from this [PowerSensor].
/// If a sensor is not configured correctly or fails to read a
/// piece of data, it will not appear in the readings dictionary.
///
/// ```
/// var readings = await myPowerSensor.readings();
/// ```
Future<Map<String, dynamic>> readings({Map<String, dynamic>? extra});

/// Get the voltage (volts) and boolean isAC
/// Get the voltage in volts, and whether the power is
/// AC (true) or DC (false).
///
/// ```
/// var voltageObject = await myPowerSensor.readings();
/// double voltageInVolts = voltageObject['volts'];
/// bool isItAC = voltageObject['isAc'];
/// ```
Future<Voltage> voltage({Map<String, dynamic>? extra});

/// Get the current (amperes) and boolean isAC
/// Get the current in amperes, and whether the current
/// is AC (true) or DC (false).
///
/// ```
/// var currentObject = await myPowerSensor.readings();
/// double amps = voltageObject['amperes'];
/// bool isItAC = voltageObject['isAc'];
/// ```
Future<Current> current({Map<String, dynamic>? extra});

/// Get the power (watts)
///
/// ```
/// var power = await myPowerSensor.power();
/// ```
Future<double> power({Map<String, dynamic>? extra});

/// Get the [ResourceName] for this [PowerSensor] with the given [name]
/// Get the [ResourceName] for this [PowerSensor] with the given [name].
static ResourceName getResourceName(String name) {
return PowerSensor.subtype.getResourceName(name);
}

/// Get the [MovementSensor] named [name] from the provided robot.
/// Get the [PowerSensor] named [name] from the provided robot.
static PowerSensor fromRobot(RobotClient robot, String name) {
return robot.getResource(PowerSensor.getResourceName(name));
}
Expand Down
8 changes: 6 additions & 2 deletions lib/src/components/sensor/sensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import '../../robot/client.dart';
abstract class Sensor extends Resource {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'sensor');

/// Obtain the measurements/data specific to this [Sensor]
/// Get the measurements or readings from this [Sensor].
///
/// ```
/// var readings = await mySensor.readings();
/// ```
Future<Map<String, dynamic>> readings({Map<String, dynamic>? extra});

/// Get the [ResourceName] for this [Sensor] with the given [name]
/// Get the [ResourceName] for this [Sensor] with the given [name].
static ResourceName getResourceName(String name) {
return Sensor.subtype.getResourceName(name);
}
Expand Down

0 comments on commit 542e18b

Please sign in to comment.