Install ROS Kinetic, TurtleBot3, Raspicam on Raspberry Pi 4b
by ilia_o in Circuits > Software
9198 Views, 6 Favorites, 0 Comments
Install ROS Kinetic, TurtleBot3, Raspicam on Raspberry Pi 4b
TurtleBot3 Burger comes with Raspberry Pi 3 B/B+ and does not support the new (as of 9/2019) Raspberry Pi 4b. Follow the steps below to make TurtleBot3 work on Raspberry Pi 4b, including
- building ROS Kinetic from sources on Raspberry Pi 4b Raspbian Buster
- adding TurtleBot3-specific packages
- adding raspicam-node to
Install Raspbian and Configure Raspberry Pi 4b
Download a Raspbian image. I used Raspbian Buster dated 2019–07–10.
Burn the downloaded Raspbian image to an SD card (at least 8Gb in size). Connect a display, keyboard and mouse to your Raspberry Pi 4b, boot and connect to WiFi. Extend file system to occupy your entire SD card and, optionally, enable SSH and VNC by running
sudo raspi-config
Download ROS Kinetic Sources
The instructions below follow the official ROS tutorial as well as DmitryM8 instructable.
Log in to your Raspberry Pi 4b and execute these commands to add ROS package repository, build tools and initialize ROS dependency tool.
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 sudo apt-get update sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake sudo rosdep init rosdep update
Create a workspace to build ROS Kinetic from source.
mkdir ~/ros_catkin_ws cd ~/ros_catkin_ws
Download source code for "ros_comm" package, which contains essential modules intended to run on robot's on-board computer. Here rosinstall_generator creates a list of source code repositories to download. wstool then proceeds to download the source code.
rosinstall_generator ros_comm --rosdistro kinetic --deps --wet-only --tar > kinetic-ros_comm-wet.rosinstall wstool init -j8 src kinetic-ros_comm-wet.rosinstall rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
To run TurtleBot3 and raspicam you will need these ROS packages in addition to ros_comm: common_msgs, rosserial, image_common, image_transport_plugins and diagnostics. To add these packages run these commands.
rosinstall_generator common_msgs common_msgs rosserial image_common image_transport_plugins diagnostics nodelet_core --rosdistro kinetic --deps --wet-only --tar > kinetic-extra-wet.rosinstall wstool merge -t src kinetic-extra-wet.rosinstall wstool update -j8 -t src rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
As dependencies versions change over time, there may be errors like "python-rosdistro-modules_0.7.5-1_all.deb (--unpack): trying to overwrite '/usr/lib/python2.7/dist-packages/rosdistro/__init__.py', which is also in package python-rosdistro 0.7.2-1". Resolve these "trying to overwrite" errors:
sudo dpkg --remove --force-all python-catkin-pkg python-catkin-pkg-modules python-rosdistro python-rosdistro-modules python-rospkg python-rospkg-modules // or sudo apt remove <package names> sudo apt --fix-broken install
Manually Fix ROS Compilation Errors
Building ROS at this point will fail with various errors. Let's fix those errors by manually editing ROS source code.
Edit
/home/pi/ros_catkin_ws/src/opencv3/modules/python/src2/cv2.cpp line 885
Replace
char* str = PyString_AsString(obj);
with
const char* str = PyString_AsString(obj);
Edit files below.
/home/pi/ros_catkin_ws/src/rospack/include/rospack/rospack.h /home/pi/ros_catkin_ws/src/rospack/src/rospack.cpp /home/pi/ros_catkin_ws/src/rospack/src/utils.cpp
Remove all occurrences of
/tr1
and replace all occurrences of
std::tr1
with
boost
Edit files below.
/home/pi/ros_catkin_ws/src/actionlib/include/actionlib/client/simple_action_client.h /home/pi/ros_catkin_ws/src/actionlib/include/actionlib/destruction_guard.h /home/pi/ros_catkin_ws/src/actionlib/include/actionlib/server/simple_action_server_imp.h /home/pi/ros_catkin_ws/src/actionlib/src/connection_monitor.cpp /home/pi/ros_catkin_ws/src/actionlib/test/destruction_guard_test.cpp /home/pi/ros_catkin_ws/src/bond_core/bondcpp/src/bond.cpp /home/pi/ros_catkin_ws/src/ros_comm/roscpp/include/ros/timer_manager.h /home/pi/ros_catkin_ws/src/ros/roslib/test/utest.cpp
Replace all ocurrences of
boost::posix_time::milliseconds(…)
with
boost::posix_time::milliseconds(int(…))
Edit the file below.
/home/pi/ros_catkin_ws/src/geometry2/tf2/src/buffer_core.cpp
Replace all
logWarn
with
CONSOLE_BRIDGE_logWarn
and
logError
with
CONSOLE_BRIDGE_logError
Build ROS Kinetic
At this point the build should succeed.
cd ~/ros_catkin_ws sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/kinetic
Append to ~/.bashrc and also execute in your shell:
source /opt/ros/kinetic/setup.bash
Build TurtleBot3 and Raspicam Packages
These instructions follow ROBOTIS tutorial.
mkdir -p ~/catkin_ws/src cd ~/catkin_ws/ catkin_make source devel/setup.bash
Edit ~/.bashrc and append
source /home/pi/catkin_ws/devel/setup.bash
Now, execute
cd ~/catkin_ws/src git clone https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone https://github.com/ROBOTIS-GIT/turtlebot3.git git clone https://github.com/UbiquityRobotics/raspicam_node.git cd ~/catkin_ws/src/turtlebot3 rm -r turtlebot3_description/ turtlebot3_teleop/ turtlebot3_navigation/ turtlebot3_slam/ turtlebot3_example/ cd ~/catkin_ws && catkin_make
The build should succeed.
Configure Raspberry Pi 4b to recognize TurtleBot3 USB peripherals.
rosrun turtlebot3_bringup create_udev_rules
Run ifconfig and write down Raspbery Pi's IP.
ifconfig
Edit ~/.bashrc. Add the lines below and also execute them in your shell.
export ROS_MASTER_URI=http://YOUR.ROS.MASTER.IP:11311 export ROS_HOSTNAME=YOUR.RASPBERRY.PI.IP
Synchronize Raspberry Pi and PC time:
sudo apt-get install ntpdate sudo ntpdate ntp.ubuntu.com
At this point, your setup should be completed. Now you can use your Raspberry Pi 4b instead of Raspberry Pi 3/3+ in your TurtleBot3.