Skip to content

Commit

Permalink
RSDK-5426 - update motion service with obstacle detectors (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 authored Nov 2, 2023
1 parent c817ae4 commit 369f33f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/components/sensor/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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<GetReadingsRequest, GetReadingsResponse>(
sensorService.getReadings.bind(sensorService),
request
);

const result: Record<string, unknown> = {};
for (const [key, value] of response.getReadingsMap().entries()) {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export {
type Motion,
type Constraints,
type LinearConstraint,
type ObstacleDetector,
type OrientationConstraint,
type CollisionSpecification,
type MotionConfiguration,
Expand Down
1 change: 1 addition & 0 deletions src/services/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type { Motion } from './motion/motion';
export type {
Constraints,
LinearConstraint,
ObstacleDetector,
OrientationConstraint,
CollisionSpecification,
MotionConfiguration,
Expand Down
14 changes: 12 additions & 2 deletions src/services/motion/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 369f33f

Please sign in to comment.