The motion commander
| 51 | |
| 52 | |
| 53 | class 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. |
no outgoing calls