CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/balancebot.py
Views: 1798
1
'''
2
Drive a BalanceBot in SITL
3
4
AP_FLAKE8_CLEAN
5
6
'''
7
8
from __future__ import print_function
9
10
import os
11
12
from rover import AutoTestRover
13
14
import vehicle_test_suite
15
from vehicle_test_suite import NotAchievedException
16
17
# get location of scripts
18
testdir = os.path.dirname(os.path.realpath(__file__))
19
20
21
class AutoTestBalanceBot(AutoTestRover):
22
23
def log_name(self):
24
return "BalanceBot"
25
26
def vehicleinfo_key(self):
27
return "Rover"
28
29
def init(self):
30
if self.frame is None:
31
self.frame = 'balancebot'
32
super(AutoTestBalanceBot, self).init()
33
34
def DO_SET_MODE(self):
35
'''Set mode via MAV_COMMAND_DO_SET_MODE'''
36
self.do_set_mode_via_command_long("HOLD")
37
self.do_set_mode_via_command_long("MANUAL")
38
39
def rc_defaults(self):
40
ret = super(AutoTestBalanceBot, self).rc_defaults()
41
ret[3] = 1500
42
return ret
43
44
def is_balancebot(self):
45
return True
46
47
def drive_rtl_mission_max_distance_from_home(self):
48
'''maximum distance allowed from home at end'''
49
'''balancebot tends to wander backwards, away from the target'''
50
return 8
51
52
def DriveRTL(self):
53
'''Drive an RTL Mission'''
54
# if we Hold then the balancebot continues to wander
55
# indefinitely at ~1m/s, hence we set to Acro
56
self.set_parameter("MIS_DONE_BEHAVE", 2)
57
super(AutoTestBalanceBot, self).DriveRTL()
58
59
def TestWheelEncoder(self):
60
'''make sure wheel encoders are generally working'''
61
ex = None
62
try:
63
self.set_parameter("WENC_TYPE", 10)
64
self.set_parameter("AHRS_EKF_TYPE", 10)
65
self.reboot_sitl()
66
self.set_parameter("WENC2_TYPE", 10)
67
self.set_parameter("WENC_POS_Y", 0.075)
68
self.set_parameter("WENC2_POS_Y", -0.075)
69
self.reboot_sitl()
70
self.change_mode("HOLD")
71
self.wait_ready_to_arm()
72
self.change_mode("ACRO")
73
self.arm_vehicle()
74
self.set_rc(3, 1600)
75
76
m = self.assert_receive_message('WHEEL_DISTANCE', timeout=5)
77
78
tstart = self.get_sim_time()
79
while True:
80
if self.get_sim_time_cached() - tstart > 10:
81
break
82
dist_home = self.distance_to_home(use_cached_home=True)
83
m = self.mav.messages.get("WHEEL_DISTANCE")
84
delta = abs(m.distance[0] - dist_home)
85
self.progress("dist-home=%f wheel-distance=%f delta=%f" %
86
(dist_home, m.distance[0], delta))
87
if delta > 5:
88
raise NotAchievedException("wheel distance incorrect")
89
self.disarm_vehicle()
90
except Exception as e:
91
self.progress("Caught exception: %s" %
92
self.get_exception_stacktrace(e))
93
self.disarm_vehicle()
94
ex = e
95
self.reboot_sitl()
96
if ex is not None:
97
raise ex
98
99
def DriveMission(self):
100
'''Drive Mission rover1.txt'''
101
self.drive_mission("balancebot1.txt", strict=False)
102
103
def tests(self):
104
'''return list of all tests'''
105
106
'''note that while AutoTestBalanceBot inherits from Rover we don't
107
inherit Rover's tests!'''
108
ret = vehicle_test_suite.TestSuite.tests(self)
109
110
ret.extend([
111
self.DriveRTL,
112
self.DriveMission,
113
self.TestWheelEncoder,
114
self.MAV_CMD_DO_SEND_BANNER,
115
self.DO_SET_MODE,
116
self.ServoRelayEvents,
117
])
118
return ret
119
120
def default_mode(self):
121
return 'MANUAL'
122
123