Skip to content

Commit

Permalink
Merge pull request #2 from turtlebot/roni-kreinin/domain_id
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
roni-kreinin authored Sep 27, 2022
2 parents d7c2278 + 31e05b1 commit 43d48d1
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 29 deletions.
12 changes: 12 additions & 0 deletions conf/webserver.service
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
58 changes: 34 additions & 24 deletions scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
81 changes: 81 additions & 0 deletions scripts/ros_config.sh
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."
22 changes: 17 additions & 5 deletions scripts/turtlebot4_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ source /opt/ros/galactic/setup.bash
sudo apt install -y \
network-manager \
daemontools \
ros-galactic-robot-upstart \
chrony \
socat \
ros-galactic-robot-upstart \
ros-galactic-turtlebot4-robot \
ros-galactic-irobot-create-control
ros-galactic-irobot-create-control \
ros-galactic-rmw-fastrtps-cpp

# Copy udev rules
sudo cp $SETUP_DIR/udev/turtlebot4.rules /etc/udev/rules.d/
Expand All @@ -82,20 +84,29 @@ sudo cp $SETUP_DIR/conf/chrony.conf /etc/chrony/
# Restart chrony
sudo service chrony restart

# Copy webserver service
sudo cp $SETUP_DIR/conf/webserver.service /etc/systemd/system/

# Enable webserver service to run from boot
sudo systemctl enable webserver.service

# Enable usb0
echo "dtoverlay=dwc2,dr_mode=peripheral" | sudo tee -a /boot/firmware/usercfg.txt
sudo sed -i '${s/$/ modules-load=dwc2,g_ether/}' /boot/firmware/cmdline.txt

# Enable i2c-3
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

# Source galactic setup in bashrc
echo "source /opt/ros/galactic/setup.bash" | sudo tee -a ~/.bashrc

# Configure cyclonedds
sudo cp $SETUP_DIR/conf/cyclonedds_rpi.xml /etc/
echo "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp" | sudo tee -a ~/.bashrc
echo "export CYCLONEDDS_URI=/etc/cyclonedds_rpi.xml" | sudo tee -a ~/.bashrc

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

# Robot upstart
$SCRIPT_DIR/install.py $model
Expand All @@ -106,6 +117,7 @@ sudo systemctl daemon-reload
sudo cp $SCRIPT_DIR/wifi.sh \
$SCRIPT_DIR/create_update_0.4.0.sh \
$SCRIPT_DIR/create_update.sh \
$SCRIPT_DIR/ros_config.sh \
$SCRIPT_DIR/swap_on.sh \
$SCRIPT_DIR/swap_off.sh \
$SCRIPT_DIR/bluetooth.sh \
Expand All @@ -114,7 +126,7 @@ sudo cp $SCRIPT_DIR/wifi.sh \

# Set image information
sudo touch /etc/turtlebot4
echo "TurtleBot 4 $model v0.1.2" | sudo tee /etc/turtlebot4
echo "TurtleBot 4 $model v0.1.3" | sudo tee /etc/turtlebot4

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

Expand Down

0 comments on commit 43d48d1

Please sign in to comment.