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

<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:** [3 April 2019 07:23 UTC](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351/12 "2019-04-03T07:23:59Z")

</div>

# Run all Components

### Correct Some Codes Before First Run

**If you cloned the simple build, no need to edit the file**

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

Change the line

```auto
<param name="camera_info_url" value="package://raspicam_node/camera_info/camerav2_640x480.yaml"/>

```

to

```auto
<param name="camera_info_url" value="package://raspicam_node/camera_info/camerav2_1280x960.yaml"/>

```

This is because the camera was calibrated with resolution of 1280x960.

### Start all ROS Nodes

Connect the aircraft to ground station (eg: Mission Planner) on your remote computer.

Switch back to the Raspberry Pi. **Use SSH to login to the Raspberry Pi in every terminal if you are not testing on ground.**

Launch raspberry pi camera node module:

```auto
roslaunch aruco_gridboard detection_rpicam.launch

```

Launch mavros module:

```auto
sudo chmod 666 <tty port>
roslaunch mavros apm.launch

```

OR

```auto
sudo chmod 666 <tty port>
roslaunch mavros apm.launch fcu_url:=<tty port>:<baud rate>

```

if you did not set default communication port.

Wait for the EK2 ready, until `Request for home position` shows up. Open a new terminal, run:

```auto
rosservice call /mavros/set_stream_rate 0 10 1
rosrun aruco_gridboard set_origin.py

```

to set data rate and origin point of your drone. After the python script start, the aircraft should be located in somewhere in Italy.

For the **first time** or if you want to **configure the camera** , open a new terminal and run:

```auto
rosrun rqt_reconfigure rqt_reconfigure

```

A window will show up and camera parameters can be modified here. For example, select these 2 checkboxes as show below if you mounted the camera upside down.

 ![rqt_reconfigure](https://discuss.cubepilot.org/uploads/default/original/1X/db94f5a2fb3ab7ddeb5c480784cf20a1d0d54cfb.png)

Open a new terminal, run:

```auto
rosrun rviz rviz -d catkin_ws/src/aruco_gridboard/data/aruco_grid.rviz

```

The rviz should be opened and two 3-axis pose should be at the middle of the screen. They represent the `/local_position/pose` and `vision_position/pose` topics, which are the position relative to the aruco board.

Go to the left top corner and find the `image` tag. Change the topic to `/image/raw`. The real time image from camera will be shown in the bottom-left corner.

You will see that pose of `vision_position/pose` change according to the angle of aruco board observed by camera. Pose of `vision_position/pose` corresponds to the EKF measurement on the Cube. Because of the EKF, `vision_position/pose` will not change immediately but slowly move to `vision_position/pose`.

There will be a small delay between the actual movement and pose. The delay can be reduced by increasing the stream rate but please consider the processing power of Raspberry Pi.

The `vision_position/pose` may not be a flat standing even if the camera is flat. The problem may be located in image processing part. It is still functional anyway.

* * *

# Load Robot Model to RVIZ

If you want to learn more about URDF model, please visit [ROS.org](http://wiki.ros.org/urdf/Tutorials)

### Install URDF\_tutorial Package

Open a terminal and run:

```auto
sudo apt install ros-kinetic-urdf-tutorial

```

### Test if Successfully Installed

Go to the package location

```auto
roscd urdf_tutorial

```

Run the default URDF

```auto
roslaunch urdf_tutorial display.launch model:=urdf/01-myfirst.urdf

```

You should be able to see a red cylinder at the middle of RVIZ.

### Add Necessary Files

**If you cloned the simple build, skip to next session.**

Go to [my github](https://github.com/AlphenLai/aruco_gridboard) and clone the following files/folders to the corresponding folders in `~/catkin_ws/src/aruco_gridboard/`

```auto
data/aruco_grid_model.rviz
launch/detection_rpicam_model.launch
meshes
script/pose_to_tf.py
urdf

```

### Prepare Robot Model

The robot models can be built in the urdf file or load a mesh file into urdf file. If you are using a Raspberry Pi, it probobly would not have enough processing power to load a mesh file.

You can read the urdf\_tutorial on [ROS.org](http://ROS.org) or look into `~/catkin_ws/src/aruco_gridboard/urdf/test.urdf` to learn how urdf works.

You may also download a mesh file, such as .STL, from other websites and load into your urdf file.

To do this, put your mesh file in `~/catkin_ws/src/aruco_gridboard/meshes`

Then, change the content of `~/catkin_ws/src/aruco_gridboard/urdf/aircraft.urdf` to:

```auto
<?xml version="1.0"?>
<robot name="aircraft">
  <link name="robot_link">
	<visual>
      <geometry>
		<mesh filename="file://$(arg meshDirectory)part1.STL"/>
      </geometry>
    </visual>
  </link>
</robot>

```

**which “part1.STL” is the file name of your mesh file**  
`~/catkin_ws/src/aruco_gridboard/urdf/aircraft.urdf` and `~/catkin_ws/src/aruco_gridboard/meshes/20_min_drone.STL` are drawn by me. You may use them as default.

##### Solidworks

If you used Solidworks to draw the STL file, put it in the `meshes` folder and run:

```auto
sed -i 's/^solid/robot/' *

```

before using it.

### Run Everything

Connect the aircraft to ground station (eg: Mission Planner) on your remote computer.

Switch back to the Raspberry Pi. **Use SSH to login to the Raspberry Pi in every terminal if you are not testing on ground**  
Open a new terminal, run:

```auto
roslaunch aruco_gridboard detection_rpicam_model.launch

```

Open a new terminal, run:

```auto
sudo chmod 666 <tty port>
~/catkin_ws$ roslaunch mavros apm.launch

```

OR

```auto
sudo chmod 666 <tty port>
~/catkin_ws$ roslaunch mavros apm.launch fcu_url:=<tty port>:<baud rate>

```

if you did not set default communication port.

Wait for the EK2 ready, until `Request for home position` shows up. Open a new terminal, run:

```auto
rosservice call /mavros/set_stream_rate 0 10 1
~/catkin_ws$ rosrun aruco_gridboard set_origin.py

```

After the python script start, the aircraft should be located in somewhere in Italy.

Convert the `/mavros/local_position/pose` to `tf` datatype

```auto
rosrun aruco_gridboard pose_to_tf.py

```

Open a new terminal, run:

```auto
rosrun rviz rviz -d catkin_ws/src/aruco_gridboard/data/aruco_grid_model.rviz

```

A robot model will be bound to the 3-axis pose of `/mavros/local_position/pose`

---

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