# Cube Rover Demonstration

**URL:** <https://discuss.cubepilot.org/t/cube-rover-demonstration/8175>\
**Category:** Cube Autopilot\
**Created:** [14 January 2022 09:23 UTC](https://discuss.cubepilot.org/t/cube-rover-demonstration/8175 "2022-01-14T09:23:40Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [14 January 2022 09:23 UTC](https://discuss.cubepilot.org/t/cube-rover-demonstration/8175/1 "2022-01-14T09:23:40Z")

</div>

Hi. I’m just here to share some tips on building a rover with Cube and other common peripherals. Most of the instructions are written in Ardupilot wiki.

# Rover with Here2

 ![Screenshot 2022-01-07 153241](https://discuss.cubepilot.org/uploads/default/original/2X/4/4b9b6b6858c894040b3ebb0e9dea1d0e03ee37a2.jpeg)

 ![rover_here3](https://discuss.cubepilot.org/uploads/default/original/2X/3/3a6cbf734a65fe2eb5fc539e61c2316977195e2d.jpeg)

Cube: Black

GPS: Here3

Lidar: Rplidar A2

This build is quite straight forward. Setting up everything and it should work. The couplers on my rover were 3D printed and they loosen over time. Therefore it is not moving quite perfectly straight in the video.

Setup are exactly same as instruction in Ardupilot wiki

> **[Simple Object Avoidance — Copter documentation](https://ardupilot.org/copter/docs/common-simple-object-avoidance.html)**

> **[Object Avoidance with Bendy Ruler — Copter documentation](https://ardupilot.org/copter/docs/common-oa-bendyruler.html)**

[![](https://img.youtube.com/vi/WEGDZAG29nE/maxresdefault.jpg "Cube Ardupilot Rover Object Avoidance with RPLIDAR-A2 and Here3") ](https://www.youtube.com/watch?v=WEGDZAG29nE)

# Rover with Realsense T265

 ![image](https://discuss.cubepilot.org/uploads/default/original/2X/3/3f6f20bb3e2fe108ca1606e7f6352adeb30912d1.jpeg)

 ![rover_viso](https://discuss.cubepilot.org/uploads/default/original/2X/b/bf4a6fab4f4d02f4aa84c28a5c8e89fa835369f6.jpeg)

Cube: Black

Companion computer: Raspberry Pi (w. APSync) /Intel UP2 (w. Ubuntu 18)

Motion camera: Intel Realsense T265

Another build a rover with companion computer and vision positioning sensor

## Companion computer Setup

### Raspberry Pi connection

 ![cube_and_pi](https://discuss.cubepilot.org/uploads/default/original/1X/6211c1d4a0889ae46d4845a0c405620e63e90223.jpeg)

Flash [APSync](https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html#apsync) into the SD card. The T265 scripts should be already installed.

If you want to use raspbian, setup as mentioned [here](https://discuss.cubepilot.org/t/indoor-autonomous-flight-with-cube-ros-and-aruco-board-ongoing/351/2#:~:text=newer%20models%2C%20the-,Bluetooth,-module%20occupied%20UART)

If you use Ubuntu, follow the steps [here](https://discuss.ardupilot.org/t/easier-setup-for-intel-realsense-t265/53991/39)

### UP2 connection

 ![UP2_pinout](https://discuss.cubepilot.org/uploads/default/original/2X/e/e3f528fb6a09bfd4bf5adcc121d2dbe20f52fbc4.jpeg)

Connect the UP2 with telem port, according to its [pinout](https://github.com/up-board/up-community/wiki/Pinout_UP2).

Setup the UP2 system as mentioned in [their wiki](https://github.com/up-board/up-community/wiki/Software) (eg: [Ubuntu](https://github.com/up-board/up-community/wiki/Ubuntu)). You will need to install their kernal to enable the HAT.

I’m using ubuntu 18.

If you connect them as shown in the figure above, the Cube should appear in ttyS5.

### Software Installation and Parameter Setup

Setup the companion computer if you are not using APSync. If you use APSync, start from [Configure ArduPilot](https://ardupilot.org/copter/docs/common-vio-tracking-camera.html#configure-ardupilot).

I’m using EK3 with compass disabled.

#### Prerequisite

Install [mavproxy](https://ardupilot.org/mavproxy/) for ease on verifying connection to autopilot

Remove modemmanager so that it won’t conflict with serial communication

Install [mavlink router](https://github.com/mavlink-router/mavlink-router) to route more ports for potential usages

Follow the instructions in wiki to complete the remaining steps:

> **[Intel RealSense T265 — Copter documentation](https://ardupilot.org/copter/docs/common-vio-tracking-camera.html)**

#### Mavlink Router Setting

Create the config file in `/etc/mavlink-router/main.conf`

```auto
[General]
ReportStats=false
MavlinkDialect=auto
​
[UartEndpoint alfa]
Device = /dev/ttyS5
Baud = 921600
​
[UdpEndpoint bravo]
Mode = Normal
Address = 127.0.0.1
Port = 14460
​
[UdpEndpoint Charlie]
Mode = Normal
Address = 127.0.0.1
Port = 14470

```

##### Make autorun at boot

Create the bash script `mavlink_router.sh`

```auto
#!/bin/bash
mavlink-routerd

```

Create the service in `/etc/systemd/system/mavlink_router.service`

```auto
[Unit]
Description=Mavlink Router Service
After=multi-user.target
StartLimitIntervalSec=0
Conflicts=
​
[Service]
User={your username}
EnvironmentFile=
ExecStartPre=
ExecStart={path to mavlink_rounter.sh}
​
Restart=on-failure
RestartSec=1
​
[Install]
WantedBy=multi-user.target

```

Enable and start the service

```auto
systemctl start mavlink_router
systemctl enable mavlink_router

```

#### T265 with UDP port

We have routed port 14460 and 14470 from serial port. Now we can use them to connect to autopilot.

Base on the T265 script (serial) in [wiki](https://ardupilot.org/copter/docs/common-vio-tracking-camera.html#how-to-run), further modify it:

```auto
connection_string_default = 'udpin:127.0.0.1:14460'

```

```auto
conn = mavutil.mavlink_connection(
connection_string,
autoreconnect = True,
source_system = 255,
source_component = 93,
target_system = 1
)

```

##### Make autorun at boot

Same as [wiki](https://ardupilot.org/copter/docs/common-vio-tracking-camera.html#autorun-at-boot) but since we use udp routed my mavlink router, we want it to start after mavlink router service. In the first part of `t265.service`:

```auto
[Unit]
Description=Realsense T265 Service
After=multi-user.target mavlink_outer.service
StartLimitIntervalSec=0
Conflicts=

```

Don’t forget to start and enable the service.

In some system (or hardware, I don’t actually know which one to blame), the service don’t start until its desktop initialized. If you don’t have any monitor/HDMI output connected, the service will stay inactive forever. In that case, you will need a HDMI dummy plug.

### Connection Test

Now if you have gone through the steps, it should work. Verify this in Mission Planner as mentioned in wiki.

The port `14470` is a spare, you can connect it from companion computer via mavproxy to confirm the connection.

`mavproxy.py --master=udp:localhost:14470 --console --map --target-system=1 --target-component=0`

You can also use it for various applications such as ROS.

### Auto Mission Test

[![](https://img.youtube.com/vi/g2nEmzHbMz8/maxresdefault.jpg "Cube Ardupilot Rover with Realsense T265") ](https://www.youtube.com/watch?v=g2nEmzHbMz8)

---

<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:** [6 May 2022 08:41 UTC](https://discuss.cubepilot.org/t/cube-rover-demonstration/8175/2 "2022-05-06T08:41:39Z")

</div>

# SLAM Mapping with Cartographer

Following the build with T265 non GPS navigation rover, I added the 2D lidar on top of it.

 ![image](https://discuss.cubepilot.org/uploads/default/original/2X/b/b2781e91111229a73d7fa50ba975f980ec7e2236.png)

### Additional Hardware

Camera: Pi camera with Raspberry pi  
Lidar: RPLidar A2  
Internet connection for companion computer: 2.4GHz Wifi dongle

You may wonder why not put all wireless connection connecting under Herelink controller’s hotspot. The answer is simply because I don’t have the hardware to connect UP2 to 5GHz wifi.  
It is also possible to setup the ethernet so that the companion computer doesn’t need additional wireless connection.

### Setup

On companion computer (UP2 in my case), build the cartographer, ROS, and other necessary packages following the instruction in [Ardupilot wiki](https://ardupilot.org/dev/docs/ros-cartographer-slam.html)

If the [error](https://discuss.ardupilot.org/t/cartographer-slam-building-fail/84986) show up when trying to build it, try to build the packages with [cartographer wiki’s instruction](https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html)

You may also need to install abseil if any related error come out

> $ sudo apt-get install stow  
> $ sudo chmod +x ~/carto\_ws/src/cartographer/scripts/install\_abseil.sh  
> $ cd ~/carto\_ws/src/cartographer/scripts  
> $ ./install\_abseil.sh

To make a remote spectator or control on laptop, use ROS’s master/remote setup:  
In master’s `~/.bashrc`, put

> export ROS\_IP={self ip}  
> export ROS\_MASTER\_URI=[http://localhost:11311](http://localhost:11311)

In remote’s `~/.bashrc`, put

> export ROS\_IP={self ip}  
> export ROS\_MASTER\_URI=http://{master’s ip}:11311

### Run the SLAM

SSH into master machine

> ssh {username}@{master ip}

Then run the ros components in different terminals

> roscore

> roslaunch rplidar\_ros rplidar.launch

> roslaunch cartographer\_ros cartographer.launch

In remote/client machine

> roscore

> rviz -d ~/catkin\_ws/src/cartographer\_ros/cartographer\_ros/configuration\_files/demo\_2d.rviz

### Generate mapping file

Finally, when mapping is done, run the following lines to generate .pgm and .yaml files

> rosrun map\_server map\_saver [-f mapname]

You will get something like this:

 ![Screenshot from 2022-05-06 10-13-00](https://discuss.cubepilot.org/uploads/default/original/2X/3/35abc4c266c0bb3158828f45c8166736314a9bc5.png)

### Video Demo

[![](https://img.youtube.com/vi/UT0S_vSonk8/maxresdefault.jpg "Cube Ardupilot Rover Cartographer SLAM") ](https://www.youtube.com/watch?v=UT0S_vSonk8)

It was a little laggy at the corner, because there is surrounded by couple of big and tall metal shelves. The wifi hotspot signal from Herelink was not reaching, but the Herelink transmission itself are working fine.

I’m not able to test the build elsewhere. That’s because I need to stick to a network with 2.4GHz hotspot(for UP2), 5GHz hotspot(for Herelink controller), and under my control.

### Errors

If the follow error shows up:

> [ERROR] [1651567143.011534119]: Client [/rviz\_1651567140920139372] wants topic /submap\_list to have datatype/md5sum [cartographer\_ros\_msgs/SubmapList/6efe809c4a0e69266aa99b3bea531f2a], but our version has [cartographer\_ros\_msgs/SubmapList/73b1e412208f0787050395996f6143db]. Dropping connection.

in master’s rosrun cartographer’s terminal when client’s rviz launch. (the md5sum string maybe different, but the idea is them being mismatched over master and client)

You may try to:

1. check whether you have sourced `devel/setup.bash` in `~/bashrc.sh` or not. If you used `catkin_make_isolated --install --use-ninja`, the directory becomes `devel_isolated/setup.bash`

2. reinstall ros-{distro}-cartographer-rviz

3. rebuild cartographer\_ros

4. reset rviz to default

5. reinstall ROS

If the follow error shows up:

> [ERROR] [1651655459.598098736]: PluginlibFactory: The plugin for class ‘Submaps’ failed to load. Error: According to the loaded plugin descriptions the class Submaps with base class type rviz::Display does not exist. Declared types are rviz/Axes rviz/Camera rviz/DepthCloud rviz/Effort rviz/FluidPressure rviz/Grid rviz/GridCells rviz/Illuminance rviz/Image rviz/InteractiveMarkers rviz/LaserScan rviz/Map rviz/Marker rviz/MarkerArray rviz/Odometry rviz/Path rviz/PointCloud rviz/PointCloud2 rviz/PointStamped rviz/Polygon rviz/Pose rviz/PoseArray rviz/PoseWithCovariance rviz/Range rviz/RelativeHumidity rviz/RobotModel rviz/TF rviz/Temperature rviz/WrenchStamped

Source `devel/setup.bash` or `devel_isolated/setup.bash` like the 1st solution in last error.

Hope you enjoy my sharing.
