Skip to content

Commit

Permalink
Add VisionClient.fromRobot (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored May 3, 2024
1 parent cfb038b commit b4a824d
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/viam_example_app/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.15'
platform :osx, '13'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/arm/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'arm.dart';
/// Used to communicate with an existing [Arm] implementation over gRPC.
class ArmClient extends Arm implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/base/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'base.dart';
/// gRPC client for the [Base] component.
class BaseClient extends Base implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/board/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'board.dart';
/// gRPC client for the [Board] component.
class BoardClient extends Board implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/camera/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'camera.dart';
/// gRPC client for the [Camera] component
class CameraClient extends Camera implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/gantry/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'gantry.dart';
/// gRPC client for the [Gantry] component.
class GantryClient extends Gantry implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/generic/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'generic.dart';
/// gRPC client for the [Generic] component.
class GenericClient extends Generic implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/components/gripper/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'gripper.dart';
/// gRPC client for the [Gripper] component.
class GripperClient extends Gripper implements ResourceRPCClient {
@override
ClientChannelBase channel;
final String name;

@override
String name;
ClientChannelBase channel;

@override
GripperServiceClient get client => GripperServiceClient(channel);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/motor/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'motor.dart';
/// gRPC client for the [Motor] component.
class MotorClient extends Motor implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/movement_sensor/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'movement_sensor.dart';
/// gRPC client for the [MovementSensor] component.
class MovementSensorClient extends MovementSensor implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/power_sensor/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'power_sensor.dart';
/// gRPC client for the [PowerSensor] component.
class PowerSensorClient extends PowerSensor implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/sensor/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'sensor.dart';
/// gRPC client for the [Sensor] component.
class SensorClient extends Sensor implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/servo/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'servo.dart';
/// gRPC client for the [Servo] component.
class ServoClient extends Servo implements ResourceRPCClient {
@override
String name;
final String name;

@override
ClientChannelBase channel;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/resource/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Subtype {

/// Abstract class that defines the base functionality for all [Resource] types
abstract class Resource {
abstract String name;
abstract final String name;

/// Send/Receive arbitrary commands to the [Resource]
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/resource/registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import '../components/sensor/sensor.dart';
import '../components/servo/client.dart';
import '../components/servo/servo.dart';
import '../resource/base.dart';
import '../services/vision.dart';

/// An object representing a resource to be registered.
///
Expand Down Expand Up @@ -65,6 +66,7 @@ class Registry {
registerSubtype(ResourceRegistration(PowerSensor.subtype, (name, channel) => PowerSensorClient(name, channel)));
registerSubtype(ResourceRegistration(Sensor.subtype, (name, channel) => SensorClient(name, channel)));
registerSubtype(ResourceRegistration(Servo.subtype, (name, channel) => ServoClient(name, channel)));
registerSubtype(ResourceRegistration(VisionClient.subtype, (name, channel) => VisionClient(name, channel)));
}

/// The [Subtype] available in the SDK
Expand Down
18 changes: 16 additions & 2 deletions lib/src/services/vision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import '../../protos/common/common.dart';
import '../../protos/service/vision.dart';
import '../media/image.dart';
import '../resource/base.dart';
import '../robot/client.dart';
import '../utils.dart';

class VisionClient implements ResourceRPCClient {
class VisionClient extends Resource implements ResourceRPCClient {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeService, 'vision');

@override
final String name;

@override
Expand Down Expand Up @@ -68,12 +72,22 @@ class VisionClient implements ResourceRPCClient {
return response.objects;
}

/// Send/Receive arbitrary commands to the Resource
@override
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) async {
final request = DoCommandRequest()
..name = name
..command = command.toStruct();
final response = await client.doCommand(request);
return response.result.toMap();
}

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

/// Get the [VisionClient] named [name] from the provided robot.
static VisionClient fromRobot(RobotClient robot, String name) {
return robot.getResource(VisionClient.getResourceName(name));
}
}

0 comments on commit b4a824d

Please sign in to comment.