|
47 | 47 | TYPE_VELOCITY_WORLD = 8
|
48 | 48 | TYPE_ZDISTANCE = 9
|
49 | 49 | TYPE_HOVER = 10
|
| 50 | +TYPE_MANUAL = 11 |
50 | 51 |
|
51 | 52 | TYPE_META_COMMAND_NOTIFY_SETPOINT_STOP = 0
|
52 | 53 |
|
@@ -232,3 +233,26 @@ def send_position_setpoint(self, x, y, z, yaw):
|
232 | 233 | pk.data = struct.pack('<Bffff', TYPE_POSITION,
|
233 | 234 | x, y, z, yaw)
|
234 | 235 | self._cf.send_packet(pk)
|
| 236 | + |
| 237 | + def send_setpoint_manual(self, roll, pitch, yawrate, thrust_percentage, rate): |
| 238 | + """ |
| 239 | + Send a new control setpoint for roll/pitch/yaw_Rate/thrust_percentage to the copter with |
| 240 | + the option to send roll rate and pitch rate. If `rate == False`, roll/pitch angle is sent. |
| 241 | + If `rate == True`, roll/pitch rate is sent. |
| 242 | +
|
| 243 | + roll, pitch are in degrees or in degrees/s |
| 244 | + yawrate is in degrees/s |
| 245 | + thrust_percentage is a float value ranging from 0 (next to no power) to 100 (full power) |
| 246 | + rate is a bool |
| 247 | + """ |
| 248 | + if thrust_percentage > 100 or thrust_percentage < 0: |
| 249 | + raise ValueError('Thrust percentage must be between 0 and 100') |
| 250 | + |
| 251 | + thrust = 10001 + 0.01 * thrust_percentage * (60000 - 10001) |
| 252 | + thrust_16 = struct.unpack('<H', struct.pack('<H', int(thrust)))[0] |
| 253 | + |
| 254 | + pk = CRTPPacket() |
| 255 | + pk.port = CRTPPort.COMMANDER_GENERIC |
| 256 | + pk.channel = SET_SETPOINT_CHANNEL |
| 257 | + pk.data = struct.pack('<BfffHB', TYPE_MANUAL, roll, -pitch, yawrate, thrust_16, rate) |
| 258 | + self._cf.send_packet(pk) |
0 commit comments