This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabfile.py
210 lines (182 loc) · 5.73 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
from fabric.api import *
from fabric.context_managers import shell_env
def _bash_run(command_string):
"""
Creates a new local command to enforce /bin/bash as shell
"""
if len(env.hosts) > 0:
run(command_string, shell="/bin/bash")
else:
local(command_string, shell="/bin/bash")
def goldorak():
"""
Setup the environment to use it on Goldorak
"""
env.hosts += ['192.168.8.2']
env.user = 'ubuntu'
env.password = 'temppwd'
def build():
"""
Compiles the project
"""
with cd('~/catkin_ws/src/goldorak'):
_bash_run('./build.sh')
def rebuild():
"""
Makes a clean build of the project
"""
_bash_run('catkin clean -y')
build()
def launch():
"""
Launch robot's full ROS stack
"""
if len(env.hosts) > 0:
ip = env.hosts[-1]
else:
ip = '127.0.0.1'
with shell_env(ROS_IP=ip, ROS_MASTER_URI='http://{}:11311'.format(ip)):
_bash_run('source ~/catkin_ws/devel/setup.bash && \
roslaunch goldorak_bringup goldorak.launch')
@parallel
def strat():
"""
Launch robot's strategy node
"""
if len(env.hosts) > 0:
robot_ip = env.hosts[-1]
else:
robot_ip = '127.0.0.1'
with shell_env(ROS_IP=robot_ip, ROS_MASTER_URI='http://{}:11311'.format(robot_ip)):
_bash_run('source ~/catkin_ws/devel/setup.bash && \
roslaunch goldorak_bringup strategy.launch')
@parallel
def strat_view():
"""
Launch robot's strategy node
"""
if len(env.hosts) > 0:
robot_ip = env.hosts[-1]
local_ip = '192.168.8.1'
else:
robot_ip = '127.0.0.1'
local_ip = '127.0.0.1'
with shell_env(ROS_IP=local_ip, ROS_MASTER_URI='http://{}:11311'.format(robot_ip)):
local('source ~/catkin_ws/devel/setup.bash && \
rosrun smach_viewer smach_viewer.py', shell='/bin/bash')
def setpoint():
"""
Send setpoint
"""
if len(env.hosts) > 0:
robot_ip = env.hosts[-1]
local_ip = '192.168.8.1'
else:
robot_ip = '127.0.0.1'
local_ip = '127.0.0.1'
with shell_env(ROS_IP=local_ip, ROS_MASTER_URI='http://{}:11311'.format(robot_ip)):
local('source ~/catkin_ws/devel/setup.bash && \
python ~/catkin_ws/src/goldorak/setpoint.py', shell='/bin/bash')
def tune_pid():
"""
Launch robot's full ROS stack
"""
if len(env.hosts) > 0:
ip = env.hosts[-1]
else:
ip = '127.0.0.1'
with shell_env(ROS_IP=ip, ROS_MASTER_URI='http://{}:11311'.format(ip)):
_bash_run('source ~/catkin_ws/devel/setup.bash && \
roslaunch goldorak_bringup test_motor.launch')
def monitor():
"""
Monitor robot using Rviz
"""
if len(env.hosts) > 0:
robot_ip = env.hosts[-1]
local_ip = '192.168.8.1'
else:
robot_ip = '127.0.0.1'
local_ip = '127.0.0.1'
with shell_env(ROS_IP=local_ip, ROS_MASTER_URI='http://{}:11311'.format(robot_ip)):
local('source ~/catkin_ws/devel/setup.bash && \
roslaunch goldorak_bringup monitor.launch',
shell="/bin/bash")
def rqt():
"""
Opens RQT on shared ROS network
"""
if len(env.hosts) > 0:
robot_ip = env.hosts[-1]
local_ip = '192.168.8.1'
else:
robot_ip = '127.0.0.1'
local_ip = '127.0.0.1'
with shell_env(ROS_IP=local_ip, ROS_MASTER_URI='http://{}:11311'.format(robot_ip)):
local('source ~/catkin_ws/devel/setup.bash && \
rqt',
shell="/bin/bash")
def vcan(vcan_name):
"""
Creates a virtual CAN interface with given name
"""
_bash_run('sudo modprobe can && \
sudo modprobe can_raw && \
sudo modprobe can_bcm && \
sudo modprobe vcan && \
sudo ip link add dev {0} type vcan && \
sudo ip link set up {0} && \
sudo ifconfig {0} up'.format(vcan_name))
def share_internet():
"""
Share internet with robot through Ethernet
"""
local('sudo iptables -A POSTROUTING -t nat -j MASQUERADE')
local('sudo echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null')
run('sudo /sbin/route add default gw 192.168.8.1')
run('sudo -s && echo "nameserver 8.8.8.8" >> /etc/resolv.conf && exit')
run('sudo ntpdate -b -s -u pool.ntp.org')
def beacon():
"""
Builds the beacon firmware and flashes it
"""
with lcd('proximity-beacon-firmware'):
local('pwd')
local('make dsdlc')
local('packager/packager.py')
local('make')
put('build/motor-control-firmware.bin', '/tmp/beacon.bin')
# wait for user input before flashing
flash_command = "read &&"
flash_command += " bootloader_flash"
# Base adress
flash_command += " -a 0x08003800"
flash_command += " -i can1"
flash_command += " --device-class proximity-beacon"
flash_command += " -b /tmp/beacon.bin"
flash_command += " --run"
flash_command += " 54"
run(flash_command)
run('rm /tmp/beacon.bin')
def motor(ids):
"""
Builds the motor firmware and flashes it to specified ids
"""
with lcd('motor-control-firmware'):
local('pwd')
local('make dsdlc')
local('packager/packager.py')
local('make')
put('build/motor-control-firmware.bin', '/tmp/motor.bin')
# wait for user input before flashing
flash_command = "read &&"
flash_command += " bootloader_flash"
# Base adress
flash_command += " -a 0x08003800"
flash_command += " -i can1"
flash_command += " --device-class motor-board-v1"
flash_command += " -b /tmp/motor.bin"
flash_command += " --run"
flash_command += " {}".format(ids)
run(flash_command)
run('rm /tmp/motor.bin')