Skip to content

Commit

Permalink
add IMU client APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Jul 10, 2019
1 parent 9bf934a commit c06c99b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
17 changes: 16 additions & 1 deletion hedgehog/client/hedgehogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { RequestMsg, ReplyMsg, Message,
ack, version, emergency, io, analog, digital, motor, servo, process } from '../protocol';
ack, version, emergency, io, analog, digital, motor, servo, imu, process } from '../protocol';

export { AcknowledgementCode } from '../protocol/messages/ack';
export { IOFlags } from '../protocol/messages/io';
Expand Down Expand Up @@ -188,6 +188,21 @@ export class HedgehogClient {
return reply.position;
}

public async getImuRate(): Promise<[number, number, number]> {
let reply = await this.send<imu.RateReply>(new imu.RateRequest());
return [reply.x, reply.y, reply.z];
}

public async getImuAcceleration(): Promise<[number, number, number]> {
let reply = await this.send<imu.AccelerationReply>(new imu.AccelerationRequest());
return [reply.x, reply.y, reply.z];
}

public async getImuPose(): Promise<[number, number, number]> {
let reply = await this.send<imu.PoseReply>(new imu.PoseRequest());
return [reply.x, reply.y, reply.z];
}

public close () {
this.socket.close();
}
Expand Down
26 changes: 25 additions & 1 deletion test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@babel/polyfill";
import * as assert from 'assert';
import * as zmq from 'zeromq';

import { HedgehogClient, protocol, Message, ack, version, emergency, io, analog, digital, motor, servo } from "../hedgehog";
import { HedgehogClient, protocol, Message, ack, version, emergency, io, analog, digital, motor, servo, imu } from "../hedgehog";

describe('Client', () => {
let server = null;
Expand Down Expand Up @@ -212,6 +212,30 @@ describe('Client', () => {
assert.strictEqual(await hedgehog.getServoPosition(0), 1000);
});

it('`getImuRate` should work', async () => {
mock_server(
[[new imu.RateRequest()], [new imu.RateReply(0, 0, 0)]],
);

assert.deepStrictEqual(await hedgehog.getImuRate(), [0, 0, 0]);
});

it('`getImuAcceleration` should work', async () => {
mock_server(
[[new imu.AccelerationRequest()], [new imu.AccelerationReply(0, 0, 0)]],
);

assert.deepStrictEqual(await hedgehog.getImuAcceleration(), [0, 0, 0]);
});

it('`getImuPose` should work', async () => {
mock_server(
[[new imu.PoseRequest()], [new imu.PoseReply(0, 0, 0)]],
);

assert.deepStrictEqual(await hedgehog.getImuPose(), [0, 0, 0]);
});

after(() => {
hedgehog.close();
hedgehog = null;
Expand Down

0 comments on commit c06c99b

Please sign in to comment.