-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdecision_command.py
151 lines (129 loc) · 4.99 KB
/
decision_command.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
Commands for the decision module.
"""
import enum
class DecisionCommand:
"""
Contains command type and coordinate data.
All coordinate values use the NED coordinate system. Positive x is north,
positive y is east, positive z is down.
The following constructors are available for different command types:
* Command.create_move_to_relative_position_command
* Command.create_move_to_absolute_position_command
* Command.create_land_at_current_position_command
* Command.create_land_at_relative_position_command
* Command.create_land_at_absolute_position_command
"""
__create_key = object()
class CommandType(enum.Enum):
"""
Different types of commands.
"""
MOVE_TO_RELATIVE_POSITION = 0 # Move relative to current position
MOVE_TO_ABSOLUTE_POSITION = 1 # Move to absolute position within local space
LAND_AT_CURRENT_POSITION = 2 # Stop the drone at current position
LAND_AT_RELATIVE_POSITION = 3 # Stop the drone at relative position within local space
LAND_AT_ABSOLUTE_POSITION = 4 # Stop the drone at absolute position within local space
@classmethod
def create_move_to_relative_position_command(
cls, relative_x: float, relative_y: float, relative_z: float
) -> "DecisionCommand":
"""
Command for drone movement relative to current position, using
the NED coordinate system. (+x, +y, +z) corresponds to the north, east, and down directions.
"""
return DecisionCommand(
cls.__create_key,
DecisionCommand.CommandType.MOVE_TO_RELATIVE_POSITION,
relative_x,
relative_y,
relative_z,
)
@classmethod
def create_move_to_absolute_position_command(
cls, absolute_x: float, absolute_y: float, absolute_z: float
) -> "DecisionCommand":
"""
Command for drone movement to absolute position within local space, using
the NED coordinate system. (+x, +y, +z) corresponds to the north, east, and down directions.
"""
return DecisionCommand(
cls.__create_key,
DecisionCommand.CommandType.MOVE_TO_ABSOLUTE_POSITION,
absolute_x,
absolute_y,
absolute_z,
)
@classmethod
def create_land_at_current_position_command(cls) -> "DecisionCommand":
"""
Command for landing at current position.
"""
return DecisionCommand(
cls.__create_key, DecisionCommand.CommandType.LAND_AT_CURRENT_POSITION, 0.0, 0.0, 0.0
)
@classmethod
def create_land_at_relative_position_command(
cls, relative_x: float, relative_y: float, relative_z: float
) -> "DecisionCommand":
"""
Command to land the drone at a relative position within local space, using
the NED coordinate system. (+x, +y, +z) corresponds to the north, east, and down directions.
"""
return DecisionCommand(
cls.__create_key,
DecisionCommand.CommandType.LAND_AT_RELATIVE_POSITION,
relative_x,
relative_y,
relative_z,
)
@classmethod
def create_land_at_absolute_position_command(
cls, absolute_x: float, absolute_y: float, absolute_z: float
) -> "DecisionCommand":
"""
Command to land the drone at an absolute position within local space, using
the NED coordinate system. (+x, +y, +z) corresponds to the north, east, and down directions.
"""
return DecisionCommand(
cls.__create_key,
DecisionCommand.CommandType.LAND_AT_ABSOLUTE_POSITION,
absolute_x,
absolute_y,
absolute_z,
)
def __init__(
self,
class_private_create_key: object,
command_type: CommandType,
command_x: float,
command_y: float,
command_z: float,
) -> None:
"""
Private constructor, use create() method.
"""
assert class_private_create_key is DecisionCommand.__create_key, "Use create() method"
self.__command_type = command_type
self.__command_x = command_x
self.__command_y = command_y
self.__command_z = command_z
def get_command_type(self) -> CommandType:
"""
Returns the command type enum.
"""
return self.__command_type
def get_command_position(self) -> "tuple[float, float, float]":
"""
Returns the command position in x, y, z tuple, using
the NED coordinate system. (+x, +y, +z) corresponds to the north, east, and down directions.
"""
return self.__command_x, self.__command_y, self.__command_z
def __str__(self) -> str:
"""
To string.
"""
representation = f"Command: {self.__command_type}"
if self.__command_type != DecisionCommand.CommandType.LAND_AT_CURRENT_POSITION:
representation += f" {self.get_command_position()}"
return representation