MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / MotionCommander

Class MotionCommander

cflib/positioning/motion_commander.py:53–412  ·  view source on GitHub ↗

The motion commander

Source from the content-addressed store, hash-verified

51
52
53class MotionCommander:
54 """The motion commander"""
55 VELOCITY = 0.2
56 RATE = 360.0 / 5
57
58 def __init__(self, crazyflie, default_height=0.3):
59 """
60 Construct an instance of a MotionCommander
61
62 :param crazyflie: a Crazyflie or SyncCrazyflie instance
63 :param default_height: the default height to fly at
64 """
65 if isinstance(crazyflie, SyncCrazyflie):
66 self._cf = crazyflie.cf
67 else:
68 self._cf = crazyflie
69
70 self.default_height = default_height
71
72 self._is_flying = False
73 self._thread = None
74
75 # Distance based primitives
76
77 def take_off(self, height=None, velocity=VELOCITY):
78 """
79 Takes off, that is starts the motors, goes straight up and hovers.
80 Do not call this function if you use the with keyword. Take off is
81 done automatically when the context is created.
82
83 :param height: the height (meters) to hover at. None uses the default
84 height set when constructed.
85 :param velocity: the velocity (meters/second) when taking off
86 :return:
87 """
88 if self._is_flying:
89 raise Exception('Already flying')
90
91 if not self._cf.is_connected():
92 raise Exception('Crazyflie is not connected')
93
94 self._is_flying = True
95 self._reset_position_estimator()
96
97 self._thread = _SetPointThread(self._cf)
98 self._thread.start()
99
100 if height is None:
101 height = self.default_height
102
103 self.up(height, velocity)
104
105 def land(self, velocity=VELOCITY):
106 """
107 Go straight down and turn off the motors.
108
109 Do not call this function if you use the with keyword. Landing is
110 done automatically when the context goes out of scope.

Callers 7

setUpMethod · 0.90
move_box_limitFunction · 0.90
move_linear_simpleFunction · 0.90
take_off_simpleFunction · 0.90

Calls

no outgoing calls

Tested by 2

setUpMethod · 0.72