Skip to content

Added send_setpoint_manual command #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cflib/crazyflie/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
TYPE_VELOCITY_WORLD = 8
TYPE_ZDISTANCE = 9
TYPE_HOVER = 10
TYPE_MANUAL = 11

TYPE_META_COMMAND_NOTIFY_SETPOINT_STOP = 0

Expand Down Expand Up @@ -232,3 +233,26 @@ def send_position_setpoint(self, x, y, z, yaw):
pk.data = struct.pack('<Bffff', TYPE_POSITION,
x, y, z, yaw)
self._cf.send_packet(pk)

def send_setpoint_manual(self, roll, pitch, yawrate, thrust_percentage, rate):
"""
Send a new control setpoint for roll/pitch/yaw_Rate/thrust_percentage to the copter.
with an option to send roll rate and pitch rate. If `rate == False`, roll/pitch angle is sent.
If `rate == True`, roll/pitch rate is sent.

roll, pitch are in degrees or in degrees/s
yawrate is in degrees/s
thrust_percentage is a float value ranging from 0 (next to no power) to 100 (full power)
rate is a bool
"""
if thrust_percentage > 100 or thrust_percentage < 0:
raise ValueError('Thrust percentage must be between 0 and 100')

thrust = 1001 + 0.01 * thrust_percentage * (60000 - 1001)
thrust_16 = struct.unpack('<H', struct.pack('<H', int(thrust)))[0]

pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC
pk.channel = SET_SETPOINT_CHANNEL
pk.data = struct.pack('<BfffHB', TYPE_MANUAL, roll, -pitch, yawrate, thrust_16, rate)
self._cf.send_packet(pk)
Loading