Robotics StackExchange | Archived questions

Python 3 in ROS Indigo on Raspberry Pi

I apologize for posting this question as python3 is not entirely supported for ROS 1. I am using a python3 library (it uses int.frombytes and int.tobytes) in my project. I have successfully installed python3 on Raspberry Pi as well. I need to run ROS (Indigo) node on this board. I found brief instructions for python 3 in ROS Indigo here. Unfortunately, it didn't work quite well, or I missed some step.

The answer referred above says to create a virtual environment by using virtualenv -p /usr/bin/python3 and then under it run pip install rospkg. It didn't work. Please see terminal below-

(whill) pi@raspberrypi:~ $ ipython
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import rospy                                                            
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-fb60b5b51009> in <module>
----> 1 import rospy

ModuleNotFoundError: No module named 'rospy'

Next, I followed the official Wiki page for installing ROS Indigo on the Raspberry Pi here. Please note that all these instructions were executed inside the python3 virtual environment.

From ROS Indigo, I need only publishers and subscribers of standard ROS messages. Therefore I decided to install ROS-Comm by using the following commands-

(whill) pi@raspberrypi:~/ros_catkin_ws $ /home/pi/whill/bin/rosinstall_generator ros_comm --rosdistro indigo --deps --wet-only --exclude roslisp --tar > indigo-ros_comm-wet.rosinstall
(whill) pi@raspberrypi:~/ros_catkin_ws $ /home/pi/whill/bin/wstool init src indigo-ros_comm-wet.rosinstall

I also installed libconsole-bridge-dev as stated in the Wiki page. The remaining dependencies were resolved by running rosdep-

(whill) pi@raspberrypi:~/ros_catkin_ws $ /home/pi/whill/bin/rosdep install --from-paths src --ignore-src --rosdistro indigo -y -r --os=debian:buster

The above took a while to finish. Finally, the catkin workspace was build as shown below-

(whill) pi@raspberrypi:~/ros_catkin_ws $ sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/indigo -j2
Base path: /home/pi/ros_catkin_ws
Source space: /home/pi/ros_catkin_ws/src
Build space: /home/pi/ros_catkin_ws/build_isolated
Devel space: /home/pi/ros_catkin_ws/devel_isolated
Install space: /opt/ros/indigo
Additional CMake Arguments: -DCMAKE_BUILD_TYPE=Release
Additional make Arguments: -j2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~  traversing 48 packages in topological order:
~~  - catkin
~~  - genmsg
~~  - gencpp
~~  - genlisp
~~  - genpy
~~  - cmake_modules
~~  - cpp_common
~~  - message_generation
~~  - message_runtime
~~  - mk
~~  - ros
~~  - ros_comm
~~  - rosbash
~~  - rosboost_cfg
~~  - rosbuild
~~  - rosclean
~~  - roscpp_traits
~~  - roscreate
~~  - rosgraph
~~  - roslang
~~  - rosmake
~~  - rosmaster
~~  - rosmsg
~~  - rospack
~~  - roslib
~~  - rosparam
~~  - rospy
~~  - rosservice
~~  - rostime
~~  - roscpp_serialization
~~  - roslaunch
~~  - rosunit
~~  - rosconsole
~~  - roslz4
~~  - rosbag_storage
~~  - rostest
~~  - std_msgs
~~  - rosgraph_msgs
~~  - std_srvs
~~  - xmlrpcpp
~~  - roscpp
~~  - rosout
~~  - message_filters
~~  - rosnode
~~  - rostopic
~~  - roswtf
~~  - topic_tools
~~  - rosbag
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The packages or cmake arguments have changed, forcing cmake invocation

==> Processing catkin package: 'catkin'
==> Creating build directory: 'build_isolated/catkin'
==> cmake /home/pi/ros_catkin_ws/src/catkin -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/catkin -DCMAKE_INSTALL_PREFIX=/opt/ros/indigo -DCMAKE_BUILD_TYPE=Release -G Unix Makefiles in '/home/pi/ros_catkin_ws/build_isolated/catkin'
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/pi/ros_catkin_ws/devel_isolated/catkin
-- Using CMAKE_PREFIX_PATH: 
-- Found PythonInterp: /usr/bin/python (found version "2.7.16") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/ros_catkin_ws/build_isolated/catkin/test_results
-- Found gtest: gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/ros_catkin_ws/build_isolated/catkin
==> make -j2 in '/home/pi/ros_catkin_ws/build_isolated/catkin'
==> make install in '/home/pi/ros_catkin_ws/build_isolated/catkin'
COMPLETE OUTPUT IS NOT SHOWN TO KEEP IT SHORT

The build process failed due to a missing header file from the boost. Please see below-

+ cd /home/pi/ros_catkin_ws/src/ros_comm/rosmsg
+ mkdir -p /opt/ros/indigo/lib/python2.7/dist-packages
+ /usr/bin/env PYTHONPATH=/opt/ros/indigo/lib/python2.7/dist-packages:/home/pi/ros_catkin_ws/build_isolated/rosmsg/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages CATKIN_BINARY_DIR=/home/pi/ros_catkin_ws/build_isolated/rosmsg /usr/bin/python /home/pi/ros_catkin_ws/src/ros_comm/rosmsg/setup.py build --build-base /home/pi/ros_catkin_ws/build_isolated/rosmsg install --install-layout=deb --prefix=/opt/ros/indigo --install-scripts=/opt/ros/indigo/bin
running build
running build_py
running build_scripts
running install
running install_lib
running install_scripts
changing mode of /opt/ros/indigo/bin/rosmsg to 755
changing mode of /opt/ros/indigo/bin/rosmsg-proto to 755
changing mode of /opt/ros/indigo/bin/rossrv to 755
running install_egg_info
Removing /opt/ros/indigo/lib/python2.7/dist-packages/rosmsg-1.11.21.egg-info
Writing /opt/ros/indigo/lib/python2.7/dist-packages/rosmsg-1.11.21.egg-info
<== Finished processing package [23 of 48]: 'rosmsg'

==> Processing catkin package: 'rospack'
==> Building with env: '/opt/ros/indigo/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/pi/ros_catkin_ws/build_isolated/rospack'
==> make -j1 in '/home/pi/ros_catkin_ws/build_isolated/rospack'
[ 11%] Building CXX object CMakeFiles/rospack.dir/src/rospack.cpp.o
In file included from /home/pi/ros_catkin_ws/src/rospack/src/rospack.cpp:28:
/home/pi/ros_catkin_ws/src/rospack/include/rospack/rospack.h:108:10: fatal error: boost/tr1/unordered_set.hpp: No such file or directory
 #include <boost/tr1/unordered_set.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/rospack.dir/build.make:63: CMakeFiles/rospack.dir/src/rospack.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:371: CMakeFiles/rospack.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
<== Failed to process package 'rospack': 
  Command '['/opt/ros/indigo/env.sh', 'make', '-j1']' returned non-zero exit status 2

Reproduce this error by running:
==> cd /home/pi/ros_catkin_ws/build_isolated/rospack && /opt/ros/indigo/env.sh make -j1

Command failed, exiting.

It seems that I am using boost 1.67 as shown below-

(whill) pi@raspberrypi:~/ros_catkin_ws $ apt-cache policy libboost-dev
libboost-dev:
  Installed: 1.67.0.1+b1
  Candidate: 1.67.0.1+b1
  Version table:
 *** 1.67.0.1+b1 500
        500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
        100 /var/lib/dpkg/status

Below is the information about Raspberry Pi OS-

(whill) pi@raspberrypi:~/ros_catkin_ws $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux
pi@raspberrypi:~ $ gcc --version
gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pi@raspberrypi:~ $ g++ --version
g++ (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pi@raspberrypi:~ $ cmake --version
cmake version 3.13.4 
CMake suite maintained and supported by Kitware (kitware.com/cmake).

pi@raspberrypi:~ $ python --version
Python 2.7.16

pi@raspberrypi:~ $ python3 --version
Python 3.7.3

The rosinstall file can be seen online here. My aim is to use Python 3 in ROS Indigo (only publisher/subscriber for std_msgs) node on the Raspberry Pi board.

Asked by ravijoshi on 2020-01-12 05:33:59 UTC

Comments

I'm not saying it can't be solved, but as an observation: you're using an EOL version of ROS on an OS it was never released for, which uses versions of dependencies Indigo was never built with, trying to use a Python version Indigo was also not written for nor tested with.

My suggestion would be to take out some of these variation points, such as the Indigo requirement. Why do you need to use Indigo? Going to Melodic would make all of this much easier.

Asked by gvdhoorn on 2020-01-12 06:33:11 UTC

@gvdhoom: Thank you very much. I understand your concerns. The official Wiki page for installing ROS Indigo on the Raspberry Pi shows Raspbian Wheezy and Jessie OS version. I should use anyone from them. The next thing about the ROS version is that ROS Master is running on Indigo. Therefore I am sticking to Indigo. May I use other ROS in this situation? If yes, then I should choose ROS Kinetic since this is the latest one mentioned in the website.

Asked by ravijoshi on 2020-01-12 08:20:01 UTC

Answers

If you only need Python and standard messages, perhaps skipping the build entirely and using something like rospypi/simple may be a usable short-cut.

Asked by gvdhoorn on 2020-01-12 06:34:50 UTC

Comments

This looks really awesome. I should give it a try in a day or two. I will get back to you with the updates.

Asked by ravijoshi on 2020-01-12 08:30:24 UTC