-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathros.bash
More file actions
194 lines (163 loc) · 6.32 KB
/
Copy pathros.bash
File metadata and controls
194 lines (163 loc) · 6.32 KB
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
#!/bin/bash
# ROS Jazzy Jalisco Install Script for Turtlebot 3 + OpenCR Configuration
# status --> TESTED ON TURTLEBOT3 (RPi 3B+ and RPi 4B)
# exit on error
set -e
# Args: swapfile: bool, ROS_DOMAIN_ID: int, lidar type: int
SWAPFILE="true"
ROS_ID="30"
LIDAR="2"
OPENCR="true"
MODEL="burger"
# handling cli args
while [[ $# -gt 0 ]]; do
case $1 in
--ros-id|-id)
ROS_ID="$2"
shift 2
;;
--lidar|-ld)
LIDAR="$2"
shift 2
;;
--no-swapfile|-nsf)
SWAPFILE="false"
shift
;;
--ros-only|-ro)
OPENCR="false"
shift
;;
--model|-m)
MODEL="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [--lidar|-ld LIDAR] [--ros-id|-id ID] [--model|-m MODEL] [--no-swapfile|-nsf None] [--ros-only|-ro None]"
exit 0
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# fun ascii art :)
cat << "EOF"
_____ _ _ ____ _
|_ _| _ _ __| |_| | ___| __ ) ___ ___ | |_
| || | | | '__| __| |/ _ \ _ \ / _ \ / _ \| __|
| || |_| | | | |_| | __/ |_) | (_) | (_) | |_
|_| \__,_|_| \__|_|\___|____/ \___/ \___/ \__|
R O S + O P E N C R
_____ ____
/ \ | o |
| |/ ___\|
|_________/
|_|_| |_|_|
EOF
echo "Welcome to TurtleBoot ROS+OPENCR!"
echo "developed by @kmhswimgirl"
# confirm args before entering password
echo "ROS_DOMAIN_ID: $ROS_ID, Swapfile: $SWAPFILE, LiDAR Type: $LIDAR, OPEN CR Setup: $OPENCR"
# start sudo session
sudo -v
while true; do sudo -n true; sleep 60; done 2>/dev/null &
# swapfile logic
if [ "$SWAPFILE" = "true" ]; then
# make swapfile if RPi has <= 2GB RAM --> ask for bool
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
free -h # --> to check for swap memory
echo "Swapfile successfully created!"
fi
# Other required dependencies
sudo apt install -y software-properties-common
sudo add-apt-repository -y universe
#referesh package updates and install curl
sudo apt update && sudo apt install -y curl
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo $VERSION_CODENAME)_all.deb" # If using Ubuntu derivates use $UBUNTU_CODENAME
sudo apt install -y /tmp/ros2-apt-source.deb
# install ROS + dev tools
sudo apt update
sudo apt install -y ros-dev-tools
sudo apt update
sudo apt -y upgrade
sudo apt install -y ros-jazzy-ros-base
source ~/.bashrc
source /opt/ros/jazzy/setup.bash
# Turtlebot Dependencies
sudo apt install -y python3-argcomplete python3-colcon-common-extensions libboost-system-dev build-essential
sudo apt install -y ros-jazzy-hls-lfcd-lds-driver
sudo apt install -y ros-jazzy-turtlebot3-msgs
sudo apt install -y ros-jazzy-dynamixel-sdk
sudo apt install -y libudev-dev
# dependencies that Robotis forgot in their setup guide...
sudo apt install -y ros-jazzy-xacro
# adding cyclone DDS as well
sudo apt install -y ros-jazzy-rmw-cyclonedds-cpp
# make turtlebot workspace
mkdir -p ~/turtlebot3_ws/src
cd ~/turtlebot3_ws/src
# check for duplicate dir or accidental root owned dir
if [ -d "turtlebot3" ]; then
echo "Removing existing turtlebot3 directory (may be root-owned or incomplete)..."
sudo rm -rf turtlebot3
fi
# Clone Packages from GitHub, make sure branches are there as well
if ! git clone -b jazzy https://github.com/ROBOTIS-GIT/turtlebot3.git; then
echo "Failed to clone turtlebot3 repository. Check if the branch 'jazzy' exists."
exit 1
fi
if ! git clone -b jazzy https://github.com/ROBOTIS-GIT/ld08_driver.git; then
echo "Failed to clone ld08_driver repository. Check if the branch 'jazzy' exists."
exit 1
fi
# remove cartographer and nav2 packages
cd ~/turtlebot3_ws/src/turtlebot3
rm -rf turtlebot3_cartographer turtlebot3_navigation2 || true
cd ~/turtlebot3_ws/
# Prevent duplicate lines in .bashrc
grep -qxF 'source /opt/ros/jazzy/setup.bash' ~/.bashrc || echo 'source /opt/ros/jazzy/setup.bash' >> ~/.bashrc
# building turtlebot workspace
cd ~/turtlebot3_ws/
colcon build --symlink-install --parallel-workers 1
# prevent ~/.bashrc clutter
grep -qxF 'source ~/turtlebot3_ws/install/setup.bash' ~/.bashrc || echo 'source ~/turtlebot3_ws/install/setup.bash' >> ~/.bashrc
source /opt/ros/jazzy/setup.bash
source ~/turtlebot3_ws/install/setup.bash
PKG_PREFIX=$(ros2 pkg prefix turtlebot3_bringup)
if [ -z "$PKG_PREFIX" ]; then
echo "Could not find turtlebot3_bringup package. Exiting."
exit 1
fi
sudo cp "$PKG_PREFIX/share/turtlebot3_bringup/script/99-turtlebot3-cdc.rules" /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
# export variables for configuring the turtlebot, prevent duplicates
grep -qxF "export ROS_DOMAIN_ID=$ROS_ID #TURTLEBOT3" ~/.bashrc || echo "export ROS_DOMAIN_ID=$ROS_ID #TURTLEBOT3" >> ~/.bashrc
grep -qxF "export LDS_MODEL=LDS-0$LIDAR # lidar config" ~/.bashrc || echo "export LDS_MODEL=LDS-0$LIDAR # lidar config" >> ~/.bashrc
grep -qxF "export TURTLEBOT3_MODEL=$MODEL # model" ~/.bashrc || echo "export TURTLEBOT3_MODEL=$MODEL # model" >> ~/.bashrc
grep -qxF "export RMW_IMPLEMENTATION='rmw_cyclonedds_cpp' # switch to cyclone dds" ~/.bashrc || echo "export RMW_IMPLEMENTATION='rmw_cyclonedds_cpp' # switch to cyclone dds" >> ~/.bashrc
# OPEN CR Section
if [ "$OPENCR" = true ]; then
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install -y libc6:armhf
export OPENCR_PORT=/dev/ttyACM0
export OPENCR_MODEL=burger
rm -rf ./opencr_update.tar.bz2
wget https://github.com/ROBOTIS-GIT/OpenCR-Binaries/raw/master/turtlebot3/ROS2/latest/opencr_update.tar.bz2
tar -xvf opencr_update.tar.bz2
cd ./opencr_update
./update.sh $OPENCR_PORT $OPENCR_MODEL.opencr
fi
# Kill sudo process
kill %1 2>/dev/null || true
# confirm sucess
echo "Set up complete!"
exit 0