Skip to content

Commit 43d48d1

Browse files
authored
Merge pull request #2 from turtlebot/roni-kreinin/domain_id
v0.1.3
2 parents d7c2278 + 31e05b1 commit 43d48d1

File tree

4 files changed

+144
-29
lines changed

4 files changed

+144
-29
lines changed

conf/webserver.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Create 3 Webserver forwarding service
3+
After=network.target
4+
StartLimitIntervalSec=0
5+
[Service]
6+
Type=simple
7+
Restart=always
8+
RestartSec=1
9+
ExecStart=/usr/bin/socat TCP-LISTEN:8080,fork,reuseaddr tcp:192.168.186.2:80
10+
11+
[Install]
12+
WantedBy=multi-user.target

scripts/install.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,55 @@
1515
#
1616
# @author Roni Kreinin ([email protected])
1717

18+
import argparse
19+
1820
import sys
1921

2022
import robot_upstart
2123

2224

23-
def help():
24-
print('TurtleBot 4 robot_upstart install script.')
25-
print('Usage: install.py [model] <ROS_DOMAIN_ID>')
26-
print('models: lite, standard')
27-
print('ROS_DOMAIN_ID: optional, defaults to 0')
25+
parser = argparse.ArgumentParser()
2826

27+
parser.add_argument('model', type=str)
28+
parser.add_argument('--domain', type=int, default=0)
29+
parser.add_argument('--rmw', type=str, default='rmw_cyclonedds_cpp')
2930

30-
argc = len(sys.argv)
31+
args = parser.parse_args()
3132

32-
if argc == 1:
33-
print('Model required.')
34-
help()
33+
if args.model != 'lite' and args.model != 'standard':
34+
print('Invalid model: {0}'.format(args.model))
35+
parser.print_help()
3536
sys.exit(1)
3637

37-
model = sys.argv[1]
38-
if model != 'lite' and model != 'standard':
39-
print('Invalid model {0}'.format(model))
40-
help()
41-
sys.exit(2)
38+
model = args.model
4239

4340
domain_id = 0
44-
if argc == 3:
45-
try:
46-
domain_id = int(sys.argv[2])
47-
except ValueError:
48-
print('Invalid ROS_DOMAIN_ID {0}'.format(sys.argv[2]))
49-
help()
50-
sys.exit(3)
41+
if (args.domain >= 0 and args.domain <= 101) or \
42+
(args.domain >= 215 and args.domain <= 232):
43+
domain_id = args.domain
44+
else:
45+
print('Invalid ROS_DOMAIN_ID: {0}'.format(args.domain))
46+
parser.print_help()
47+
sys.exit(2)
48+
49+
rmw = 'rmw_cyclonedds_cpp'
50+
if args.rmw == 'rmw_fastrtps_cpp' or args.rmw == 'rmw_cyclonedds_cpp':
51+
rmw = args.rmw
52+
else:
53+
print('Invalid RMW {0}'.format(args.rmw))
54+
parser.print_help()
55+
sys.exit(3)
56+
57+
print('Installing TurtleBot 4 {0}. ROS_DOMAIN_ID={1}, RMW_IMPLEMENTATION={2}'.format(model, domain_id, rmw))
5158

52-
print('Installing TurtleBot 4 {0}. ROS_DOMAIN_ID={1}'.format(model, domain_id))
59+
if rmw == 'rmw_cyclonedds_cpp':
60+
rmw_config = '/etc/cyclonedds_rpi.xml'
61+
else:
62+
rmw_config = None
5363

5464
turtlebot4_job = robot_upstart.Job(name='turtlebot4',
55-
rmw='rmw_cyclonedds_cpp',
56-
rmw_config='/etc/cyclonedds_rpi.xml',
65+
rmw=rmw,
66+
rmw_config=rmw_config,
5767
workspace_setup='/opt/ros/galactic/setup.bash',
5868
ros_domain_id=domain_id)
5969

scripts/ros_config.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# Flags:
4+
# -h Help
5+
6+
Help()
7+
{
8+
echo "TurtleBot 4 Configure Create 3"
9+
echo
10+
echo "usage: sudo bash create_config.sh [-h]"
11+
echo "options:"
12+
echo " -h Print this help statement"
13+
echo
14+
}
15+
16+
while getopts "h" flag
17+
do
18+
case "${flag}" in
19+
h)
20+
Help
21+
exit;;
22+
\?)
23+
echo "Error: Invalid flag"
24+
exit;;
25+
esac
26+
done
27+
28+
read -p "ROS_DOMAIN_ID (default 0): " ros_domain_id
29+
ros_domain_id=${ros_domain_id:-0}
30+
#read -p "ROS namespace (default empty): " namespace
31+
read -p "RMW Implementation [rmw_cyclonedds_cpp,rmw_fastrtps_cpp] (default rmw_cyclonedds_cpp): " rmw
32+
rmw=${rmw:-rmw_cyclonedds_cpp}
33+
34+
echo "ROS_DOMAIN_ID: $ros_domain_id";
35+
#echo "Namespace: $namespace";
36+
echo "RMW_IMPLEMENTATION: $rmw";
37+
read -p "Press enter to apply these settings."
38+
39+
ttb4=$( cat /etc/turtlebot4 )
40+
41+
model="standard"
42+
43+
case $ttb4 in
44+
*"lite"*)
45+
model="lite";;
46+
esac
47+
48+
# Set Create 3 configuration
49+
curl -d "ros_domain_id=$ros_domain_id&ros_namespace=&rmw_implementation=$rmw" -X POST http://192.168.186.2/ros-config-save-main -o /dev/null
50+
51+
# Reboot Create 3
52+
curl -X POST http://192.168.186.2/api/reboot
53+
54+
# Stop running turtlebot4 service
55+
sudo systemctl stop turtlebot4.service
56+
57+
# Uninstall robot_upstart job
58+
uninstall.py
59+
60+
# Install robot_upstart job with new ROS_DOMAIN_ID
61+
install.py $model --domain $ros_domain_id --rmw $rmw
62+
63+
# Start job
64+
sudo systemctl daemon-reload && sudo systemctl start turtlebot4
65+
66+
# Add settings to .bashrc
67+
if grep -Fq "export RMW_IMPLEMENTATION=" ~/.bashrc
68+
then
69+
sudo sed -i "s/export RMW_IMPLEMENTATION=.*/export RMW_IMPLEMENTATION=$rmw/g" ~/.bashrc
70+
else
71+
echo "export RMW_IMPLEMENTATION=$rmw" | sudo tee -a ~/.bashrc
72+
fi
73+
74+
if grep -Fq "export ROS_DOMAIN_ID=" ~/.bashrc
75+
then
76+
sudo sed -i "s/export ROS_DOMAIN_ID=.*/export ROS_DOMAIN_ID=$ros_domain_id/g" ~/.bashrc
77+
else
78+
echo "export ROS_DOMAIN_ID=$ros_domain_id" | sudo tee -a ~/.bashrc
79+
fi
80+
81+
echo "Source ~/.bashrc to apply these changes to this terminal."

scripts/turtlebot4_setup.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ source /opt/ros/galactic/setup.bash
6868
sudo apt install -y \
6969
network-manager \
7070
daemontools \
71-
ros-galactic-robot-upstart \
7271
chrony \
72+
socat \
73+
ros-galactic-robot-upstart \
7374
ros-galactic-turtlebot4-robot \
74-
ros-galactic-irobot-create-control
75+
ros-galactic-irobot-create-control \
76+
ros-galactic-rmw-fastrtps-cpp
7577

7678
# Copy udev rules
7779
sudo cp $SETUP_DIR/udev/turtlebot4.rules /etc/udev/rules.d/
@@ -82,20 +84,29 @@ sudo cp $SETUP_DIR/conf/chrony.conf /etc/chrony/
8284
# Restart chrony
8385
sudo service chrony restart
8486

87+
# Copy webserver service
88+
sudo cp $SETUP_DIR/conf/webserver.service /etc/systemd/system/
89+
90+
# Enable webserver service to run from boot
91+
sudo systemctl enable webserver.service
92+
8593
# Enable usb0
8694
echo "dtoverlay=dwc2,dr_mode=peripheral" | sudo tee -a /boot/firmware/usercfg.txt
8795
sudo sed -i '${s/$/ modules-load=dwc2,g_ether/}' /boot/firmware/cmdline.txt
8896

8997
# Enable i2c-3
9098
echo "dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=4,i2c_gpio_scl=5" | sudo tee -a /boot/firmware/usercfg.txt
9199

100+
# Source galactic setup in bashrc
101+
echo "source /opt/ros/galactic/setup.bash" | sudo tee -a ~/.bashrc
102+
92103
# Configure cyclonedds
93104
sudo cp $SETUP_DIR/conf/cyclonedds_rpi.xml /etc/
94105
echo "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp" | sudo tee -a ~/.bashrc
95106
echo "export CYCLONEDDS_URI=/etc/cyclonedds_rpi.xml" | sudo tee -a ~/.bashrc
96107

97-
# Source galactic setup in bashrc
98-
echo "source /opt/ros/galactic/setup.bash" | sudo tee -a ~/.bashrc
108+
# Set ROS_DOMAIN_ID
109+
echo "export ROS_DOMAIN_ID=0" | sudo tee -a ~/.bashrc
99110

100111
# Robot upstart
101112
$SCRIPT_DIR/install.py $model
@@ -106,6 +117,7 @@ sudo systemctl daemon-reload
106117
sudo cp $SCRIPT_DIR/wifi.sh \
107118
$SCRIPT_DIR/create_update_0.4.0.sh \
108119
$SCRIPT_DIR/create_update.sh \
120+
$SCRIPT_DIR/ros_config.sh \
109121
$SCRIPT_DIR/swap_on.sh \
110122
$SCRIPT_DIR/swap_off.sh \
111123
$SCRIPT_DIR/bluetooth.sh \
@@ -114,7 +126,7 @@ sudo cp $SCRIPT_DIR/wifi.sh \
114126

115127
# Set image information
116128
sudo touch /etc/turtlebot4
117-
echo "TurtleBot 4 $model v0.1.2" | sudo tee /etc/turtlebot4
129+
echo "TurtleBot 4 $model v0.1.3" | sudo tee /etc/turtlebot4
118130

119131
echo "Installation complete, press enter to reboot in AP mode."
120132

0 commit comments

Comments
 (0)