DEV Community

Cover image for How to install ROS on Brainy Pi
Manan Gupta
Manan Gupta

Posted on

How to install ROS on Brainy Pi

This blog is mainly going to focus on answering your questions like ‘What is Brainy-Pi’, ‘What is ROS’ and ‘How to install ROS on Brainy-Pi’

What is Brainy-Pi?

Brainy-pi is a single chip computer inspired by Raspberry-pi made by IoTIoT, an Indian startup. The brainy-pi is currently(when this blog was written) in the development stage. Its motive is to provide an made-in-India alternative version of raspberry pi.
To know more about it head on to the official BrainyPi website.

Brainy-pi dev board

What is ROS?

The Robot Operating System (ROS) is an open-source framework that helps researchers and developers build and reuse code between robotics applications. ROS is also a global open-source community of engineers, developers and hobbyists who contribute to making robots better, more accessible and available to everyone.

ROS

Installing ROS on Brainy-pi

Now to answer the big question; ‘is brainy-pi even compatible with ROS?’, The answer to that question is yes and its installation is as easy as installing ROS on any other device.

Flashing Brainy-pi with ubuntu

To install ROS on your brainy pi you would first need to flash an image of Ubuntu in it. To flash the image first plug in your mouse and keyboard to the brainy-pi and connect the HDMI cable to a screen and power it on using a USB type-C cable. By default the brainy pi will boot into the recovery OS for the first time where you can select the OS you want to install(Ubuntu is not set as one of the default OS for brainy pi but do not worry).

To add Ubuntu to the download options follow these steps

Step 1: Configure brainypi-recovery to install Ubuntu

We need to create a file at location /boot/settings/os-sources.list and change the source variable in the file to Ubuntu.

sudo mkdir -p /boot/settings
sudo touch /boot/settings/os-sources.list
cat <<EOF | sudo tee /boot/settings/os-sources.list
SOURCE_URL="http://releases.brainypi.com/ubuntu"
SOURCE_REPO="testing"
EOF
Enter fullscreen mode Exit fullscreen mode

Now the brainypi-recovery is configured and it will install Ubuntu 18.04.

Enable Console on the Monitor, Ubuntu 18.04 does not have a GUI, so console needs to be enabled manually.

cat <<EOF | sudo tee /boot/extlinux/extlinux.conf
label Ubuntu 18.04
    kernel /Image
    fdt /rk3399-brainypi.dtb
    append earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 console=tty0 init=/sbin/init
EOF
Enter fullscreen mode Exit fullscreen mode

Now reboot to the Recovery OS.

Now you should be able to install ubuntu 18.04 on brainy-pi.

Since we are using Ubuntu 18.04, we have to use the ROS version compatible with it, that is ROS melodic.(you can use any ubuntu version you like, just make sure to use the version of ROS compatible with it)

Installation of ROS

Setup your source list

Setup your pc/pi to accept software from packages.ros.org.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
Enter fullscreen mode Exit fullscreen mode

Setup your keys

Curl needs to be installed if you haven't already

sudo apt install curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode

Installation

Update your packages

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install ROS

sudo apt install ros-melodic-desktop-full
Enter fullscreen mode Exit fullscreen mode

Configuration Steps

Now that you have ROS installed in your device, you need to configure it so that you can use it to the fullest.

Adding environment variables: To Automatically add ROS environment variables to your bash session every time a new shell (terminal) is launched.

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Before you can use many ROS tools, you will need to initialise rosdep. rosdep enables you to easily install system dependencies for source you want to compile and is required to run some core components in ROS. If you have not yet installed rosdep.

sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
sudo rosdep init
rosdep update
Enter fullscreen mode Exit fullscreen mode

Installing additional packages

You may or may not need these packages but it's good to have them in case you ever need it.

Catkin tools

sudo apt-get install ros-melodic-catkin python3-catkin-tools
Enter fullscreen mode Exit fullscreen mode

std_msgs package

sudo apt install ros-melodic-std-msgs
Enter fullscreen mode Exit fullscreen mode

Turtlesim

sudo apt-get install ros-melodic-ros-tutorials
Enter fullscreen mode Exit fullscreen mode

Creating the workspace

Having a workspace directory for ROS is important because it allows for better distribution of packages, better cross compilation, better portability, plus all your work is stored under a single directory.

Create the root workspace directory. You can name your directory anything but by ROS convention we will use catkin_ws as the name

cd ~/
mkdir -p ~/catkin_ws/src/
Enter fullscreen mode Exit fullscreen mode

Initialise the workspace

cd catkin_ws
catkin init
Enter fullscreen mode Exit fullscreen mode

Build the workspace

catkin_make
Enter fullscreen mode Exit fullscreen mode

Now to make your installation detectable in ROS, we have to source the workspace

source ~/catkin_ws/devel/setup.bash
Enter fullscreen mode Exit fullscreen mode

The setup.bash needs to be sourced everytime. So to avoid that we will simply add this command to your bashrc

sudo nano ~/.bashrc
source ~/catkin_ws/devel/setup.bash
Enter fullscreen mode Exit fullscreen mode

Note: make sure to add this line at the end of your bashrc file.
Now simply save(ctrl+o) and exit(ctrl+x)

Now that your installation is done and your workspace has been successfully created, you can create packages, scripts etc according to your use.

Creating a ROS package

Software in ROS is organized in packages. A package might contain ROS nodes, a ROS- independent library, a dataset, configuration files, a third-party piece of software, or anything else that logically constitutes a useful module.The goal of these packages it to provide this useful functionality in an easy-to-consume manner so that software can be easily reused.

To create a ROS package you first nee to navigate to the source space directory of the catkin workspace you’ve created.

cd ~/catkin_ws/src
Enter fullscreen mode Exit fullscreen mode

Now, use the catkin_create_pkg script to create a new package called pkg_ros_basics which depends on std_msgs, roscpp, and rospy:

catkin_create_pkg pkg_ros_basics std_msgs rospy roscpp
Enter fullscreen mode Exit fullscreen mode

Now, you need to build the packages in the catkin workspace

cd ~/catkin_ws
catkin_make
Enter fullscreen mode Exit fullscreen mode

Inside the package, there are src folder, package.xml , CMakeLists.txt , and the include folders.

Creating a ROS node and running a basic script

In this section we will learn how to create a ROS Node inside pkg_ros_basics ROS Package which we created in the previous section.

Navigate to pkg_ros_basics

cd ~/catkin_ws/src/pkg_ros_basics
Enter fullscreen mode Exit fullscreen mode

Create a scripts folder for your Python scripts and navigate into the folder.

mkdir scripts
cd scripts
Enter fullscreen mode Exit fullscreen mode

Create a Python script called node_hello_ros.py .

touch node_hello_ros.py
Enter fullscreen mode Exit fullscreen mode

Open the script in any text-editor and start editing.

gedit node_hello_ros.py
Enter fullscreen mode Exit fullscreen mode

First line of all your Python ROS scripts should be the following shebang, i.e.

#!/usr/bin/env python3
Enter fullscreen mode Exit fullscreen mode

Now write a ROS Node to print Hello World! on the console.

#!/usr/bin/env python
import rospy
def main():
#Initialize the new node
rospy.init_node('node_hello_ros', anonymous=True)
#  Print info on console.
rospy.loginfo("Hello World!")

if __name__ == '__main__':

    try:
        main()
    except rospy.ROSInterruptException:
        pass
Enter fullscreen mode Exit fullscreen mode

save the script and exit the gedit.

Make your node executable

sudo chmod +x node_hello_ros.py
Enter fullscreen mode Exit fullscreen mode

Now to run your node

Open the terminal and run ROS master

roscore
Enter fullscreen mode Exit fullscreen mode

Once the roscore is running open a new terminal and run the main node

rosrun pkg_ros_basics node_hello_ros.py
Enter fullscreen mode Exit fullscreen mode

Note This command will work only if you have sourced setup.bash of your catkin workspace either manually or using .bashrc .

Congratulations. Now your brainy-pi has ROS installed in it. Now you can use it in any way you like.

Top comments (0)