[Documentation] [TitleIndex] [WordIndex

You can use the official Aldebaran cross-toolchain to crosscompile your code locally. The method is different between the 1.14 and 2.1 toolchains as the toolchain organization has changed quite a bit. We suggest to use two different workspaces, one for cross compiling the ros libraries like roscpp or moveit, and one for your own packages, which will use the libraries from the other workspace. That way, you still have the option to not cross compile your packages and let them use your locally installed ros distribution. Note: It is not possible to cross compile single packages in a catkin workspace: https://github.com/ros/catkin/issues/484

Create workspace for roscpp

First we create the workspace for the cross compiled ros packages. In this case it is only roscpp and its dependencies:

rosinstall_generator roscpp --rosdistro indigo --deps --upstream > nao_ros_indigo.rosinstall
wstool init src nao_ros_indigo.rosinstall

In order to cross compile the roscpp workspace, you need to download the cross-toolchain (v1.14 or 2.1) for the architecture of your PC from https://community.aldebaran-robotics.com/resources/.

Now, roscpp depends on some third party software that is not in Aldebaran's toolchain. So the tricky part is to add these third party libraries to your toolchain.

Toolchain 1.14

export TOOLCHAIN1=the/path/of/your/untarred/1.14/toolchain

Download packages from the great robotpkg work and add them to the toolchain:

wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-1.14.5.1-i386/All/console-bridge-0.2.7.tgz
wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-1.14.5.1-i386/All/log4cxx-0.10.0~doc.tgz
wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-1.14.5.1-i386/All/lz4-121r1.tgz
tar -xvf console-bridge-0.2.7.tgz -C $TOOLCHAIN1/sysroot/usr/
tar -xvf log4cxx-0.10.0~doc.tgz -C $TOOLCHAIN1/sysroot/usr/
tar -xvf lz4-121r1.tgz -C $TOOLCHAIN1/sysroot/usr/

You also need to modify the CMake of those packages as the paths are different:

find $TOOLCHAIN1/sysroot/usr/share/ -type f -print0 | xargs -0 sed -i 's,/opt/openrobots/,'"$TOOLCHAIN1"'/sysroot/usr/,'

And one final thing to do: As apr is not part of the toolchain but log4cxx depends on it, you need to allow gcc to compile without it:

sed -i '$ d' $TOOLCHAIN1/cross-config.cmake
echo set\(CMAKE_CXX_FLAGS \"$\{CMAKE_CXX_FLAGS\} -DOE_CROSS_BUILD -Wl,--allow-shlib-undefined\" CACHE STRING \"\" FORCE\) >> $TOOLCHAIN1/cross-config.cmake

You can then safely compile:

src/catkin/bin/catkin_make_isolated --merge --cmake-args -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN1/cross-config.cmake

Toolchain 2.1

export TOOLCHAIN2=the/path/of/your/untarred/2.1/toolchain

This one is trickier as it is less standard.

wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-2.1.0.19-i386/All/console-bridge-0.2.7.tgz
wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-2.1.0.19-i386/All/log4cxx-0.10.0~doc.tgz
wget http://robotpkg.openrobots.org/packages/bsd/OpenNao-2.1.0.19-i386/All/lz4-121r1.tgz
tar -xvf console-bridge-0.2.7.tgz -C $TOOLCHAIN2/libnaoqi-sysroot/
tar -xvf log4cxx-0.10.0~doc.tgz -C $TOOLCHAIN2/libnaoqi-sysroot/
tar -xvf lz4-121r1.tgz -C $TOOLCHAIN2/libnaoqi-sysroot/

You also need to modify the CMake of those packages as the paths are different:

find $TOOLCHAIN2/libnaoqi-sysroot/share/ -type f -print0 | xargs -0 sed -i 's,/opt/openrobots/,'"$TOOLCHAIN2"'/libnaoqi-sysroot/,'

You need to add bzip2 to the toolchain:

cp -fr $TOOLCHAIN2/bzip2/* $TOOLCHAIN2/libnaoqi-sysroot/

Now, some cmake files are meant to be used by qiBuild so you need to override them

rm -fr $TOOLCHAIN2/libnaoqi-sysroot/share/cmake/boost*
rm -fr $TOOLCHAIN2/libnaoqi-sysroot/share/cmake/bzip2*
rm -fr $TOOLCHAIN2/libnaoqi-sysroot/share/cmake/opencv*
cp -fr /usr/share/cmake-2.8/Modules/ $TOOLCHAIN2/libnaoqi-sysroot/share/cmake/

And you need to have CMake look there:

sed -i 's,list(INSERT CMAKE_FIND_ROOT_PATH 0  "${_TC_DIR}"),list(INSERT CMAKE_FIND_ROOT_PATH 0  "${ALDE_CTC_CROSS}" "${ALDE_CTC_SYSROOT}" "${ALDE_CTC_ROOTDIR}/libnaoqi-sysroot"),' $TOOLCHAIN2/cross-config.cmake

And one final thing to do: As apr is not part of the toolchain but log4cxx depends on it, you need to allow gcc to compile without it:

sed -i '$ d' $TOOLCHAIN2/cross-config.cmake
echo set\(CMAKE_CXX_FLAGS \"$\{CMAKE_CXX_FLAGS\} -DOE_CROSS_BUILD -Wl,--allow-shlib-undefined\" CACHE STRING \"\" FORCE\) >> $TOOLCHAIN2/cross-config.cmake

You can then safely compile:

src/catkin/bin/catkin_make_isolated --merge --cmake-args -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN2/cross-config.cmake

To do for both

Once you compile everything, you still need to copy anything you've added to the toolchain to your robot so make sure you do:

cp $TOOLCHAIN1/sysroot/usr/lib/libconsole_bridge.so ./devel_isolated/lib/
cp $TOOLCHAIN1/sysroot/usr/lib/liblog4cxx.so* ./devel_isolated/lib/
cp $TOOLCHAIN1/sysroot/usr/lib/liblz4.so* ./devel_isolated/lib/

or

cp $TOOLCHAIN2/libnaoqi-sysroot/lib/libconsole_bridge.so ./devel_isolated/lib/
cp $TOOLCHAIN2/libnaoqi-sysroot/lib/liblog4cxx.so* ./devel_isolated/lib/
cp $TOOLCHAIN2/libnaoqi-sysroot/lib/liblz4.so* ./devel_isolated/lib/

Create workspace for your packages

Simply create your own workspace as you always do, but source this workspace after you sourced and compiled the roscpp workspace. That way, you ensure that the cross-compiled roscpp package overlays the roscpp version of your locally installed ROS distribution. If you don't overlay the installed roscpp versions, your own packages will link against these and not against the cross-compiled ones. As a result, your packages wouldn't work on the NAOs architecture.

Copy your binaries to your NAO

It should be clear, how you copy files to your NAO, but keep in mind, that if you copy the devel_isolated folder completely, the paths in the setup.sh file are not set right for your NAO. One possibility to avoid that is to set the -DCMAKE_INSTALL_PREFIX="to what ever it is on your robot".


2024-11-16 14:47