motion_commander – Simple controls built on Commander

The MotionCommander is used to make it easy to write scripts that move 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.

class motion_commander.MotionCommander(commander, func_set_param, default_height=0.3)[source]

The motion commander

Construct an instance of a MotionCommander

Parameters:
  • commander – Instance of Commander class

  • func_set_param – Function object ‘set_param(name, value)’

  • crazyflie – A Crazyflie or SyncCrazyflie instance

  • default_height – The default height to fly at

back(distance_m, velocity=0.2)[source]

Go backwards

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

circle_left(radius_m, velocity=0.2, angle_degrees=360.0)[source]

Go in circle, counter clock wise

Parameters:
  • 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)

Returns:

circle_right(radius_m, velocity=0.2, angle_degrees=360.0)[source]

Go in circle, clock wise

Parameters:
  • 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)

Returns:

down(distance_m, velocity=0.2)[source]

Go down

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

enable_flying(do_enable)[source]

Enable or disable flight. After enabling, you must delay for at least 1 second to allow the kalman filter to stabilize before taking off.

Parameters:

do_enable – True to enable flying mode, False to disable

forward(distance_m, velocity=0.2)[source]

Go forward

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

is_flying()[source]

Check if currently flying

land(velocity=0.2)[source]

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:

velocity – The velocity (meters/second) when going down

Returns:

left(distance_m, velocity=0.2)[source]

Go left

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

move_distance(distance_x_m, distance_y_m, distance_z_m, velocity=0.2)[source]

Move in a straight line. positive X is forward positive Y is left positive Z is up

Parameters:
  • 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)

Returns:

right(distance_m, velocity=0.2)[source]

Go right

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

start_back(velocity=0.2)[source]

Start moving backwards. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

start_circle_left(radius_m, velocity=0.2)[source]

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

Parameters:
  • radius_m – The radius of the circle (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

start_circle_right(radius_m, velocity=0.2)[source]

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

Parameters:
  • radius_m – The radius of the circle (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

start_down(velocity=0.2)[source]

Start moving down. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

start_forward(velocity=0.2)[source]

Start moving forward. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

start_left(velocity=0.2)[source]

Start moving left. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

start_linear_motion(velocity_x_m, velocity_y_m, velocity_z_m, rate_yaw=0.0)[source]

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:
  • 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)

Returns:

start_right(velocity=0.2)[source]

Start moving right. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

start_turn_left(rate=72.0)[source]

Start turning left. This function returns immediately.

Parameters:

rate – The angular rate (degrees/second)

Returns:

start_turn_right(rate=72.0)[source]

Start turning right. This function returns immediately.

Parameters:

rate – The angular rate (degrees/second)

Returns:

start_up(velocity=0.2)[source]

Start moving up. This function returns immediately.

Parameters:

velocity – The velocity of the motion (meters/second)

Returns:

steady(seconds=0)[source]

Hold steady on set course for specified duration. This function will update the flight controller periodically during the wait. Passing 0 will update without delay (non-blocking).

Parameters:

seconds – The time to hold steady (seconds)

stop()[source]

Stop any motion and hover.

Returns:

take_off(height=None, velocity=0.2)[source]

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:
  • height – The height (meters) to hover at. None uses the default height set when constructed.

  • velocity – The velocity (meters/second) when taking off

Returns:

turn_left(angle_degrees, rate=72.0)[source]

Turn to the left, staying on the spot

Parameters:
  • angle_degrees – How far to turn (degrees)

  • rate – The turning speed (degrees/second)

Returns:

turn_right(angle_degrees, rate=72.0)[source]

Turn to the right, staying on the spot

Parameters:
  • angle_degrees – How far to turn (degrees)

  • rate – The turning speed (degrees/second)

Returns:

up(distance_m, velocity=0.2)[source]

Go up

Parameters:
  • distance_m – The distance to travel (meters)

  • velocity – The velocity of the motion (meters/second)

Returns:

class motion_commander.SetpointTracker(commander)[source]

Replaces cflib SetPointThread. Track current setpoint and poll/update the commander. * Use self.poll_for(seconds) rather than time.sleep() to keep feeding setpoints. * To do async tasks, you’ll need to call self.update() periodically.

get_height()[source]

Get current height

new_vel(velocity_x, velocity_y, velocity_z, rate_yaw)[source]

New velocity setpoint

poll_for(seconds)[source]

Let it fly!

reset()[source]

Reset “ground” state

update()[source]

Poll at 100-200ms rate

Download Source