@@ -671,20 +671,15 @@ def cmd_movemulti(self, args, latlon=None):
671
671
wpend_offset )
672
672
print ("Moved %s %u:%u to %f, %f rotation=%.1f" % (self .itemstype (), wpstart , wpend , lat , lon , rotation ))
673
673
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 ):
676
675
if not self .check_have_list ():
677
676
return
678
- if len (args ) < 2 :
679
- print ("usage: %s changealt WPNUM NEWALT <NUMWP>" % self .command_name ())
680
- return
681
677
idx = int (args [0 ])
682
678
if not self .good_item_num_to_manipulate (idx ):
683
679
print ("Invalid %s number %u" % (self .itemtype (), idx ))
684
680
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 ])
688
683
else :
689
684
count = 1
690
685
if not self .good_item_num_to_manipulate (idx + count - 1 ):
@@ -698,65 +693,45 @@ def cmd_changealt(self, args):
698
693
continue
699
694
if not self .wploader .is_location_command (wp .command ):
700
695
continue
701
- wp . z = newalt
696
+ changer ( wp )
702
697
wp .target_system = self .target_system
703
698
wp .target_component = self .target_component
704
699
self .wploader .set (wp , offset )
705
700
706
701
self .wploader .last_change = time .time ()
702
+ self .upload_start = time .time ()
707
703
self .loading_waypoints = True
708
704
self .loading_waypoint_lasttime = time .time ()
709
705
self .master .mav .mission_write_partial_list_send (
710
706
self .target_system ,
711
707
self .target_component ,
712
- offset ,
713
- offset ,
708
+ self . item_num_to_offset ( idx ) ,
709
+ self . item_num_to_offset ( idx + count ) ,
714
710
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 ))
716
723
717
724
def cmd_changeframe (self , args ):
718
725
'''handle wp change frame of multiple waypoints'''
719
- if not self .check_have_list ():
720
- return
721
726
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 ())
735
728
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 ))
736
734
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
-
760
735
def fix_jumps (self , idx , delta ):
761
736
# nothing by default as only waypoints need worry
762
737
pass
0 commit comments