forked from aws-deepracer/aws-deepracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize_deepracer.sh
More file actions
executable file
·154 lines (109 loc) · 5.48 KB
/
initialize_deepracer.sh
File metadata and controls
executable file
·154 lines (109 loc) · 5.48 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
#!/bin/bash
### Setup color output macro ###
loginfo() {
GREEN="\033[0;32m"
GREENB="\033[1;32m"
YELLOW="\033[0;33m"
YELLOWB="\033[1;33m"
RESET="\033[0m"
echo -e "${!1}DEEPRACER INITIALIZATION: ${2}${RESET}"
}
### Run in non-interactive mode ###
export DEBIAN_FRONTEND=noninteractive
### Terminate on errors ###
set -e
### Modify timeout for password requirement ###
loginfo "YELLOWB" "Updating password timeout the 'deepracer-core' service..."
pushd /etc/sudoers.d
echo "Defaults timestamp_timeout=60" | sudo tee -a deepracer
### Stop and disable the `deepracer-core` service ###
loginfo "YELLOWB" "Disabling the 'deepracer-core' service..."
sudo systemctl stop deepracer-core.service
sudo systemctl disable deepracer-core.service
### Update the system ###
loginfo "YELLOWB" "Updating and upgrading packages..."
sudo apt update -y
sudo apt-mark hold rsyslog # the `config` package by Intel (`dpkg -l` description: "deepcam configuration install package.") causes conflicts with the `rsyslog` package. This is because the `config` packages also writes to `/etc/logrotate.d/rsyslog`.
sudo apt upgrade -qy -o Dpkg::Options::="--force-confdef" # so that it chooses the default option when it comes to configuration file conflicts
sudo apt install ros-foxy-navigation2 ros-foxy-nav2-bringup ros-foxy-imu-tools -qy # install dependencies
### Install the AWS DeepRacer ROS 2 packages ###
loginfo "YELLOWB" "Installing ROS 2 packages for the AWS DeepRacer..."
cd /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_nodes && ./install_dependencies.sh
# Ignore the files when building (they're needed for simulation only)
touch /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_description/COLCON_IGNORE
touch /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_gazebo/COLCON_IGNORE
# Install the IMU I2C driver
cd /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_nodes/BMI160-i2c
pip install .
# Install the IMU package
source /opt/ros/foxy/setup.bash
cd /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_nodes/larsll-deepracer-imu-pkg
sudo rosdep init
rosdep update
rosdep install -i --from-path . --rosdistro foxy -y
# Install the ROS 2 packages
cd /home/deepracer/deepracer_nav2_ws/aws-deepracer/deepracer_nodes
rosws update
cd ~/deepracer_nav2_ws/aws-deepracer/ && colcon build
### Set up userspace access to camera ###
loginfo "YELLOWB" "Setting up access to camera..."
sudo usermod -aG video deepracer # the `video` group already has access, so just add the `deepracer` user
### Set up userspace access to servo ###
loginfo "YELLOWB" "Setting up access to servo..."
# Create new group and add users
sudo groupadd pwmgroup
sudo usermod -aG pwmgroup deepracer
sudo usermod -aG pwmgroup root
# Create shell script to modify permissions
cat <<EOF | sudo tee /usr/local/bin/udev-pwm-permissions.sh
#!/bin/bash
GPIO_PIN=436 # provided by pegatron as found https://github.com/aws-deepracer/aws-deepracer-servo-pkg/blob/f232684f84313dd3f2c740836493ccd049be6686/servo_pkg/include/servo_pkg/servo_mgr.hpp#L47
# Workaround to 'manually' create the \`pwm*\` directories in /sys/class/pwm/pwmchip0; there are 5 channels in total
for (( i=0; i<5; i++ ))
do
echo \${i} > /sys/class/pwm/pwmchip0/export
done
# Workaround to 'manually' create the gpio pin directory in /sys/class/gpio/
echo \${GPIO_PIN} > /sys/class/gpio/export
# Modify group
chown -R :pwmgroup /sys/class/pwm/pwmchip0/ # additional front slash indicates modification of the contents of pwmchip0
chown -R :pwmgroup /sys/class/gpio/export
chown -R :pwmgroup /sys/class/gpio/gpio\${GPIO_PIN}/
# Modify permissions for owner and group
chmod -R 770 /sys/class/pwm/pwmchip0/
chmod -R 220 /sys/class/gpio/export
chmod -R 770 /sys/class/gpio/gpio\${GPIO_PIN}/
EOF
sudo chmod +x /usr/local/bin/udev-pwm-permissions.sh
# Create udev rule to run shell script
cat <<EOF | sudo tee /etc/udev/rules.d/99-custom-pwm.rules
SUBSYSTEM=="pwm", KERNEL=="pwmchip0", ACTION=="add", PROGRAM="/usr/local/bin/udev-pwm-permissions.sh"
EOF
### Set up userspace access to IMU ###
loginfo "YELLOWB" "Setting up access to IMU..."
sudo usermod -aG i2c deepracer # the i2c group already has access, so just add the `deepracer` user
### Installing convenience scripts ###
# Copy executables to be global binaries
mkdir -p ${HOME}/.local/bin
cp --preserve=mode setup/bin/start-ros-service ${HOME}/.local/bin/start-ros-service
cp --preserve=mode setup/bin/stop-ros-service ${HOME}/.local/bin/stop-ros-service
# Copy internal executable scripts (not intended for users)
mkdir -p ${HOME}/.local/libexec
cp --preserve=mode setup/libexec/start_ros.sh ${HOME}/.local/libexec/start_ros.sh
cp --preserve=mode setup/libexec/start_ros_evo.sh ${HOME}/.local/libexec/start_ros_evo.sh
# Create convenience service file to run ROS 2 nodes
mkdir -p ${HOME}/.config/systemd/user
cp setup/service/start-ros.service ${HOME}/.config/systemd/user/start-ros.service
cp setup/service/start-ros-evo.service ${HOME}/.config/systemd/user/start-ros-evo.service
systemctl --user daemon-reload
### Adding source files and variables to .bashrc ###
loginfo "YELLOWB" "Adding source files and variables to .bashrc..."
echo "" >> ~/.bashrc
echo "# ROS source files" >> ~/.bashrc
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
echo "source /home/deepracer/deepracer_nav2_ws/aws-deepracer/install/setup.bash" >> ~/.bashrc
echo "" >> ~/.bashrc
echo "# Updated PATH locations" >> ~/.bashrc
echo "export PATH=${HOME}/.local/bin:${PATH}" >> ~/.bashrc
### Completion ###
loginfo "GREENB" "Initialization complete!"