8 import sys, os, subprocess, time
13 conf_path =
"/etc/ubiquity/robot.yaml" 17 'raspicam' : {
'position' :
'forward'},
19 'motor_controller' : {
20 'board_version' :
None,
21 'serial_port':
"/dev/ttyAMA0",
23 'pid_proportional': 5000,
25 'pid_derivative': -110,
26 'pid_denominator': 1000,
27 'pid_moving_buffer_size': 70,
30 'force_time_sync' :
'True',
38 with open(conf_path)
as conf_file:
40 conf = yaml.safe_load(conf_file)
41 except Exception
as e:
42 print(
'Error reading yaml file, using default configuration')
47 print(
'WARN /etc/ubiquity/robot.yaml is empty, using default configuration')
50 for key, value
in default_conf.items():
56 print(
"WARN /etc/ubiquity/robot.yaml doesn't exist, using default configuration")
58 except yaml.parser.ParserError:
59 print(
"WARN failed to parse /etc/ubiquity/robot.yaml, using default configuration")
62 if __name__ ==
"__main__":
66 if conf[
'sonars'] ==
'pi_sonar_v1':
67 conf[
'sonars'] =
'true' 69 conf[
'sonars'] =
'false' 72 oled_display_installed =
'false' 73 if conf[
'oled_display'][
'controller'] ==
'SH1106':
74 oled_display_installed =
'true' 78 if conf[
'force_time_sync']:
81 timeout = time.time() + 40
83 if (time.time() > timeout):
86 output = subprocess.check_output([
"pifi",
"status"])
87 if "not activated" in output:
89 if "acting as an Access Point" in output:
90 print "we are in AP mode, don't wait for time" 92 if "is connected to" in output:
93 print "we are connected to a network, wait for time" 94 subprocess.call([
"chronyc",
"waitsync",
"20"])
96 except (RuntimeError, OSError, subprocess.CalledProcessError)
as e:
97 print "Error calling pifi" 98 subprocess.call([
"chronyc",
"waitsync",
"6"])
100 print "Skipping time sync steps due to configuration" 104 if conf[
'motor_controller'][
'board_version'] ==
None:
108 i2cbus = smbus.SMBus(1)
109 i2cbus.write_byte(0x20, 0xFF)
111 inputPortBits = i2cbus.read_byte(0x20)
112 boardRev = 49 + (15 - (inputPortBits & 0x0F))
113 print "Got board rev: %d" % boardRev
115 print "Error reading motor controller board version from i2c" 117 extrinsics_file =
'~/.ros/camera_info/extrinsics_%s.yaml' % conf[
'raspicam'][
'position']
118 extrinsics_file = os.path.expanduser(extrinsics_file)
119 if not os.path.isfile(extrinsics_file):
120 extrinsics_file =
'-' 122 controller = conf[
'motor_controller']
125 sys.argv = [
"roslaunch",
"magni_bringup",
"core.launch",
126 "raspicam_mount:=%s" % conf[
'raspicam'][
'position'],
127 "sonars_installed:=%s" % conf[
'sonars'],
128 "controller_board_version:=%d" % boardRev,
129 "camera_extrinsics_file:=%s" % extrinsics_file,
130 "controller_serial_port:=%s" % controller[
'serial_port'],
131 "controller_serial_baud:=%s" % controller[
'serial_baud'],
132 "controller_pid_proportional:=%s" % controller[
'pid_proportional'],
133 "controller_pid_integral:=%s" % controller[
'pid_integral'],
134 "controller_pid_derivative:=%s" % controller[
'pid_derivative'],
135 "controller_pid_denominator:=%s" % controller[
'pid_denominator'],
136 "controller_pid_moving_buffer_size:=%s" % controller[
'pid_moving_buffer_size'],
137 "controller_pid_velocity:=%s" % controller[
'pid_velocity'],
138 "oled_display:=%s" % oled_display_installed
141 roslaunch.main(sys.argv)