forked from ajmwagar/ufo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraits.rs
109 lines (80 loc) · 3.62 KB
/
traits.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// Mod for traits regarding onboard functions. (i.e. Camera stream, LEDs, barometer, battery status, etc)
pub mod drone {
use std::error::Error;
// TODO Calibration trait
/// Trait for drone calibration
pub trait Calibrate {
/// Calibrate the drone
fn calibrate(&mut self) -> Result<(), Box<dyn Error>>;
}
pub trait Stop {
fn stop(&mut self) -> Result<(), Box<dyn Error>>;
}
/// Trait for drones that can hover
pub trait Hover {
/// Enable hover mode
fn hover(&mut self) -> Result<(), Box<dyn Error>>;
}
// TODO Emergency trait
// TODO VideoStream trait
// TODO PhotoStream trait
// TODO ReturnToSender trait
}
/// Mod for exposed control traits of drones (i.e. functions that affect rotor stats and
/// calibration)
pub mod control {
use std::error::Error;
/// pub trait for drones that can flip
pub trait Flips {
/// Preforms a Front Flip
fn front_flip() -> Result<(), Box<dyn Error>>;
/// Preforms a Back Flip
fn back_flip() -> Result<(), Box<dyn Error>>;
/// Side flip left
fn left_flip() -> Result<(), Box<dyn Error>>;
/// Side flip right
fn righ_flip() -> Result<(), Box<dyn Error>>;
}
/// pub trait for drones that can do multi-dimensional flips (i.e. front + left at the same time)
pub trait MultiFlips {
/// Performs a front flip & a left-side flip at the same time
fn front_left_flip() -> Result<(), Box<dyn Error>>;
/// Performs a front flip & a right-side flip at the same time
fn front_right_flip() -> Result<(), Box<dyn Error>>;
/// Performs a back flip & a left-side flip at the same time
fn back_left_flip() -> Result<(), Box<dyn Error>>;
/// Performs a back flip & a right-side flip at the same time
fn back_right_flip() -> Result<(), Box<dyn Error>>;
}
/// Movement pub trait (i.e. controls for Up, Down, Forward, Backwards, Left and Right);
pub trait Movement {
// TODO Determine length of time parameter (milliseconds or seconds)
// X Axis
/// Move the drone left for n milliseconds (takes in a usize)
fn left(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
/// Move the drone right for n milliseconds (takes in a usize)
fn right(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
// Y Axis
/// Move the drone up for n milliseconds (takes in a usize)
fn up(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
/// Move the drone down for n milliseconds (takes in a usize)
fn down(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
// Z Axis
/// Move the drone forwards for n milliseconds (takes in a usize)
fn forwards(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
/// Move the drone backwards for n milliseconds (takes in a usize)
fn backwards(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
// TODO Determine length of time parameter (milliseconds or seconds)
/// Move the drone left for n milliseconds (takes in a usize)
fn rot_left(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
/// Move the drone right for n milliseconds (takes in a usize)
fn rot_right(&mut self, time: usize) -> Result<(), Box<dyn Error>>;
}
/// pub trait for Takeoff and Landing
pub trait FlightControl {
/// Performs a takeoff
fn take_off(&mut self) -> Result<(), Box<dyn Error>>;
/// Performs a landing
fn land(&mut self) -> Result<(), Box<dyn Error>>;
}
}