EE3305/ME3243 Robotic System Design
© Lai Yan Kai, National University of Singapore
A bash script (file extension .sh) contains terminal commands, allowing users to conveniently run long terminal commands without re-typing them.
This chapter shows how a bash script can be created and run, and provides some examples of these scripts.
2.3 Kill Ruby Scripts (Gazebo): kill.sh
2.6 Simulate SLAM: sim_slam.sh
2.7 Save SLAM Map: save_map.sh
2.8 Simulate Nav2 Localization: sim_nav2.sh
-
Use VSCode to create a new file ending in
.shin the workspace directory. For example,bd.sh. -
In a terminal in the workspace directory, allow running the script with
chmod. This should be run once for every new.shfile.cd ~/ee3305 # go to workspace. chmod +x *.sh # allow all current .sh files in this directory.
Again, the command only needs to be run once for each file in its lifetime.
-
To run a script called
bd.sh,cd ~/ee3305 # go to workspace. ./bd.sh # run commands in bd.sh in a new subshell.
The
./copies the environment variables in the current shell to a new subshell without modifying the current shell's variables. This should be the preferred way to execute bash scripts in this course.
The scripts below are used by the author to quickly run commands.
For re-building the workspace.
#!/bin/bash
colcon build --symlink-installFor re-building the workspace if the built executables do not seem to perform as intended (mostly due to careless changes to the package and executables).
Requires bd.sh.
#!/bin/bash
rm -rf build install log
./bd.shGazebo may occasionally fail to stop running when the user interrupts with Ctrl+C.
Since Gazebo is run using ruby scripts, we can kill all ruby scripts with pkill -9 ruby.
However, if there are other applications run by ruby, it will kill those applications as well.
As no applications are run by ruby in this course, we assume that the following is sufficient.
#!/bin/bash
# kills gz, which is run by ruby. This will kill other ruby processes.
pkill -9 rubyThis script runs the project files in simulation. The launch arguments below can be modified.
Requires kill.sh.
#!/bin/bash
source install/setup.bash
ros2 launch ee3305_bringup run.launch.py cpp:=False headless:=False libgl:=False
./kill.sh # run in case gz cannot be interrupted properly.Teleoperates the turtlebot.
#!/bin/bash
export TURTLEBOT3_MODEL=burger
ros2 run turtlebot3_teleop teleop_keyboardRuns the simulation and SLAM together.
The launch arguments below can be modified.
Requires kill.sh.
#!/bin/bash
source install/setup.bash
ros2 launch ee3305_bringup sim_slam.launch.py headless:=False libgl:=False
./kill.shSaves the map created by the running SLAM node and installs the map by building the workspace.
#!/bin/bash
# make sure the SLAM (cartographer) node is running.
ros2 run nav2_map_server map_saver_cli -f src/ee3305_bringup/maps/ee3305
./bd.shRuns the simulation and Nav2 localization based on the previously saved SLAM map.
The launch arguments below can be modified.
Requires kill.sh.
#!/bin/bash
source install/setup.bash
ros2 launch ee3305_bringup sim_nav2.launch.py headless:=False libgl:=False
./kill.sh