Skip to content

Commit 00107da

Browse files
committed
mission_item_protocol: factor and fix changealt/changeframe
the formation of the partial mission packet was incorrect - not appropriate for a range of waypoints!
1 parent d8a2ab5 commit 00107da

File tree

1 file changed

+25
-50
lines changed

1 file changed

+25
-50
lines changed

Diff for: MAVProxy/modules/lib/mission_item_protocol.py

+25-50
Original file line numberDiff line numberDiff line change
@@ -671,20 +671,15 @@ def cmd_movemulti(self, args, latlon=None):
671671
wpend_offset)
672672
print("Moved %s %u:%u to %f, %f rotation=%.1f" % (self.itemstype(), wpstart, wpend, lat, lon, rotation))
673673

674-
def cmd_changealt(self, args):
675-
'''handle wp change target alt of multiple waypoints'''
674+
def change_mission_item_range(self, args, desc, changer, newvalstr):
676675
if not self.check_have_list():
677676
return
678-
if len(args) < 2:
679-
print("usage: %s changealt WPNUM NEWALT <NUMWP>" % self.command_name())
680-
return
681677
idx = int(args[0])
682678
if not self.good_item_num_to_manipulate(idx):
683679
print("Invalid %s number %u" % (self.itemtype(), idx))
684680
return
685-
newalt = float(args[1])
686-
if len(args) >= 3:
687-
count = int(args[2])
681+
if len(args) >= 2:
682+
count = int(args[1])
688683
else:
689684
count = 1
690685
if not self.good_item_num_to_manipulate(idx+count-1):
@@ -698,65 +693,45 @@ def cmd_changealt(self, args):
698693
continue
699694
if not self.wploader.is_location_command(wp.command):
700695
continue
701-
wp.z = newalt
696+
changer(wp)
702697
wp.target_system = self.target_system
703698
wp.target_component = self.target_component
704699
self.wploader.set(wp, offset)
705700

706701
self.wploader.last_change = time.time()
702+
self.upload_start = time.time()
707703
self.loading_waypoints = True
708704
self.loading_waypoint_lasttime = time.time()
709705
self.master.mav.mission_write_partial_list_send(
710706
self.target_system,
711707
self.target_component,
712-
offset,
713-
offset,
708+
self.item_num_to_offset(idx),
709+
self.item_num_to_offset(idx+count),
714710
mission_type=self.mav_mission_type())
715-
print("Changed alt for WPs %u:%u to %f" % (idx, idx+(count-1), newalt))
711+
print("Changed %s for WPs %u:%u to %s" % (desc, idx, idx+(count-1), newvalstr))
712+
713+
def cmd_changealt(self, args):
714+
'''handle wp change target alt of multiple waypoints'''
715+
if len(args) < 2:
716+
print("usage: %s changealt WPNUM NEWALT <NUMWP>" % self.command_name())
717+
return
718+
value = float(args[1])
719+
del args[1]
720+
def changer(wp):
721+
wp.z = value
722+
self.change_mission_item_range(args, "alt", changer, str(value))
716723

717724
def cmd_changeframe(self, args):
718725
'''handle wp change frame of multiple waypoints'''
719-
if not self.check_have_list():
720-
return
721726
if len(args) < 2:
722-
print("usage: %s changeframe WPNUM NEWFRAME <NUMWP>" % self.command_name())
723-
return
724-
idx = int(args[0])
725-
if not self.good_item_num_to_manipulate(idx):
726-
print("Invalid %s number %u" % (self.itemtype(), idx))
727-
return
728-
newframe = int(args[1])
729-
if len(args) >= 3:
730-
count = int(args[2])
731-
else:
732-
count = 1
733-
if not self.good_item_num_to_manipulate(idx+count-1):
734-
print("Invalid %s number %u" % (self.itemtype(), idx+count-1))
727+
print("usage: %s changealt WPNUM NEWALT <NUMWP>" % self.command_name())
735728
return
729+
value = int(args[1])
730+
del args[1]
731+
def changer(wp):
732+
wp.frame = value
733+
self.change_mission_item_range(args, "frame", changer, str(value))
736734

737-
for wpnum in range(idx, idx+count):
738-
offset = self.item_num_to_offset(wpnum)
739-
wp = self.wploader.wp(offset)
740-
if wp is None:
741-
continue
742-
if not self.wploader.is_location_command(wp.command):
743-
continue
744-
wp.frame = newframe
745-
wp.target_system = self.target_system
746-
wp.target_component = self.target_component
747-
self.wploader.set(wp, offset)
748-
749-
self.wploader.last_change = time.time()
750-
self.loading_waypoints = True
751-
self.loading_waypoint_lasttime = time.time()
752-
self.master.mav.mission_write_partial_list_send(
753-
self.target_system,
754-
self.target_component,
755-
offset,
756-
offset,
757-
mission_type=self.mav_mission_type())
758-
print("Changed frame for WPs %u:%u to %u" % (idx, idx+(count-1), newframe))
759-
760735
def fix_jumps(self, idx, delta):
761736
# nothing by default as only waypoints need worry
762737
pass

0 commit comments

Comments
 (0)