Skip to content

Commit 7c144fb

Browse files
committed
wifi + speed + rotate + flip + goto
1 parent d3fec73 commit 7c144fb

File tree

8 files changed

+143
-1
lines changed

8 files changed

+143
-1
lines changed

src/cmds/flip.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { encode } from "../lib/text.ts";
2+
import DroneController from "../mod.ts";
3+
4+
/**
5+
* Flip in a direction
6+
* @param rotation Flip left (l), right (r), forward (f), back (b)
7+
*/
8+
9+
export function flip(this: DroneController, direction: "l" | "r" | "f" | "b") {
10+
return () =>
11+
this.socket.send(
12+
encode(`flip ${direction}`),
13+
this.options.telloPort,
14+
this.options.telloIP,
15+
);
16+
}

src/cmds/goto.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { encode } from "../lib/text.ts";
2+
import DroneController from "../mod.ts";
3+
4+
/**
5+
* Goto a specific location (requires mission pad??)
6+
* @param coords Coordinates of where you want to go (between -500 and 500)
7+
* @param speed 10 - 60
8+
* @param missionPad Go to the coodinates based on a certain mission pad
9+
*/
10+
11+
export function goto(
12+
this: DroneController,
13+
coords: { x: number; y: number; z: number },
14+
speed: number,
15+
missionPad?: "m1" | "m2" | "m3" | "m4" | "m5" | "m6" | "m7" | "m8",
16+
) {
17+
if (speed < 10 || speed > 60) {
18+
throw new Error("Speed needs to be between 10 and 60");
19+
}
20+
return () =>
21+
this.socket.send(
22+
encode(
23+
`go ${coords.x} ${coords.y} ${coords.x} ${speed}${
24+
missionPad && ` ${missionPad}`
25+
}`,
26+
),
27+
this.options.telloPort,
28+
this.options.telloIP,
29+
);
30+
}

src/cmds/mod.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import { emergency } from "./emergency.ts";
2+
import { flip } from "./flip.ts";
3+
import { goto } from "./goto.ts";
24
import { land } from "./land.ts";
5+
import { rotate } from "./rotate.ts";
6+
import { speed } from "./speed.ts";
37
import { takeOff } from "./takeoff.ts";
48
import { wait } from "./wait.ts";
9+
import { wifi } from "./wifi.ts";
510
import { xMovement } from "./xMovement.ts";
611
import { yMovement } from "./yMovement.ts";
12+
import { zMovement } from "./zMovement.ts";
713

8-
export { emergency, land, takeOff, wait, xMovement, yMovement };
14+
export {
15+
emergency,
16+
flip,
17+
goto,
18+
land,
19+
rotate,
20+
speed,
21+
takeOff,
22+
wait,
23+
wifi,
24+
xMovement,
25+
yMovement,
26+
zMovement,
27+
};

src/cmds/rotate.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { encode } from "../lib/text.ts";
2+
import DroneController from "../mod.ts";
3+
4+
/**
5+
* Rotate the drone clockwise or counterclockwise
6+
* @param rotation Rotate clockwise (+) or counterclockwise (-)
7+
*/
8+
9+
export function rotate(this: DroneController, rotation: number) {
10+
if (rotation > 360 || rotation == 0 || rotation < -360) {
11+
throw new Error("Invalid rotation number! Must be between 360 and -360");
12+
}
13+
const r = rotation > 0 ? `cw ${rotation}` : `ccw ${rotation * -1}`;
14+
return () =>
15+
this.socket.send(
16+
encode(r),
17+
this.options.telloPort,
18+
this.options.telloIP,
19+
);
20+
}

src/cmds/speed.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { encode } from "../lib/text.ts";
2+
import DroneController from "../mod.ts";
3+
4+
/**
5+
* Sets the speed in cm/s
6+
* @param newspeed Speed between 10 and 100 to set the speed to
7+
*/
8+
9+
export function speed(this: DroneController, newspeed: number) {
10+
if (newspeed > 100 || newspeed < 10) {
11+
throw new Error("Invalid speed number! Must be between 10 and 100");
12+
}
13+
14+
return () =>
15+
this.socket.send(
16+
encode(`speed ${newspeed}`),
17+
this.options.telloPort,
18+
this.options.telloIP,
19+
);
20+
}

src/cmds/wait.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { encode } from "../lib/text.ts";
22
import DroneController from "../mod.ts";
33

4+
/**
5+
* Function that adds time between other functions
6+
* @param delay Time you want to delay for (in ms)
7+
*/
48
export function wait(this: DroneController, delay: number) {
59
return () =>
610
new Promise<void>((resolve) =>

src/cmds/wifi.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { encode } from "../lib/text.ts";
2+
import DroneController from "../mod.ts";
3+
4+
/**
5+
* @param ssid Wifi ssid
6+
* @param password Wifi password
7+
* @param accessPoint Weather you're connecting to an access point or not (default off)
8+
*/
9+
export function wifi(
10+
this: DroneController,
11+
ssid: string,
12+
password: string,
13+
accessPoint = false,
14+
) {
15+
return () =>
16+
this.socket.send(
17+
encode(`${accessPoint ? "ap" : "wifi"} ${ssid} ${password}`),
18+
this.options.telloPort,
19+
this.options.telloIP,
20+
);
21+
}

src/mod.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import {
22
emergency,
3+
flip,
4+
goto,
35
land,
6+
rotate,
7+
speed,
48
takeOff,
59
wait,
10+
wifi,
611
xMovement,
712
yMovement,
13+
zMovement,
814
} from "./cmds/mod.ts";
915
import { dgram } from "./deps.ts";
1016
import { decode, encode } from "./lib/text.ts";
@@ -14,8 +20,14 @@ export default class DroneController {
1420
public wait = wait;
1521
public xMovement = xMovement;
1622
public yMovement = yMovement;
23+
public zMovement = zMovement;
1724
public land = land;
1825
public emergency = emergency;
26+
public flip = flip;
27+
public goto = goto;
28+
public rotate = rotate;
29+
public speed = speed;
30+
public wifi = wifi;
1931

2032
readonly options: Options;
2133
public socket!: dgram.Socket;

0 commit comments

Comments
 (0)