Used for sending high level setpoints to the Crazyflie.
The high level commander generates setpoints from within the firmware based on a predefined trajectory. This was merged as part of the Crazyswarm project of the USC ACT lab. The high level commander uses a planner to generate smooth trajectories based on actions like “take off”, “go to” or “land” with 7th order polynomials.
Classes
HighLevelCommander
HighLevelCommander(crazyflie=None)
Used for sending high level setpoints to the Crazyflie
Initialize the object.
Class variables
ALL_GROUPS
COMMAND_DEFINE_TRAJECTORY
COMMAND_GO_TO
COMMAND_GO_TO_2
COMMAND_LAND_2
COMMAND_SET_GROUP_MASK
COMMAND_SPIRAL
COMMAND_START_TRAJECTORY
COMMAND_STOP
COMMAND_TAKEOFF_2
TRAJECTORY_LOCATION_MEM
TRAJECTORY_TYPE_POLY4D
TRAJECTORY_TYPE_POLY4D_COMPRESSED
Methods
def define_trajectory(self, trajectory_id, offset, n_pieces, type=0)
Define a trajectory that has previously been uploaded to memory.
Parameters
Name | Description |
---|---|
trajectory_id | The id of the trajectory |
offset | Offset in uploaded memory |
n_pieces | Nr of pieces in the trajectory |
type | The type of trajectory data; TRAJECTORY_TYPE_POLY4D or TRAJECTORY_TYPE_POLY4D_COMPRESSED:return: |
def go_to(self, x, y, z, yaw, duration_s, relative=False, linear=False, group_mask=0)
Go to an absolute or relative position.
The path is designed to transition smoothly from the current state to the target position, gradually decelerating at the goal with minimal overshoot. When the system is at hover, the path will be a straight line, but if there is any initial velocity, the path will be a smooth curve.
The trajectory is derived by solving for a unique 7th-degree polynomial that satisfies the initial conditions of position, velocity, and acceleration, and ends at the goal with zero velocity and acceleration. Additionally, the jerk (derivative of acceleration) is constrained to be zero at both the starting and ending points.
Warning! Avoid overlapping go_to commands. When a command is sent to a Crazyflie when another one is currently executed, the generated polynomial can take unexpected routes and have high peaks.
Parameters
Name | Description |
---|---|
x | X (m) |
y | Y (m) |
z | Z (m) |
yaw | Yaw (radians) |
duration_s | Time it should take to reach the position (s) |
relative | True if x, y, z is relative to the current position |
linear | True to use linear interpolation instead of a smooth polynomial |
group_mask | Mask for which CFs this should apply to |
def land(self, absolute_height_m, duration_s, group_mask=0, yaw=0.0)
vertical land from current x-y position to given height
Parameters
Name | Description |
---|---|
absolute_height_m | Absolute (m) |
duration_s | Time it should take until target height is reached (s) |
group_mask | Mask for which CFs this should apply to |
yaw | Yaw (rad). Use current yaw if set to None. |
def set_group_mask(self, group_mask=0)
Set the group mask that the Crazyflie belongs to
Parameters
Name | Description |
---|---|
group_mask | Mask for which groups this CF belongs to |
def spiral(self, angle, r0, rF, ascent, duration_s, sideways=False, clockwise=False, group_mask=0)
Follow a spiral-like segment (spline approximation of a spiral/arc for <= 90-degree segments)
Parameters
Name | Description |
---|---|
angle | spiral angle (rad), limited to +/- 2pi |
r0 | initial radius (m), must be positive |
rF | final radius (m), must be positive |
ascent | altitude gain (m), positive to climb, negative to descent |
duration_s | time it should take to reach the end of the spiral (s) |
sideways | true if crazyflie should spiral sideways instead of forward |
clockwise | true if crazyflie should spiral clockwise instead of counter-clockwise |
group_mask | Mask for which CFs this should apply to |
def start_trajectory(self, trajectory_id, time_scale=1.0, relative=False, reversed=False, group_mask=0)
starts executing a specified trajectory
Parameters
Name | Description |
---|---|
trajectory_id | Id of the trajectory (previously defined by define_trajectory) |
time_scale | Time factor; 1.0 = original speed; >1.0: slower; <1.0: faster |
relative | Set to True, if trajectory should be shifted to current setpoint |
reversed | Set to True, if trajectory should be executed in reverse |
group_mask | Mask for which CFs this should apply to:return: |
def stop(self, group_mask=0)
stops the current trajectory (turns off the motors)
Parameters
Name | Description |
---|---|
group_mask | Mask for which CFs this should apply to:return: |
def takeoff(self, absolute_height_m, duration_s, group_mask=0, yaw=0.0)
vertical takeoff from current x-y position to given height
Parameters
Name | Description |
---|---|
absolute_height_m | Absolute (m) |
duration_s | Time it should take until target height is reached (s) |
group_mask | Mask for which CFs this should apply to |
yaw | Yaw (rad). Use current yaw if set to None. |