From 369f33ff1c9ad511dd2cbed2d157bf2fbeb16ffd Mon Sep 17 00:00:00 2001 From: Nicole Jung <31713368+purplenicole730@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:27:24 -0400 Subject: [PATCH] RSDK-5426 - update motion service with obstacle detectors (#186) --- buf.lock | 4 ++-- src/components/sensor/client.ts | 15 +++++++++------ src/main.ts | 1 + src/services/motion.ts | 1 + src/services/motion/types.ts | 14 ++++++++++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/buf.lock b/buf.lock index 9ee74e78c..0b62e85d3 100644 --- a/buf.lock +++ b/buf.lock @@ -14,8 +14,8 @@ deps: - remote: buf.build owner: viamrobotics repository: api - commit: 2109757288234ffc8248121f60437cdd - digest: shake256:18027527c16555ead747df632f73fecce3e2e489da437a35c175826d89472cce8323f32b9fa74261ca322e58e81aedcfce4d7cdc776b65eceb57dacacfe4822d + commit: 9196e89cb02f40d6b38344d637fdb3fc + digest: shake256:45153f9922a876347f1b3cf7db9d35a76ff045e5a72b83fc7d6e89d1e899ff53b2d3930c36f7ce8aac704fb57f60dd9cbdba61224c8df51b1044a1ff9882ba15 - remote: buf.build owner: viamrobotics repository: goutils diff --git a/src/components/sensor/client.ts b/src/components/sensor/client.ts index 3b9d4dc95..f4ee1a5be 100644 --- a/src/components/sensor/client.ts +++ b/src/components/sensor/client.ts @@ -5,7 +5,10 @@ import type { Options, StructType } from '../../types'; import { SensorServiceClient } from '../../gen/component/sensor/v1/sensor_pb_service'; import { promisify, doCommandFromClient } from '../../utils'; -import sensorApi from '../../gen/component/sensor/v1/sensor_pb'; +import { + GetReadingsRequest, + GetReadingsResponse, +} from '../../gen/common/v1/common_pb'; import type { Sensor } from './sensor'; /** @@ -30,16 +33,16 @@ export class SensorClient implements Sensor { async getReadings(extra = {}) { const { sensorService } = this; - const request = new sensorApi.GetReadingsRequest(); + const request = new GetReadingsRequest(); request.setName(this.name); request.setExtra(Struct.fromJavaScript(extra)); this.options.requestLogger?.(request); - const response = await promisify< - sensorApi.GetReadingsRequest, - sensorApi.GetReadingsResponse - >(sensorService.getReadings.bind(sensorService), request); + const response = await promisify( + sensorService.getReadings.bind(sensorService), + request + ); const result: Record = {}; for (const [key, value] of response.getReadingsMap().entries()) { diff --git a/src/main.ts b/src/main.ts index 25f71f3b9..ebca0440d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -309,6 +309,7 @@ export { type Motion, type Constraints, type LinearConstraint, + type ObstacleDetector, type OrientationConstraint, type CollisionSpecification, type MotionConfiguration, diff --git a/src/services/motion.ts b/src/services/motion.ts index 8fe9dbe93..6be7df5e7 100644 --- a/src/services/motion.ts +++ b/src/services/motion.ts @@ -2,6 +2,7 @@ export type { Motion } from './motion/motion'; export type { Constraints, LinearConstraint, + ObstacleDetector, OrientationConstraint, CollisionSpecification, MotionConfiguration, diff --git a/src/services/motion/types.ts b/src/services/motion/types.ts index 2ed7b7a50..d9755c394 100644 --- a/src/services/motion/types.ts +++ b/src/services/motion/types.ts @@ -2,6 +2,7 @@ import pb from '../../gen/service/motion/v1/motion_pb'; import { encodeResourceName } from '../../utils'; export type Constraints = pb.Constraints.AsObject; +export type ObstacleDetector = pb.ObstacleDetector.AsObject; export type LinearConstraint = pb.LinearConstraint.AsObject; export type OrientationConstraint = pb.OrientationConstraint.AsObject; export type CollisionSpecification = pb.CollisionSpecification.AsObject; @@ -65,8 +66,17 @@ export const encodeMotionConfiguration = ( ): pb.MotionConfiguration => { const result = new pb.MotionConfiguration(); - result.setVisionServicesList( - obj.visionServicesList.map((x) => encodeResourceName(x)) + result.setObstacleDetectorsList( + obj.obstacleDetectorsList.map((x: ObstacleDetector) => { + const obstacleDetector = new pb.ObstacleDetector(); + if (x.visionService) { + obstacleDetector.setVisionService(encodeResourceName(x.visionService)); + } + if (x.camera) { + obstacleDetector.setCamera(encodeResourceName(x.camera)); + } + return obstacleDetector; + }) ); result.setPositionPollingFrequencyHz(obj.positionPollingFrequencyHz); result.setObstaclePollingFrequencyHz(obj.obstaclePollingFrequencyHz);