# 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:** 9

<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:23 UTC](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351/9 "2019-04-02T09:23:58Z")

</div>

# Prepare the Aruco Board

This tutorial is referenced to the [ardupilot.org](http://ardupilot.org/dev/docs/ros-aruco-detection.html)

_ **Remark** _

> The example grid board assume you are flying a tiny drone. Otherwise, please create your own board by yourself.

### Check the IDs You Need

Open the file  
` ~/catkin_ws/src/aruco_gridboard/data/layout-my.yaml`

and you will see the following configuration:

```auto
ids:
 - 104
 - 111
 - 106
 - 105
 - 101
 - 110
 - 103
 - 102
 - 107
 - 109
 - 100
 - 108

```

These 12 IDs represent the aruco tags that will be recognized by the system. Edit them if you want to work on a customized board.

### Download the Board

The aruco board can be downloaded from [here](https://github.com/AlphenLai/aruco_gridboard/blob/master/aruco-gridboard_board.pdf) if you do not want to modify it.

### Make Your Own Board

Go to  
`~/catkin_ws/src/aruco_gridboard/src`

Compile the `create_board.cpp` by

```auto
g++ -ggdb create_board.cpp -o createboard `pkg-config --cflags --libs opencv`

```

Then, run `createboard` to generate the image file and content of yaml file.

```auto
./createboard

```

A message will list all neccessary input parameters.

| Parameters | |
| --- | --- |
| w | number of markers in x direction |
| h | number of markers in y direction |
| l | length of marker (in pixel) |
| s | space between markers (in pixel) |
| d | type of marker |
| f | ID of first marker (not available if you are not using my fork) |

Example input:

```auto
./create_board_wID board.jpg -w=10 -h=6 -l=700 -s=140 -d=16 -f=100

```

An image `board.jpg` will be created. Copy the ouput from the terminal and create a yaml file. A yaml file `layout_<markers in x direction>x<markers in y direction>_<markerLength>.yaml` will be automatically create if my fork was used.

Put the new yaml file to `~/catkin_ws/src/aruco_gridboard/data`  
Open `detection_rpicam.launch` and change the parameter

```auto
<param name="board_path" value="$(find aruco_gridboard)/data/layout-my.yaml" />

```

to your new yaml file.

Print your image.

_ **Remark** _

> The size of your grid board determine the range of your aircraft. As mentioned before, the grid board act as mock GPS system. If the board is too small, it will easily lose its sight on markers. It is recommended to create the markers big enough for your aircraft too see at its altitude. At least 4 markers should be visible by the aircraft.

* * *

# Camera Calibration

This tutorial is referenced to the [ROS.org](http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration)

### Prepare the checkerboard

Download the checkerboard [here](http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration?action=AttachFile&do=view&target=check-108.pdf)

The checkerboard is already with known dimension, which are 108mm squares. To print it on a A4 size paper, open the printing option dialog before printing and adjust the percentage size. I diminished the checkerboard to 20% of its original size, so the squares became 21.6mm.

### Calibration

**Make sure raspicam\_node has been installed in Raspberry Pi**

launch the ROS node and enable raw image

```auto
roslaunch raspicam_node camerav2_1280x960_10fps.launch enable_raw:=true

```

Run the Calibration Program

```auto
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0216 image:=/raspicam_node/image camera:=/raspicam_node

```

or

```auto
rosrun camera_calibration cameracalibrator.py --size 8x6 --square <square size> image:=/raspicam_node/image camera:=/raspicam_node

```

if you have a customized checkerboard

​ **Remark**

​ if camera\_calibration is not found, run:  
​ ` ​	sudo apt-get install ros-kinetic-image-pipelline ​	`  
​ you will need to remake the raspicam\_node after running the command.

A calibration window which highlight the checkerboard will pop up. Rotate, tite, and move the checkerboard slowly until the `X`, `Y`, and `Size` bar are filled up. When `Calibration` button lights, press it. The window will freeze but it is working. Wait for it patiently.

Something like this will be shown in the terminal:

```auto
D = [-0.33758562758914146, 0.11161239414304096, -0.00021819272592442094, -3.029195446330518e-05]
K = [430.21554970319971, 0.0, 306.6913434743704, 0.0, 430.53169252696676, 227.22480030078816, 0.0, 0.0, 1.0]
R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
# oST version 5.0 parameters

[image]

width
640

height
480

[narrow_stereo/left]

camera matrix
430.215550 0.000000 306.691343
0.000000 430.531693 227.224800
0.000000 0.000000 1.000000

distortion
-0.337586 0.111612 -0.000218 -0.000030 0.0000

rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000

projection
1.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000

```

Switch back to the calibration window and click `commit` to save the result.

​ **Remark**

​ If `Segmentation fault` is shown after commit, check if this file exist:

```auto
	~/.ros/camera_info/camerav2_1280x960.yam

```

ROS need to be re-launched to apply the calibration data.

### Troubleshooting

If `package not found` is shown, run:

```auto
sudo apt-get install ros-kinetic-rqt-reconfigure

```

If `found no plugin matching` is shown, run:

```auto
rqt --force-discover

```

and select the reconfigure in the pop up window

---

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