Skip to content

Commit 6a42731

Browse files
authored
Merge pull request #539 from bitcraze/Aris/Commander_Generic_Setpoints
Added send_setpoint_manual command
2 parents 1708d3f + aea9aa1 commit 6a42731

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cflib/crazyflie/commander.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
TYPE_VELOCITY_WORLD = 8
4848
TYPE_ZDISTANCE = 9
4949
TYPE_HOVER = 10
50+
TYPE_MANUAL = 11
5051

5152
TYPE_META_COMMAND_NOTIFY_SETPOINT_STOP = 0
5253

@@ -232,3 +233,26 @@ def send_position_setpoint(self, x, y, z, yaw):
232233
pk.data = struct.pack('<Bffff', TYPE_POSITION,
233234
x, y, z, yaw)
234235
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

Comments
 (0)