The basics
Robotics Software Engineering · Lecture slides
Start the build
git clone https://github.com/canonlearning/robotics-software
cd robotics-software/code
docker compose up -d --build
Open a terminal on your laptop, with Docker running. The build downloads about 2 GB.
Today: make the robot drive, make it faster, and keep the change.
Go into the container
docker compose exec robot bash
pwd
ls
ls robot
The prompt now starts with root@: this terminal is inside the container.
pwd prints the folder we are in. ls lists what is in a folder.
Two terminals on one screen
tmux start it
Ctrl-b then % split the screen in two
Ctrl-b then an arrow move to the other side
The robot needs two terminals: one to run it, and one to send it a goal.
Start the robot, on the left
ros2 launch robot/robot.launch.py | tee -i ~/launch.log
It is ready when it prints Managed nodes are active, after a few
seconds. It then holds this side of the screen. | tee -i also saves
everything it prints in the file ~/launch.log.
Drive it, on the right
time python3 robot/goal.py 3.8 0.0
echo "0.2 41" >> ~/times.txt
The first line sends the robot 3.8 meters across the room and prints
Arrived. time then prints how long that took, after real. In the
second line, put your seconds in place of the 41. >> adds the line to
the end of a file.
How many programs is the robot?
- 1
- 2: the simulator and the navigation
- 8
- More than 20
Count them, on the right
ps -e
grep "Reached the goal" ~/launch.log
wc -l ~/launch.log
ps -e lists every running program. The robot is python3, which is its
simulator, and the seven names under it. grep prints the lines of a file
that hold the words: the line starts with the name of the program that
said it. wc -l counts a file's lines.
The robot is 8 programs, and each one is a process of its own.
At twice the top speed, how long will the drive take?
- About 20 seconds: half
- About 26 seconds
- About 41 seconds: the same
- The robot will hit a wall
Change the top speed to 0.4, on the right
nvim robot/nav2.yaml
/desired then Enter jump to the line
A type at the end of the line
Backspace delete the old number
Esc stop typing
:wq then Enter save and leave
:q! then Enter leave without saving
Drive it again
# on the left: stop the robot, and start it again
ros2 launch robot/robot.launch.py | tee -i ~/launch.log
# on the right
time python3 robot/goal.py 3.8 0.0
echo "0.4 26" >> ~/times.txt
Ctrl-C stops the robot. The up arrow brings back an earlier command. The robot reads its settings when it starts, so it has to be started again.
Now 3.0
cat ~/times.txt
Change the line to 3.0, start the robot again, time the drive, and add
the time to the file. cat prints a file.
The times on one laptop
At twice the top speed the drive took 26 seconds, not 20. At 3.0 it took longer than at 0.4.
A program in C++
cat basics/drive_time.cpp
g++ basics/drive_time.cpp -o basics/drive_time
./basics/drive_time
On the right. The file is a program in C++ that divides the distance by
the top speed. g++ builds it into a program the computer can run, named
after -o. The last line runs it.
Change its speed to 0.4
nvim basics/drive_time.cpp
/0.2 then Enter jump to the number
R type over it
Esc stop typing
:wq then Enter save and leave
Then run it again, with ./basics/drive_time.
What does it print?
- 9.5 seconds
- 19 seconds
- An error
- Nothing
Build it again
g++ basics/drive_time.cpp -o basics/drive_time
./basics/drive_time
It printed 19 because the program was built before the change. Built again, it prints 9.5.
./basics/drive_time is the program that g++ built. After a change to
the .cpp file, it has to be built again.
What did we change?
cd robotics-software/code
git status
git diff
Open a second terminal on the laptop for this: git is not used inside
the container today. git status names the files that changed. git diff
shows each changed line as it was, in red, and as it is, in green.
Put one back
git restore robot/nav2.yaml
git diff
git blame -L 72,72 robot/nav2.yaml
git restore puts a file back as it was in the last commit, so
git diff no longer shows it. git blame says who last changed line 72,
and when: the person who chose 0.2.
Choose a speed
nvim robot/nav2.yaml in the container, on the right
git diff on the laptop
Set the top speed you would give this robot. git diff shows your choice
against the 0.2.
Tell git who you are
git config --global user.name "Your Name"
git config --global user.email "you@gatech.edu"
On the laptop, once. Git writes this name on every commit you make.
Keep it, on a branch
git switch -c faster
git commit -a -m "Drive faster"
git log --oneline -3
The first line makes a branch and moves to it. The second saves every changed file as one commit, with a message. The third lists the newest commits: yours is on top.
On main, what is the top speed?
git switch main
grep desired robot/nav2.yaml
Guess before you run the two lines.
- Your speed
- 0.2
- The file is gone
- Git refuses to switch
Merge it
git merge faster
grep desired robot/nav2.yaml
git log --oneline -3
git merge brings the commits of faster into main. The file has your
speed again, and git log shows your commit on main.
After docker compose down, what is left?
- The speed in
nav2.yaml, and the times in~/times.txt - Only the speed
- Only the times
- Neither
Delete the container, and make a new one
Ctrl-C on the left, to stop the robot
exit three times
docker compose down
docker compose up -d
docker compose exec robot bash
The first two exits close the two sides of tmux, and the third leaves
the container. down deletes the container, and up makes a new one
from the image.
What is left?
grep desired robot/nav2.yaml
cat ~/times.txt
The speed is still there. The times are gone.
~/times.txt was inside the container, and was deleted with it.
robot/nav2.yaml is in the folder the container shares with the laptop.
What we used
- tmux put two terminals on one screen
psandgrepshowed what was running, and what it printed- Neovim changed a line in a file
g++built a C++ program- git showed what changed, and kept it as a commit
- Docker gave every laptop the same robot
Before the next class
- Work the six practice problems of "The basics" on paper
- Run
nvim +Tutor, which takes 30 minutes