The PositionHlCommander is used to make it easy to write scripts that moves the Crazyflie around. Some sort of positioning support is required, for instance the Loco Positioning System. The implementation uses the High Level Commander and position setpoints.
The API contains a set of primitives that are easy to understand and use, such as “go forward” or “turn around”.
The PositionHlCommander can be used as context manager using the with keyword. In this mode of operation takeoff and landing is executed when the context is created/closed.
Classes
PositionHlCommander
PositionHlCommander(crazyflie, x=0.0, y=0.0, z=0.0, default_velocity=0.5, default_height=0.5, controller=None, default_landing_height=0.0)
The position High Level Commander
Construct an instance of a PositionHlCommander
Parameters
Name | Description |
---|---|
crazyflie | A Crazyflie or SyncCrazyflie instance |
x | Initial position, x |
y | Initial position, y |
z | Initial position, z |
default_velocity | The default velocity to use |
default_height | The default height to fly at |
controller | Which underlying controller to use |
default_landing_height | Landing height (zero if not specified); for landing on objects off the ground |
Class variables
CONTROLLER_MELLINGER
CONTROLLER_PID
DEFAULT
Methods
def back(self, distance_m, velocity=None)
Go backwards
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |
def down(self, distance_m, velocity=None)
Go down
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |
def forward(self, distance_m, velocity=None)
Go forward
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |
def get_position(self)
Get the current position :return: (x, y, z)
def go_to(self, x, y, z=None, velocity=None)
Go to a position
Parameters
Name | Description |
---|---|
x | X coordinate |
y | Y coordinate |
z | Z coordinate |
velocity | The velocity (meters/second):return: |
def land(self, velocity=None, landing_height=None)
Go straight down and turn off the motors.
Do not call this function if you use the with keyword. Landing is done automatically when the context goes out of scope.
Parameters
Name | Description |
---|---|
velocity | The velocity (meters/second) when going down:return: |
def left(self, distance_m, velocity=None)
Go left
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |
def move_distance(self, distance_x_m, distance_y_m, distance_z_m, velocity=None)
Move in a straight line. positive X is forward positive Y is left positive Z is up
Parameters
Name | Description |
---|---|
distance_x_m | The distance to travel along the X-axis (meters) |
distance_y_m | The distance to travel along the Y-axis (meters) |
distance_z_m | The distance to travel along the Z-axis (meters) |
velocity | The velocity of the motion (meters/second):return: |
def right(self, distance_m, velocity=None)
Go right
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |
def set_default_height(self, height)
Set the default height to use in commands when no height is defined
Parameters
Name | Description |
---|---|
height | The default height (meters):return: |
def set_default_velocity(self, velocity)
Set the default velocity to use in commands when no velocity is defined
Parameters
Name | Description |
---|---|
velocity | The default velocity (meters/s):return: |
def set_landing_height(self, landing_height)
Set the landing height to a specific value Use this function to land on objects that are at non-zero height
def take_off(self, height=None, velocity=None)
Takes off, that is starts the motors, goes straight up and hovers. Do not call this function if you use the with keyword. Take off is done automatically when the context is created.
Parameters
Name | Description |
---|---|
height | The height (meters) to hover at. None uses the default height set when constructed. |
velocity | The velocity (meters/second) when taking off:return: |
def up(self, distance_m, velocity=None)
Go up
Parameters
Name | Description |
---|---|
distance_m | The distance to travel (meters) |
velocity | The velocity of the motion (meters/second):return: |