Skip to content

Commit 98b8e0e

Browse files
Add armClient.getKinematics() (#664)
1 parent f01aa40 commit 98b8e0e

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

examples/teleop-react/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.env
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
pnpm-debug.log*
10+
lerna-debug.log*
11+
12+
node_modules
13+
dist
14+
dist-ssr
15+
*.local
16+
17+
# Editor directories and files
18+
.vscode/*
19+
!.vscode/extensions.json
20+
.idea
21+
.DS_Store
22+
*.suo
23+
*.ntvs*
24+
*.njsproj
25+
*.sln
26+
*.sw?

examples/teleop-react/src/components/connect-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const ConnectForm = (props: ConnectFormProps): JSX.Element => {
5252
setApiKeyId(event.target.value);
5353
};
5454
const handleApiKey: ChangeEventHandler<HTMLInputElement> = (event) => {
55-
setApiKeyId(event.target.value);
55+
setApiKey(event.target.value);
5656
};
5757
const handleSubmit: FormEventHandler = (event) => {
5858
onSubmit({ hostname, apiKeyId, apiKey });

src/components/arm/arm.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { PlainMessage, Struct } from '@bufbuild/protobuf';
2-
import type { Pose, Resource } from '../../types';
2+
import type { Pose, Resource, Vector3 } from '../../types';
33

44
import * as armApi from '../../gen/component/arm/v1/arm_pb';
55
import type { Geometry } from '../../gen/common/v1/common_pb';
6+
import type { Frame } from '../../gen/app/v1/robot_pb';
67

78
export type ArmJointPositions = PlainMessage<armApi.JointPositions>;
89

@@ -41,6 +42,34 @@ export interface Arm extends Resource {
4142
*/
4243
getGeometries: (extra?: Struct) => Promise<Geometry[]>;
4344

45+
/**
46+
* Get the kinematics information associated with the arm.
47+
*
48+
* @example
49+
*
50+
* ```ts
51+
* const arm = new VIAM.ArmClient(machine, 'my_arm');
52+
* const kinematics = await arm.getKinematics();
53+
* console.log(kinematics);
54+
*
55+
* For more information, see [Arm
56+
* API](https://docs.viam.com/dev/reference/apis/components/arm/#getkinematics).
57+
* ```
58+
*/
59+
getKinematics: (extra?: Struct) => Promise<{
60+
name: string;
61+
kinematic_param_type: 'SVA' | 'URDF' | 'UNSPECIFIED';
62+
joints: {
63+
id: string;
64+
type: string;
65+
parent: string;
66+
axis: Vector3;
67+
max: number;
68+
min: number;
69+
}[];
70+
links: Frame[];
71+
}>;
72+
4473
/**
4574
* Move the end of the arm to the pose.
4675
*

src/components/arm/client.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import type { RobotClient } from '../../robot';
1414
import type { Options, Pose } from '../../types';
1515
import { doCommandFromClient } from '../../utils';
1616
import type { Arm } from './arm';
17-
import { GetGeometriesRequest } from '../../gen/common/v1/common_pb';
17+
import {
18+
GetGeometriesRequest,
19+
GetKinematicsRequest,
20+
} from '../../gen/common/v1/common_pb';
1821

1922
/**
2023
* A gRPC-web client for the Arm component.
@@ -59,6 +62,20 @@ export class ArmClient implements Arm {
5962
return response.geometries;
6063
}
6164

65+
async getKinematics(extra = {}, callOptions = this.callOptions) {
66+
const request = new GetKinematicsRequest({
67+
name: this.name,
68+
extra: Struct.fromJson(extra),
69+
});
70+
71+
const response = await this.client.getKinematics(request, callOptions);
72+
73+
const decoder = new TextDecoder('utf8');
74+
const jsonString = decoder.decode(response.kinematicsData);
75+
76+
return JSON.parse(jsonString) as ReturnType<Arm['getKinematics']>;
77+
}
78+
6279
async moveToPosition(pose: Pose, extra = {}, callOptions = this.callOptions) {
6380
const request = new MoveToPositionRequest({
6481
name: this.name,

0 commit comments

Comments
 (0)