# Indoor Autonomous Flight with Cube, ROS and Aruco Board (Ongoing)

**URL:** <https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351>\
**Category:** Uncategorized\
**Created:** [1 April 2019 10:09 UTC](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351 "2019-04-01T10:09:19Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Alvin](https://discuss.cubepilot.org/user_avatar/discuss.cubepilot.org/alvin/32/1000_2.png) [@Alvin](https://discuss.cubepilot.org/u/Alvin)\
**Post date:** [2 April 2019 09:14 UTC](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351/8 "2019-04-02T09:14:41Z")

</div>

# Install Necessary Packages in ROS

### Install raspicam\_node

Detailed procedure can be found [here](https://github.com/UbiquityRobotics/raspicam_node)

##### Installation

Detailed procedure can be found [here](https://packages.ubiquityrobotics.com/)

Add source to apt lists

```auto
sudo sh -c 'echo "deb https://packages.ubiquityrobotics.com/ubuntu/ubiquity xenial main" > /etc/apt/sources.list.d/ubiquity-latest.list'

```

Add signing key to trusted list

```auto
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C3032ED8

```

Run

```auto
sudo apt-get update

```

##### Build `catkin_ws`

Detailed procedure can be found [here](http://wiki.ros.org/catkin#Installing_catkin/)  
Jump to next session if you have already installed `catkin_ws`

Install pre-built package

```auto
sudo apt-get install ros-kinetic-catkin

```

Source your environment

```auto
source /opt/ros/kinetic/setup.bash

```

Create a catkin workspace

```auto
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make

```

Source your workspace

```auto
nano ~/.bashrc

```

Add `source ~/catkin_ws/devel/setup.bash` at the bottom of file.  
OR  
Run `source devel/setup.bash` in terminal everytime before running any package in catkin\_ws.

##### Build from Source

Go to your catkin\_ws

```auto
cd ~/catkin_ws/src

```

Download the source for `raspicam_node`

```auto
git clone https://github.com/UbiquityRobotics/raspicam_node.git

```

Create recognizable file for ROS dependencies

```auto
sudo touch /etc/ros/rosdep/sources.list.d/30-ubiquity.list
sudo nano /etc/ros/rosdep/sources.list.d/30-ubiquity.list

```

Add the following line to the file

```auto
yaml https://raw.githubusercontent.com/UbiquityRobotics/rosdep/master/raspberry-pi.yaml

```

Run `rosdep update`

Install the ros dependencies

```auto
cd ~/catkin_ws
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y

```

Compile the code

```auto
catkin_make

```

##### Run the Node to Confirm Success Installation

Most of the camera in the current market shoud be Pi Camera v2

For a V2.x camera, run `roslaunch raspicam_node camerav2_1280x960.launch`

For a V1.x camera, run `roslaunch raspicam_node camerav1_1280x720.launch`

### Install OpenCV

Detailed procedure can be found [here](https://www.alatortsev.com/2018/09/05/installing-opencv-3-4-3-on-raspberry-pi-3-b/). You may check the time estimation for each procedure in the link.  
This part is tested workable on 3B and 3B+ only.

**Warning: Compiling OpenCV is a CPU-intensive task. Make sure your Raspberry Pi has radiators and a fan (or place a powerful external fan next to it) in order to avoid overheating. The Raspberry Pi would not die from overheating, but overheating will throttle its CPU performance, potentially increasing build time.**

**Raspberry Pi will stop responding for several times. Reboot the Pi to continue its work.**

**Make sure you have enough time to stick with the Raspberry Pi.**

Confirm OS is up-to-date

```auto
sudo apt-get update
sudo apt-get upgrade

```

Install useful utilities

```auto
sudo apt-get install screen
sudo apt-get install htop

```

Install dependencies

```auto
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran

```

Install Python 3

```auto
sudo apt-get install python3-dev

```

Install pip3

```auto
sudo apt-get install python3-pip

```

Get **OpenCV 3.2.0** source code

```auto
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.2.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
unzip opencv.zip
unzip opencv_contrib.zip

```

Install Numpy, Scipy

```auto
sudo pip3 install numpy scipy

```

Compile OpenCV

```auto
cd ~/opencv-3.2.0/
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
    -D BUILD_EXAMPLES=ON ..

```

Build OpenCV

**The Raspberry Pi will overheat if there is no proper cooling. Reboot the Pi and run the command again if it overheated. The progress will be keep after reboot.**

Use all 4 cores to build

```auto
make -j4

```

Once OpenCV builds successfully, continue the installation:

```auto
sudo make install
sudo ldconfig
sudo apt-get update

```

Reboot the Raspberry Pi after installation

```auto
sudo reboot

```

##### Confirm Success Installation

Open a terminal, type:

```auto
python3

```

Then run `import cv2` and `cv2. __version__ `. The version of OpenCV will be shown.

### Install aruco\_gridboard

Detailed procedure can be found [here](https://github.com/anbello/aruco_gridboard)

If OpenCV extra module failed to build, rebuild them with the following codes:

```auto
cd <opencv_build_directory>
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
make -j4

```

##### Rebuild `vision_opencv` from source

Clone `vision_opencv` in your `catkin_ws/scr` and rebuild everything

```auto
cd ~/catkin_ws/src
git clone https://github.com/ros-perception/vision_opencv.git
cd ..
catkin_make -DOpenCV_DIR=/path-to-build-opencv-3.2

```

If building failed, try

```auto
catkin_make -DOpenCV_DIR=/path-to-build-opencv-3.2 -DENABLE_PRECOMPILED_HEADERS=OFF

```

Install dependancies if any of them is missing during the build

```auto
sudo apt-get install ros-kinetic-cv-bridge
sudo apt-get install ros-kinetic-vision-opencv

```

##### Check `cv_bridge` version

Open a terminal and type:

```auto
cd ~/catkin_ws/devel/lib
ldd libcv_bridge.so | grep opencv

```

The following result should be shown:

```auto
libopencv_core.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_core.so.3.2 (0x00007f7acb240000)
libopencv_imgcodecs.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_imgcodecs.so.3.2 (0x00007f7acaffe000)
libopencv_imgproc.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_imgproc.so.3.2 (0x00007f7ac97ca000)

```

##### Clone aruco\_gridboard

I modify a lot of things start from here. If you want to know what have I done, following my instructions. If you just want it to work on your system, clone my fork for simplicity.

**Simple build:**

```auto
cd ~/catkin_ws/src
git clone https://github.com/AlphenLai/aruco_gridboard.git
cd ..
catkin_make
source devel/setup.bash

```

Then skip to the next session.

**Detailed build:**

Clone it into your catkin\_ws and build with catkin\_make

```auto
cd ~/catkin_ws/src
git clone https://github.com/jokla/aruco_gridboard.git
cd ..
catkin_make
source devel/setup.bash

```

The catkin\_make should failed at this point.

Go to `~/catkin_ws/src/aruco_gridboard/data/detector_params.yml` and `~/catkin_ws/src/aruco_gridboard/src/node.cpp`  
Open them with text editor and replace `cornerRefinementMethod` with `doCornerRefinement`

##### Confirm Success Installation

Add the new OpenCV to the path

```auto
cd ~/catkin_ws
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jokla/Software/opencv-3.2.0/build/lib/

```

Launch the detection node

```auto
roslaunch aruco_gridboard detection.launch

```

---

_[View the full topic](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351)._
