Skip to content

Commit 61e3d73

Browse files
committed
autotest: add test for MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET
1 parent 7230fe2 commit 61e3d73

3 files changed

Lines changed: 191 additions & 51 deletions

File tree

Tools/autotest/arducopter.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4867,11 +4867,33 @@ def setup_servo_mount(self, roll_servo=5, pitch_servo=6, yaw_servo=7):
48674867
"SERVO%u_FUNCTION" % yaw_servo: 6, # yaw
48684868
})
48694869

4870+
# FIXME: change this to use wait_and_maintain
4871+
def wait_mount_roll_pitch_yaw_deg(self, r=None, p=None, y=None, timeout=20):
4872+
tstart = self.get_sim_time()
4873+
while True:
4874+
if self.get_sim_time_cached() - tstart > timeout:
4875+
raise NotAchievedException("Did not get rpy")
4876+
got_r, got_p, got_y = self.get_mount_roll_pitch_yaw_deg()
4877+
self.progress("want=(%s, %s, %s)" % (r, p , y))
4878+
self.progress("got=(%s, %s, %s)" % (got_r, got_p , got_y))
4879+
passed = True
4880+
for (want, got) in [(r, got_r), (p, got_p), (y, got_y)]:
4881+
if want is None:
4882+
continue
4883+
if abs(want - got) > 5:
4884+
passed = False
4885+
break
4886+
if passed:
4887+
self.progress("achieved mount rpy")
4888+
break
4889+
48704890
def get_mount_roll_pitch_yaw_deg(self):
4871-
'''return mount (aka gimbal) roll, pitch and yaw angles in degrees'''
4891+
'''return mount (aka gimbal) roll, pitch and yaw angles in degrees - in body frame'''
48724892
# wait for gimbal attitude message
48734893
m = self.assert_receive_message('GIMBAL_DEVICE_ATTITUDE_STATUS', timeout=5)
4894+
return self.eulers_in_degrees_from_GIMBAL_DEVICE_ATTITUDE_STATUS(m)
48744895

4896+
def eulers_in_degrees_from_GIMBAL_DEVICE_ATTITUDE_STATUS(self, m):
48754897
# convert quaternion to euler angles and return
48764898
q = quaternion.Quaternion(m.q)
48774899
euler = q.euler
@@ -4886,8 +4908,65 @@ def set_mount_mode(self, mount_mode):
48864908
p3=0, # stabilize pitch (unsupported)
48874909
)
48884910

4911+
def MountWPNextOffsetMission(self, target_system=1, target_component=1):
4912+
'''check the MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET mission item'''
4913+
# setup mount parameters
4914+
self.setup_servo_mount()
4915+
self.reboot_sitl() # to handle MNT_TYPE changing
4916+
4917+
alt = 50
4918+
4919+
loc = self.mav.location()
4920+
4921+
items = [
4922+
self.mission_item_home(),
4923+
self.mission_item_copter_takeoff(alt=50),
4924+
]
4925+
4926+
# third waypoint
4927+
loc = self.offset_location_ne(loc, 100, 0)
4928+
items.append(self.mission_item_do_cmd_roi_set_wpnext_offset(p=0))
4929+
items.append(self.mission_item_waypoint(loc.lat, loc.lng, alt))
4930+
4931+
# third waypoint
4932+
loc = self.offset_location_ne(loc, 100, 0)
4933+
items.append(self.mission_item_do_cmd_roi_set_wpnext_offset(p=-45))
4934+
items.append(self.mission_item_waypoint(loc.lat, loc.lng, alt))
4935+
4936+
# fourth waypoint (offset from second)
4937+
loc = self.offset_location_ne(loc, 100, 0)
4938+
items.append(self.mission_item_do_cmd_roi_set_wpnext_offset(y=45))
4939+
items.append(self.mission_item_waypoint(loc.lat, loc.lng, alt))
4940+
4941+
# now RTL
4942+
items.append(self.mission_item_rtl())
4943+
4944+
self.renumber_mission_items(items)
4945+
self.check_mission_upload_download(items)
4946+
4947+
self.set_parameter('AUTO_OPTIONS', 3)
4948+
self.wait_ready_to_arm()
4949+
self.arm_vehicle()
4950+
self.change_mode('AUTO')
4951+
4952+
self.wait_current_waypoint(3)
4953+
# the 30 here is because the vehicle is pitching down and the
4954+
# gimbal is compensating
4955+
self.wait_mount_roll_pitch_yaw_deg(r=0, p=30, y=0)
4956+
4957+
self.wait_current_waypoint(5)
4958+
# the -15 here is because the vehicle is pitching down and the
4959+
# gimbal is compensating, and is being asked to pitch down 45 degrees
4960+
self.wait_mount_roll_pitch_yaw_deg(r=0, p=-15, y=0)
4961+
4962+
self.wait_current_waypoint(7)
4963+
self.wait_mount_roll_pitch_yaw_deg(y=45)
4964+
4965+
self.wait_disarmed()
4966+
48894967
def Mount(self):
48904968
'''Test Camera/Antenna Mount'''
4969+
48914970
ex = None
48924971
self.context_push()
48934972
old_srcSystem = self.mav.mav.srcSystem
@@ -5234,6 +5313,9 @@ def Mount(self):
52345313
self.set_mount_mode(mavutil.mavlink.MAV_MOUNT_MODE_NEUTRAL)
52355314
self.test_mount_pitch(0, 0.1, mavutil.mavlink.MAV_MOUNT_MODE_NEUTRAL)
52365315

5316+
self.start_subtest("Testing MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET")
5317+
self.test_mount_mav_cmd_do_set_roi_wpnext_offset_mission()
5318+
52375319
except Exception as e:
52385320
self.print_exception_caught(e)
52395321
ex = e
@@ -9624,6 +9706,7 @@ def tests1e(self):
96249706
self.RTLSpeed,
96259707
self.Mount,
96269708
self.MountYawVehicleForMountROI,
9709+
self.MountWPNextOffsetMission,
96279710
self.Button,
96289711
self.ShipTakeoff,
96299712
self.RangeFinder,

Tools/autotest/common.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,107 @@ def create_simple_relhome_mission(self, items_in, target_system=1, target_compon
38593859

38603860
return ret
38613861

3862+
def renumber_mission_items(self, items):
3863+
'''make item's seq sequential starting from zero'''
3864+
count = 0
3865+
for item in items:
3866+
item.seq = count
3867+
count += 1
3868+
3869+
def mission_item_copter_takeoff(self, alt=30, target_system=1, target_component=1):
3870+
'''returns a mission_item_int which can be used as takeoff in a mission'''
3871+
return self.mav.mav.mission_item_int_encode(
3872+
target_system,
3873+
target_component,
3874+
1, # seq
3875+
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
3876+
mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
3877+
0, # current
3878+
0, # autocontinue
3879+
0, # p1
3880+
0, # p2
3881+
0, # p3
3882+
0, # p4
3883+
int(1.0000 * 1e7), # latitude
3884+
int(1.0000 * 1e7), # longitude
3885+
alt, # altitude
3886+
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
3887+
3888+
def mission_item_rtl(self, target_system=1, target_component=1):
3889+
'''returns a mission_item_int which can be used as RTL in a mission'''
3890+
return self.mav.mav.mission_item_int_encode(
3891+
target_system,
3892+
target_component,
3893+
1, # seq
3894+
mavutil.mavlink.MAV_FRAME_GLOBAL,
3895+
mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH,
3896+
0, # current
3897+
0, # autocontinue
3898+
0, # p1
3899+
0, # p2
3900+
0, # p3
3901+
0, # p4
3902+
0, # latitude
3903+
0, # longitude
3904+
0.0000, # altitude
3905+
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
3906+
3907+
def mission_item_do_cmd_roi_set_wpnext_offset(self, r=0, p=0, y=0, target_system=1, target_component=1):
3908+
return self.mav.mav.mission_item_encode(
3909+
target_system,
3910+
target_component,
3911+
0, # seq
3912+
mavutil.mavlink.MAV_FRAME_GLOBAL,
3913+
mavutil.mavlink.MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET,
3914+
0, # current
3915+
0, # autocontinue
3916+
0, # param1
3917+
0, # param2
3918+
0, # param3
3919+
0, # param4
3920+
r, # param5
3921+
p, # param6
3922+
y # param7
3923+
)
3924+
3925+
def mission_item_waypoint(self, lat, lng, alt, target_system=1, target_component=1):
3926+
'''returns a mission_item_int which can be used as waypoint in a mission'''
3927+
return self.mav.mav.mission_item_int_encode(
3928+
target_system,
3929+
target_component,
3930+
0, # seq
3931+
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
3932+
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
3933+
0, # current
3934+
0, # autocontinue
3935+
0, # p1
3936+
0, # p2
3937+
0, # p3
3938+
0, # p4
3939+
int(lat*1e7), # latitude
3940+
int(lng*1e7), # longitude
3941+
alt, # altitude
3942+
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
3943+
3944+
def mission_item_home(self, target_system=1, target_component=1):
3945+
'''returns a mission_item_int which can be used as home in a mission'''
3946+
return self.mav.mav.mission_item_int_encode(
3947+
target_system,
3948+
target_component,
3949+
0, # seq
3950+
mavutil.mavlink.MAV_FRAME_GLOBAL_INT,
3951+
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
3952+
0, # current
3953+
0, # autocontinue
3954+
3, # p1
3955+
0, # p2
3956+
0, # p3
3957+
0, # p4
3958+
int(1.0000 * 1e7), # latitude
3959+
int(2.0000 * 1e7), # longitude
3960+
31.0000, # altitude
3961+
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
3962+
38623963
def upload_simple_relhome_mission(self, items, target_system=1, target_component=1):
38633964
mission = self.create_simple_relhome_mission(
38643965
items,

Tools/autotest/helicopter.py

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -429,44 +429,6 @@ def ManAutoRotation(self, timeout=600):
429429
self.wait_servo_channel_value(8, 1000, timeout=3)
430430
self.wait_disarmed()
431431

432-
def mission_item_home(self, target_system, target_component):
433-
'''returns a mission_item_int which can be used as home in a mission'''
434-
return self.mav.mav.mission_item_int_encode(
435-
target_system,
436-
target_component,
437-
0, # seq
438-
mavutil.mavlink.MAV_FRAME_GLOBAL_INT,
439-
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
440-
0, # current
441-
0, # autocontinue
442-
3, # p1
443-
0, # p2
444-
0, # p3
445-
0, # p4
446-
int(1.0000 * 1e7), # latitude
447-
int(2.0000 * 1e7), # longitude
448-
31.0000, # altitude
449-
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
450-
451-
def mission_item_takeoff(self, target_system, target_component):
452-
'''returns a mission_item_int which can be used as takeoff in a mission'''
453-
return self.mav.mav.mission_item_int_encode(
454-
target_system,
455-
target_component,
456-
1, # seq
457-
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
458-
mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
459-
0, # current
460-
0, # autocontinue
461-
0, # p1
462-
0, # p2
463-
0, # p3
464-
0, # p4
465-
int(1.0000 * 1e7), # latitude
466-
int(1.0000 * 1e7), # longitude
467-
31.0000, # altitude
468-
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
469-
470432
def mission_item_rtl(self, target_system, target_component):
471433
'''returns a mission_item_int which can be used as takeoff in a mission'''
472434
return self.mav.mav.mission_item_int_encode(
@@ -538,7 +500,7 @@ def scurve_nasty_mission(self, target_system=1, target_component=1):
538500
# slot 0 is home
539501
self.mission_item_home(target_system=target_system, target_component=target_component),
540502
# slot 1 is takeoff
541-
self.mission_item_takeoff(target_system=target_system, target_component=target_component),
503+
self.mission_item_copter_takeoff(target_system=target_system, target_component=target_component),
542504
# now three spline waypoints right on top of one another:
543505
copy.copy(wp2_by_three),
544506
copy.copy(wp2_by_three),
@@ -549,11 +511,9 @@ def scurve_nasty_mission(self, target_system=1, target_component=1):
549511
copy.copy(wp5_by_three),
550512
self.mission_item_rtl(target_system=target_system, target_component=target_component),
551513
])
552-
# renumber the items:
553-
count = 0
554-
for item in ret:
555-
item.seq = count
556-
count += 1
514+
515+
self.renumber_mission_items(ret)
516+
557517
return ret
558518

559519
def scurve_nasty_up_mission(self, target_system=1, target_component=1):
@@ -616,7 +576,7 @@ def scurve_nasty_up_mission(self, target_system=1, target_component=1):
616576
# slot 0 is home
617577
self.mission_item_home(target_system=target_system, target_component=target_component),
618578
# slot 1 is takeoff
619-
self.mission_item_takeoff(target_system=target_system, target_component=target_component),
579+
self.mission_item_copter_takeoff(target_system=target_system, target_component=target_component),
620580
wp2,
621581
wp3,
622582
wp4,
@@ -626,11 +586,7 @@ def scurve_nasty_up_mission(self, target_system=1, target_component=1):
626586
wp7,
627587
self.mission_item_rtl(target_system=target_system, target_component=target_component),
628588
])
629-
# renumber the items:
630-
count = 0
631-
for item in ret:
632-
item.seq = count
633-
count += 1
589+
self.renumber_mission_items(ret)
634590
return ret
635591

636592
def fly_mission_points(self, points):

0 commit comments

Comments
 (0)