How to install ROS on a Turtle Rover - Tutorial

Make sure you have dirmngr installed (it’s necessary for downloading public keys from the HKP server)
$ sudo apt install dirmngr

Add ROS repositories and download GPG keys
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

Update package list
$ sudo apt update

Install prerequisites
$ sudo apt install python-rosdep python-rosinstall-generator python-wstool python-rosinstall python-catkin-tools python-psutil build-essential cmake

Initialize rosdep and update its package list
$ sudo rosdep init
$ rosdep update

Create a directory to store our catkin workspace
$ mkdir -p ~/ros_catkin_ws
$ cd ~/ros_catkin_ws

Use rosinstall_generator tool for creating a rosinstall file. This file will contain a list of ROS packages alongside their sources
$ rosinstall_generator ros_comm --rosdistro kinetic --deps --wet-only --tar > kinetic-ros_comm-wet.rosinstall
ros_comm contains basic ROS communication tools. The above command will include this package and all its recursive dependencies

Download packages to source directory using wstool
$ wstool init src kinetic-ros_comm-wet.rosinstall

Install system dependencies of downloaded packages with the rosdep tool
$ rosdep install -y --from-paths src --ignore-src --rosdistro kinetic -r --os=debian:stretch

Initialize and configure catkin workspace
$ catkin init
$ catkin config --install -i /opt/ros/kinetic -j 2
Configuration shown above says that the workspace is going to be installed to the /opt/ros/kinetic directory and that up to 2 parallel jobs can be running

NOTE: In this tutorial we use catkin commands from catkin-tools. If you want instead to use the catkin_make command, you can follow this tutorial:
http://wiki.ros.org/ROSberryPi/Installing%20ROS%20Kinetic%20on%20the%20Raspberry%20Pi#Building_the_catkin_Workspace

Build and install the workspace
$ sudo catkin build

CAUTION: Raspberry Pi has limited resources and TurtleOS doesn’t have a swap partition. This fact can lead to the device becoming unresponsive over time, because of a memory exhaustion. If this results in the compilation being terminated, you can try limiting the jobs running based on the memory usage
$ sudo catkin build --mem-limit 50%
The next job won’t be started as long as the memory usage is above 50%
Also remember to have a decent power supply (a 5V/2.5A charger would do fine)

That’s it! Our workspace is installed in the /opt/ros/kinetic directory. If you want to access all the installed tools and packages, use this command:
$ source /opt/ros/kinetic/setup.bash

If you want the command to be executed at every start of the terminal session, simply add it to the .bashrc file
$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

Hi guys,
just wanted to note that the same tutorial (and more) is available in the docs:
https://docs.turtlerover.com/manuals/install-ros-on-turtle-rover

Hi all,
I had previously been using TurtleOS-1.2.1-ROS-20190213.img and working with tr_webui. Since the interface is now tr_bringup I am currently trying to get that working but am having trouble getting that up on the old build. My current plan is build the OS from the ground up. I got ROS working on this new build but the bridge is not communicating with the Turtle Hat. Please take a look at my process and let me know if I missed something. I don’t have tcs installed so I thought perhaps there is some driver or module that is required for ROS to see the Turtle Hat. If that is the case perhaps this is an easy fix.

Build process 7/16/19

My goal here was to build tr_ros using the scripts available on TurtleRover github repository. I originally mounted the image and built the os that way but the image would not work (4 raspberries))

** Setup Raspbian light (stretch) **

  • Downloaded 4-19 stretch
  • I’m working from a Mac and used dd to create the disk
  • bootup operating system and log in
  • expand operating system
  • modify wpa_supplicant
  • enable ssh
  • reboot
  • log back in to setup ROS

** Setup ROS **

SCRIPT 1:

apt-get install dirmngr
        
 echo "deb http://packages.ros.org/ros/ubuntu stretch main" > /etc/apt/sources.list.d/ros-latest.list
 apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key  C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
        
 apt update
 apt -y upgrade 
        
 apt install -y python-rosdep python-rosinstall-generator python-wstool python-pip  

SCRIPT 2:

 PACKAGES=`cat packages`



 mkdir -p root/ros_ws
 cd root/ros_ws

 rosinstall_generator $PACKAGES --rosdistro kinetic --deps --wet-only --tar > turtle-  kinetic.rosinstall
 wstool init src
 wstool merge turtle-kinet

 wstool update -t src

SCRIPT 3:

 rosdep init
 rosdep update

 cd root/ros_ws
 rosdep install -y --from-paths src --ignore-src --rosdistro kinetic -r --os=debian:stretch
 apt install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev # gscam    dependencies

SCRIPT 4:

 cd root/ros_ws
 ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/kinetic -j1 

(be sure to modify number of cores to 1 , -j1, to avoid compiler errors in catkin_make_isolated)

From here I followed the Intall Turtle Rover ROS Package and Run Turtle Rover ROS :
https://docs.turtlerover.com/ros-tutorials/install-turtle-rover-ros-package

There is no communication with Turtle Hat

(As a sanity check I put in my current working Turtle ROS build from the image supplied here on the google Drive (I think) The image is TurtleOS-1.2.1-ROS-20190213.img This worked, so there isn’t anything wrong with the PI hat. I compared src/tr_hat_bridge between the two systems and they match.

There is no communication with Turtle Hat

Can you paste the output of tr_hat_bridge?

I get the following, which looks like it connects ok:

[INFO] [1563452254.468864]: Connected to serial device /dev/ttyAMA0

Then when I run rostopic echo /batteryI get no response. Also tr_teleop does not run the motors. No errors are given.

the Turtle Hat firmware is 1.3.3

This looks like it connected successfully. Maybe the problem lies in ROS communication. Please paste the output of roswtf command

Thanks for the quick reply! Here’s that output:

No package or stack in context

Static checks summary:

No errors or warnings

Beginning tests of your ROS graph. These may take awhile…
analyzing graph…
… done analyzing graph
running graph rules…
… done running graph rules

Online checks summary:

Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:

  • /tr_hat_bridge:
    • /servo3/angle
    • /tr_hat_bridge/motors
    • /servo2/angle
    • /servo1/angle

Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr

Running roswtf again produced a different output:

No package or stack in context
================================================================================
Static checks summary:

No errors or warnings
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 2 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:
 * /tr_hat_bridge:
   * /servo3/angle
   * /tr_hat_bridge/motors
   * /servo2/angle
   * /servo1/angle

WARNING The following nodes are unexpectedly connected:
 * unknown (http://mikey:37337/)->/rosout (/rosout)

Running roswtf again and got a bit of a different output:

No package or stack in context
================================================================================
Static checks summary:

No errors or warnings
================================================================================
Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 2 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:
 * /tr_hat_bridge:
   * /servo3/angle
   * /tr_hat_bridge/motors
   * /servo2/angle
   * /servo1/angle

WARNING The following nodes are unexpectedly connected:
 * unknown (http://mikey:37337/)->/rosout (/rosout)

And how did you check if there is communication with Turtle Hat?

I use rostopic echo /battery to check communications. If I get no response after a few minutes I assume its not going to happen. If perhaps the Hat is getting my request but I’m not seeing the info displayed I use tr_teleop_key to see if the forward command will turn the wheels. With my new build neither of those work.

Do you use rostopic echo /battery directly on Raspberry Pi or on your computer?
Please also paste the output of:

env | grep ROS

I ssh into the Raspberry Pi on the rover to run ROS.

Here are those paths:

        ROS_ETC_DIR=/opt/ros/kinetic/etc/ros
        ROS_ROOT=/opt/ros/kinetic/share/ros
        ROS_MASTER_URI=http://localhost:11311
        ROS_VERSION=1
        ROS_PACKAGE_PATH=/home/pi/turtle_ws/src/tr_ros/tr:/home/pi/turtle_ws/src/tr_ros/tr_bringup:/home/pi/turtle_ws/src/tr_ros/tr_control:/home/pi/turtle_ws/src/tr_ros/tr_hat_bridge:/home/pi/turtle_ws/src/tr_ros/tr_teleop:/opt/ros/kinetic/share
        ROSLISP_PACKAGE_DIRECTORIES=/home/pi/turtle_ws/devel/share/common-lisp
        ROS_DISTRO=kinetic

I believe I isolated the problem, which is on the configuration of ttyAMA0 in the OS. I got communication with the Turtle Hat once using the a python script and using ttyS0. But I rebooted and haven’t been able to get it up again. To get this working I modified /boot/config.txt to match the working OS. Basically this was adding in

enable_uart=1
dtoverlay=pi3-disable-bt
disable_spash=1
gpu_mem=256

And I disabled hiciuart.service, rebooted and then ran this test script:

from time import sleep
import serial
import struct
from threading import Lock

#   dev = '/dev/ttyAMA0' # not working on new build, but works on provided Turtle ROS image
dev = '/dev/ttyS0' # works!



class SerialComm():
    def __init__(self, device, baudrate=115200, timeout=1.0):
        self.device = device
        self.baudrate = baudrate
        self.timeout = timeout
        self.serial = None
        self.lock = Lock()

    def process_command(self, data):
        if not self.serial:
            print('Serial communication no yet initialized')
            return None

        with self.lock:
            self.serial.flushInput()
            self.serial.write(data)
            print('writing')
            try:
                print('trying to readline')
                #while True:
                status = self.serial.readline()
                bat_read_loop(status)
            except serial.SerialException as e:
                print(e)
                return None
            else:
                return status

def bat_read_loop(status):
    if not status or not status.endswith("

“):
print(‘Could not get battery status’)
else:
battery_status = struct.unpack(”<f", status[:4])[0]
print(battery_status)

def connect(self):
    while self.serial is None:
        try:
            self.serial = serial.Serial(
                self.device,
                baudrate=self.baudrate,
                timeout=self.timeout
            )
            print('connected')
        except serial.SerialException as e:
            print('Waiting for serial device')


BATTERY_PREFIX = 0x31
POSTFIX = [0x0D, 0x0A]

def battery():
    command = bytearray()
    command.append(BATTERY_PREFIX)
    command.extend([0x00, 0x00, 0x00, 0x00])
    command.extend(POSTFIX)
    return command




comm = SerialComm(dev)
connect(comm)
comm.process_command(battery())

hopefully can get this figured out soon. perhaps my version of Raspian lite is missing something? I noticed that gpio library was not installed

So is it working after changing the boot config?

After disabling bluetooth, /dev/ttyAMA0 should point to the right device.
Could you also try using /dev/serial0 device? From what I read, it should point to the UART device regardless of Bluetooth configuration.

You don’t have to change the code to choose device. You can pass it through private parameter:

rosrun tr_hat_bridge tr_hat_bridge _device:=/dev/serial0

The GPIO python library (RPi.GPIO) should be installed and you should have permission to access gpio pins. For this, make sure your user is in gpio group. (Type groups to see the list). If it isn’t, type:

sudo adduser pi gpio

Thanks. I got it working by disabling bluetooth and using AMA0. The entire leo_ui works with this setup now . Camera runs very nicely.
As for the serial port on my install, I may have done something to these configurations during my setup so, in the name of getting nice procedure for building from the ground up, I’m going to rebuild the OS again and check the serial communications with AMA0 and serial0 settings.