Configure ROS Environment (Post-Installation)
1. Overview
We need to distribute the ROS system on two computers: a Raspberry Pi (RPi) attaching to the robot; and a off-the-board host computer (Host). We will let the RPI to handle the hardware interface (Communicate with the micro-controller), and let the Host to do computations required by SLAM and navigation packages. You can refer to the official tutorial of Configuring environment. And this guide is emphasizing configuring ROS environment on two computers working together.
2. Load ROS by Default (on RPi and Host)
Execute following command in terminal once to append line: source /opt/ros/jazzy/setup.bash at the end of the $HOME/.bashrc file.
This allows any newly opened terminal to load ROS automatically.
Or, you’ll have to manually source ROS setup every time you fire up a new terminal.
$ echo "source /opt/ros/jazzy/setup.bash" >> $HOME/.bashrc
Sanity Check
Close current terminal and open a new one. Make sure you don’t see any file not found message in the new terminal.
Run following command in terminal.
$ ros2 topic list
And the expected result should be as follows.
/parameter_events
/rosout
3. Set ROS Domain ID (on RPi and Host)
Execute following command in terminal once to append line: export ROS_DOMAIN_ID=<id number> at the end of the $HOME/.bashrc file.
This allows the on-board Raspberry Pi to communicate with the host machine, exclusively, through your (wireless/wifi) network.
$ echo "export ROS_DOMAIN_ID=99" >> $HOME/.bashrc # use a number between 0 and 101
Sanity Check
Fire up a new terminal on both RPi and Host then type
echo $ROS_DOMAIN_ID. Compare if the out numbers are identical (or these two computer will lose communication).On RPi, start a
talkerexecutable to send out messages.
$ ros2 run demo_nodes_cpp talker
On Host, start a
listenerexecutable to receive messages sent from RPi.
$ ros2 run demo_nodes_py listener
4. Synchronize Clock
It is critical to have the RPi and the Host using the same clock. And Chrony can sync the time on both computers via Network Time Protocol (NTP). You can also refer to the blog post.
Install Chrony (on RPi and Host)
Fire up a terminal, run following command:
$ sudo apt install chrony
Configure Chrony on Host
Open configuration file with sudo privilege (You can use any text editor, the example below use nano).
$ sudo nano /etc/chrony/chrony.conf
Add following line to the end of the file
allow 192.168.0.0/24
Restart chronyd service on Host
$ sudo systemctl restart chronyd
Configure Chrony on RPi
Open configuration file with sudo privilege.
$ sudo nano /etc/chrony/chrony.conf
Add following line to the end of the file
$ server 192.168.0.XX iburst
XX is your Host’s IP address.
You can find your Host’s IP address with command ip route
Then restart chronyd service on RPi
$ sudo systemctl restart chronyd