|
| 1 | +# Cross-compile and run a ROS application |
| 2 | + |
| 3 | +This document describes how to cross-compile and setup the environment to run a CORC app with ROS support. It assumes that you have a deployment target and a host machine. |
| 4 | + |
| 5 | +It assumes that you have ROS installed on both the host and target machines. For the target, the debian/ubuntu package `ros-base-dev` can be used. |
| 6 | + |
| 7 | +## ROS environment setup |
| 8 | +In order to run on both host and target, ROS should be configured. We assume that roscore will run on the host machine. |
| 9 | +On the host: |
| 10 | +```bash |
| 11 | + $ export ROS_MASTER_UI=http://[host_ip]:11311 |
| 12 | + $ export ROS_HOSTNAME=[host_hostname] |
| 13 | + $ export ROS_IP=[host_ip] |
| 14 | +``` |
| 15 | +On the target: |
| 16 | +```bash |
| 17 | + $ export ROS_MASTER_UI=http://[host_ip]:11311 |
| 18 | + $ export ROS_HOSTNAME=[target_hostname] |
| 19 | + $ export ROS_IP=[target_ip] |
| 20 | +``` |
| 21 | +>These can be added to the .bashrc of the host and target respectivelly to be automatically setup. |
| 22 | +
|
| 23 | +>If the hostnames are not defined, edit the /etc/hosts files (see ROS [documentation](http://wiki.ros.org/ROS/Tutorials/MultipleRemoteMachines) or this [example](https://github.com/mktk1117/six_wheel_robot/wiki/Communication-between-Raspberry-Pi-and-PC-\(ROS\)) for more details). |
| 24 | +
|
| 25 | + |
| 26 | +## Cross-compilation |
| 27 | +In order to cross-compile CORC with ROS support from the host machine, you first need to create a sysroot: a copy of the basic filesystem of the target. To do so, create a folder named `corc-target-sysroot`. Using scp or sftp, copy the following folders from the target to this folder: |
| 28 | +```bash |
| 29 | + /usr/ |
| 30 | + /lib/ |
| 31 | +``` |
| 32 | +>It is recommended to do this on a minimal system to reduce the size of these folders. Typically graphical packages (xserver etc...) which may be installed by default on the BB distribution can be uninstall before. |
| 33 | +
|
| 34 | +Once the files are copied, in a terminal, set the directory of this folder: |
| 35 | +```bash |
| 36 | + $ export CORC_CMAKE_SYSROOT=/path/to/my/folder/corc-target-sysroot |
| 37 | +``` |
| 38 | + |
| 39 | +Edit the `CMakeFileLists.txt` to select the app to build and ensure that the line `set(USE_ROS ON)` is NOT commented and set to ON. |
| 40 | + |
| 41 | +Cross-compile by passing the sysroot path argument to cmake (and the toolchain argument). In the root CANOpenRobotController: |
| 42 | +```bash |
| 43 | + $ rm -r build && mkdir build && cd build/ && cmake -DCMAKE_SYSROOT=/path/to/my/folder/corc-target-sysroot -DCMAKE_TOOLCHAIN_FILE=../armhf.cmake .. |
| 44 | + $ make -j8 |
| 45 | +``` |
| 46 | +Voila ! |
| 47 | + |
| 48 | +## Run the app |
| 49 | +On the host machine, start ROS: |
| 50 | +```bash |
| 51 | + $ roscore |
| 52 | +``` |
| 53 | +In a second terminal, start rqt to visualise the active ROS graph: |
| 54 | +```bash |
| 55 | + $ rqt |
| 56 | +``` |
| 57 | +Plugins->Introspection->Node Graph. |
| 58 | + |
| 59 | +Once copied on the target, the APP can then be run normally, simply adding an extra command line parameter to specify the address of the master node: |
| 60 | +```bash |
| 61 | + $ sudo X2DemoMachineApp __master:=$ROS_MASTER_URI |
| 62 | +``` |
| 63 | + |
| 64 | +You should now see in rqt the nodes corresponding to the CORC app. |
0 commit comments