Skip to content

Commit e735de5

Browse files
authored
Merge pull request #383 from bitcraze/add-notify-setpoint
Add notify setpoint
2 parents 7e8aeac + 3a4dff9 commit e735de5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

cflib/crazyflie/commander.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@
3333
__author__ = 'Bitcraze AB'
3434
__all__ = ['Commander']
3535

36+
SET_SETPOINT_CHANNEL = 0
37+
META_COMMAND_CHANNEL = 1
38+
3639
TYPE_STOP = 0
3740
TYPE_VELOCITY_WORLD = 1
3841
TYPE_ZDISTANCE = 2
3942
TYPE_HOVER = 5
4043
TYPE_POSITION = 7
4144

45+
TYPE_META_COMMAND_NOTIFY_SETPOINT_STOP = 0
46+
4247

4348
class Commander():
4449
"""
@@ -82,6 +87,18 @@ def send_setpoint(self, roll, pitch, yawrate, thrust):
8287
pk.data = struct.pack('<fffH', roll, -pitch, yawrate, thrust)
8388
self._cf.send_packet(pk)
8489

90+
def send_notify_setpoint_stop(self, remain_valid_milliseconds=0):
91+
"""
92+
Sends a packet so that the priority of the current setpoint to the lowest non-disabled value,
93+
so any new setpoint regardless of source will overwrite it.
94+
"""
95+
pk = CRTPPacket()
96+
pk.port = CRTPPort.COMMANDER_GENERIC
97+
pk.channel = META_COMMAND_CHANNEL
98+
pk.data = struct.pack('<BI', TYPE_META_COMMAND_NOTIFY_SETPOINT_STOP,
99+
remain_valid_milliseconds)
100+
self._cf.send_packet(pk)
101+
85102
def send_stop_setpoint(self):
86103
"""
87104
Send STOP setpoing, stopping the motors and (potentially) falling.
@@ -100,6 +117,7 @@ def send_velocity_world_setpoint(self, vx, vy, vz, yawrate):
100117
"""
101118
pk = CRTPPacket()
102119
pk.port = CRTPPort.COMMANDER_GENERIC
120+
pk.channel = SET_SETPOINT_CHANNEL
103121
pk.data = struct.pack('<Bffff', TYPE_VELOCITY_WORLD,
104122
vx, vy, vz, yawrate)
105123
self._cf.send_packet(pk)
@@ -116,6 +134,7 @@ def send_zdistance_setpoint(self, roll, pitch, yawrate, zdistance):
116134
"""
117135
pk = CRTPPacket()
118136
pk.port = CRTPPort.COMMANDER_GENERIC
137+
pk.channel = SET_SETPOINT_CHANNEL
119138
pk.data = struct.pack('<Bffff', TYPE_ZDISTANCE,
120139
roll, pitch, yawrate, zdistance)
121140
self._cf.send_packet(pk)
@@ -132,6 +151,7 @@ def send_hover_setpoint(self, vx, vy, yawrate, zdistance):
132151
"""
133152
pk = CRTPPacket()
134153
pk.port = CRTPPort.COMMANDER_GENERIC
154+
pk.channel = SET_SETPOINT_CHANNEL
135155
pk.data = struct.pack('<Bffff', TYPE_HOVER,
136156
vx, vy, yawrate, zdistance)
137157
self._cf.send_packet(pk)
@@ -146,6 +166,7 @@ def send_position_setpoint(self, x, y, z, yaw):
146166
"""
147167
pk = CRTPPacket()
148168
pk.port = CRTPPort.COMMANDER_GENERIC
169+
pk.channel = SET_SETPOINT_CHANNEL
149170
pk.data = struct.pack('<Bffff', TYPE_POSITION,
150171
x, y, z, yaw)
151172
self._cf.send_packet(pk)

0 commit comments

Comments
 (0)