Skip to content

Commit

Permalink
added new control commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kanekotic committed Dec 13, 2018
1 parent 332e55a commit c6b5498
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,14 @@ this sdk provide functions when you import for the next capabilities:

```js
const sdk = require('tellojs')

const x = number,
y = number,
z = number,
speed = number,
start = {x, y, z},
end = {x, y, z}

//CONTROL COMMANDS
await sdk.control.connect() // Enter SDK mode.
await sdk.control.takeoff() // Auto takeoff.
Expand All @@ -24,6 +32,8 @@ await sdk.control.move.left(x) // move left to “x” cm.
await sdk.control.move.right(x) // move right to “x” cm.
await sdk.control.move.front(x) // move forward to “x” cm.
await sdk.control.move.back(x) // move backwards to “x” cm.
await sdk.control.move.go(end, speed ) // fly to x y z in speed (cm/s)
await sdk.control.move.curve(start, end, speed) // fly to x y z in speed (cm/s)
await sdk.control.rotate.clockwise(x) // rotate clockwise 'x' degrees.
await sdk.control.rotate.counterClockwise(x) // rotate counter clockwise 'x' degrees.
await sdk.control.flip.left() // Flip to the left.
Expand Down
6 changes: 6 additions & 0 deletions src/commands/control.js
Expand Up @@ -28,12 +28,18 @@ const clockwise = (angle) => commander.send(`cw ${angle}`)

const counterClockwise = (angle) => commander.send(`ccw ${angle}`)

const go = (end,speed) => commander.send(`go ${end.x} ${end.y} ${end.z} ${speed}`)

const curve = (start, end,speed) => commander.send(`curve ${start.x} ${start.y} ${start.z} ${end.x} ${end.y} ${end.z} ${speed}`)

module.exports = {
connect,
takeOff,
land,
emergency,
stop,
go,
curve,
move: { up, down, left, right, back, front },
rotate: { clockwise, counterClockwise },
flip: {
Expand Down
27 changes: 27 additions & 0 deletions test/commands/control-test.js
Expand Up @@ -100,4 +100,31 @@ describe('control commands', () => {
expect(commander.send).toBeCalledWith(`ccw ${angle}`)
})

it('should have command for go to position', () => {
const end = {
x: faker.random.number(500),
y: faker.random.number(500),
z: faker.random.number(500)
}
const speed = faker.random.number(100)
controlCommands.go(end,speed)
expect(commander.send).toBeCalledWith(`go ${end.x} ${end.y} ${end.z} ${speed}`)
})

it('should have command for curve to position', () => {
const start = {
x: faker.random.number(500),
y: faker.random.number(500),
z: faker.random.number(500)
},
end = {
x: faker.random.number(500),
y: faker.random.number(500),
z: faker.random.number(500)
},
speed = faker.random.number(100)
controlCommands.curve(start, end, speed)
expect(commander.send).toBeCalledWith(`curve ${start.x} ${start.y} ${start.z} ${end.x} ${end.y} ${end.z} ${speed}`)
})

})

0 comments on commit c6b5498

Please sign in to comment.