-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from turtlebot/roni-kreinin/domain_id
v0.1.3
- Loading branch information
Showing
4 changed files
with
144 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Create 3 Webserver forwarding service | ||
After=network.target | ||
StartLimitIntervalSec=0 | ||
[Service] | ||
Type=simple | ||
Restart=always | ||
RestartSec=1 | ||
ExecStart=/usr/bin/socat TCP-LISTEN:8080,fork,reuseaddr tcp:192.168.186.2:80 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,45 +15,55 @@ | |
# | ||
# @author Roni Kreinin ([email protected]) | ||
|
||
import argparse | ||
|
||
import sys | ||
|
||
import robot_upstart | ||
|
||
|
||
def help(): | ||
print('TurtleBot 4 robot_upstart install script.') | ||
print('Usage: install.py [model] <ROS_DOMAIN_ID>') | ||
print('models: lite, standard') | ||
print('ROS_DOMAIN_ID: optional, defaults to 0') | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('model', type=str) | ||
parser.add_argument('--domain', type=int, default=0) | ||
parser.add_argument('--rmw', type=str, default='rmw_cyclonedds_cpp') | ||
|
||
argc = len(sys.argv) | ||
args = parser.parse_args() | ||
|
||
if argc == 1: | ||
print('Model required.') | ||
help() | ||
if args.model != 'lite' and args.model != 'standard': | ||
print('Invalid model: {0}'.format(args.model)) | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
model = sys.argv[1] | ||
if model != 'lite' and model != 'standard': | ||
print('Invalid model {0}'.format(model)) | ||
help() | ||
sys.exit(2) | ||
model = args.model | ||
|
||
domain_id = 0 | ||
if argc == 3: | ||
try: | ||
domain_id = int(sys.argv[2]) | ||
except ValueError: | ||
print('Invalid ROS_DOMAIN_ID {0}'.format(sys.argv[2])) | ||
help() | ||
sys.exit(3) | ||
if (args.domain >= 0 and args.domain <= 101) or \ | ||
(args.domain >= 215 and args.domain <= 232): | ||
domain_id = args.domain | ||
else: | ||
print('Invalid ROS_DOMAIN_ID: {0}'.format(args.domain)) | ||
parser.print_help() | ||
sys.exit(2) | ||
|
||
rmw = 'rmw_cyclonedds_cpp' | ||
if args.rmw == 'rmw_fastrtps_cpp' or args.rmw == 'rmw_cyclonedds_cpp': | ||
rmw = args.rmw | ||
else: | ||
print('Invalid RMW {0}'.format(args.rmw)) | ||
parser.print_help() | ||
sys.exit(3) | ||
|
||
print('Installing TurtleBot 4 {0}. ROS_DOMAIN_ID={1}, RMW_IMPLEMENTATION={2}'.format(model, domain_id, rmw)) | ||
|
||
print('Installing TurtleBot 4 {0}. ROS_DOMAIN_ID={1}'.format(model, domain_id)) | ||
if rmw == 'rmw_cyclonedds_cpp': | ||
rmw_config = '/etc/cyclonedds_rpi.xml' | ||
else: | ||
rmw_config = None | ||
|
||
turtlebot4_job = robot_upstart.Job(name='turtlebot4', | ||
rmw='rmw_cyclonedds_cpp', | ||
rmw_config='/etc/cyclonedds_rpi.xml', | ||
rmw=rmw, | ||
rmw_config=rmw_config, | ||
workspace_setup='/opt/ros/galactic/setup.bash', | ||
ros_domain_id=domain_id) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Flags: | ||
# -h Help | ||
|
||
Help() | ||
{ | ||
echo "TurtleBot 4 Configure Create 3" | ||
echo | ||
echo "usage: sudo bash create_config.sh [-h]" | ||
echo "options:" | ||
echo " -h Print this help statement" | ||
echo | ||
} | ||
|
||
while getopts "h" flag | ||
do | ||
case "${flag}" in | ||
h) | ||
Help | ||
exit;; | ||
\?) | ||
echo "Error: Invalid flag" | ||
exit;; | ||
esac | ||
done | ||
|
||
read -p "ROS_DOMAIN_ID (default 0): " ros_domain_id | ||
ros_domain_id=${ros_domain_id:-0} | ||
#read -p "ROS namespace (default empty): " namespace | ||
read -p "RMW Implementation [rmw_cyclonedds_cpp,rmw_fastrtps_cpp] (default rmw_cyclonedds_cpp): " rmw | ||
rmw=${rmw:-rmw_cyclonedds_cpp} | ||
|
||
echo "ROS_DOMAIN_ID: $ros_domain_id"; | ||
#echo "Namespace: $namespace"; | ||
echo "RMW_IMPLEMENTATION: $rmw"; | ||
read -p "Press enter to apply these settings." | ||
|
||
ttb4=$( cat /etc/turtlebot4 ) | ||
|
||
model="standard" | ||
|
||
case $ttb4 in | ||
*"lite"*) | ||
model="lite";; | ||
esac | ||
|
||
# Set Create 3 configuration | ||
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 | ||
|
||
# Reboot Create 3 | ||
curl -X POST http://192.168.186.2/api/reboot | ||
|
||
# Stop running turtlebot4 service | ||
sudo systemctl stop turtlebot4.service | ||
|
||
# Uninstall robot_upstart job | ||
uninstall.py | ||
|
||
# Install robot_upstart job with new ROS_DOMAIN_ID | ||
install.py $model --domain $ros_domain_id --rmw $rmw | ||
|
||
# Start job | ||
sudo systemctl daemon-reload && sudo systemctl start turtlebot4 | ||
|
||
# Add settings to .bashrc | ||
if grep -Fq "export RMW_IMPLEMENTATION=" ~/.bashrc | ||
then | ||
sudo sed -i "s/export RMW_IMPLEMENTATION=.*/export RMW_IMPLEMENTATION=$rmw/g" ~/.bashrc | ||
else | ||
echo "export RMW_IMPLEMENTATION=$rmw" | sudo tee -a ~/.bashrc | ||
fi | ||
|
||
if grep -Fq "export ROS_DOMAIN_ID=" ~/.bashrc | ||
then | ||
sudo sed -i "s/export ROS_DOMAIN_ID=.*/export ROS_DOMAIN_ID=$ros_domain_id/g" ~/.bashrc | ||
else | ||
echo "export ROS_DOMAIN_ID=$ros_domain_id" | sudo tee -a ~/.bashrc | ||
fi | ||
|
||
echo "Source ~/.bashrc to apply these changes to this terminal." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters