motion_commander

The MotionCommander is used to make it easy to write scripts that moves the Crazyflie around. Some sort of positioning support is required, for instance the Flow deck.

The motion commander uses velocity setpoints and does not have a notion of absolute position, the error in position will accumulate over time.

The API contains a set of primitives that are easy to understand and use, such as “go forward” or “turn around”.

There are two flavors of primitives, one that is blocking and returns when a motion is completed, while the other starts a motion and returns immediately. In the second variation the user has to stop or change the motion when appropriate by issuing new commands.

The MotionCommander 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

MotionCommander

MotionCommander(crazyflie, default_height=0.3)

The motion commander

Construct an instance of a MotionCommander

Parameters

Name Description
crazyflie A Crazyflie or SyncCrazyflie instance
default_height The default height to fly at

Class variables

RATE

VELOCITY

Methods

def back(self, distance_m, velocity=0.2)

Go backwards

Parameters

Name Description
distance_m The distance to travel (meters)
velocity The velocity of the motion (meters/second):return:

def circle_left(self, radius_m, velocity=0.2, angle_degrees=360.0)

Go in circle, counter clock wise

Parameters

Name Description
radius_m The radius of the circle (meters)
velocity The velocity along the circle (meters/second)
angle_degrees How far to go in the circle (degrees):return:

def circle_right(self, radius_m, velocity=0.2, angle_degrees=360.0)

Go in circle, clock wise

Parameters

Name Description
radius_m The radius of the circle (meters)
velocity The velocity along the circle (meters/second)
angle_degrees How far to go in the circle (degrees):return:

def down(self, distance_m, velocity=0.2)

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=0.2)

Go forward

Parameters

Name Description
distance_m The distance to travel (meters)
velocity The velocity of the motion (meters/second):return:

def land(self, velocity=0.2)

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=0.2)

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=0.2)

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=0.2)

Go right

Parameters

Name Description
distance_m The distance to travel (meters)
velocity The velocity of the motion (meters/second):return:

def start_back(self, velocity=0.2)

Start moving backwards. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def start_circle_left(self, radius_m, velocity=0.2)

Start a circular motion to the left. This function returns immediately.

Parameters

Name Description
radius_m The radius of the circle (meters)
velocity The velocity of the motion (meters/second):return:

def start_circle_right(self, radius_m, velocity=0.2)

Start a circular motion to the right. This function returns immediately

Parameters

Name Description
radius_m The radius of the circle (meters)
velocity The velocity of the motion (meters/second):return:

def start_down(self, velocity=0.2)

Start moving down. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def start_forward(self, velocity=0.2)

Start moving forward. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def start_left(self, velocity=0.2)

Start moving left. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def start_linear_motion(self, velocity_x_m, velocity_y_m, velocity_z_m, rate_yaw=0.0)

Start a linear motion with an optional yaw rate input. This function returns immediately.

positive X is forward positive Y is left positive Z is up

Parameters

Name Description
velocity_x_m The velocity along the X-axis (meters/second)
velocity_y_m The velocity along the Y-axis (meters/second)
velocity_z_m The velocity along the Z-axis (meters/second)
rate The angular rate (degrees/second):return:

def start_right(self, velocity=0.2)

Start moving right. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def start_turn_left(self, rate=72.0)

Start turning left. This function returns immediately.

Parameters

Name Description
rate The angular rate (degrees/second):return:

def start_turn_right(self, rate=72.0)

Start turning right. This function returns immediately.

Parameters

Name Description
rate The angular rate (degrees/second):return:

def start_up(self, velocity=0.2)

Start moving up. This function returns immediately.

Parameters

Name Description
velocity The velocity of the motion (meters/second):return:

def stop(self)

Stop any motion and hover.

:return:


def take_off(self, height=None, velocity=0.2)

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 turn_left(self, angle_degrees, rate=72.0)

Turn to the left, staying on the spot

Parameters

Name Description
angle_degrees How far to turn (degrees)
rate The turning speed (degrees/second):return:

def turn_right(self, angle_degrees, rate=72.0)

Turn to the right, staying on the spot

Parameters

Name Description
angle_degrees How far to turn (degrees)
rate The turning speed (degrees/second):return:

def up(self, distance_m, velocity=0.2)

Go up

Parameters

Name Description
distance_m The distance to travel (meters)
velocity The velocity of the motion (meters/second):return: