<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Manan Gupta</title>
    <description>The latest articles on DEV Community by Manan Gupta (@mgupta28).</description>
    <link>https://dev.to/mgupta28</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F961796%2F459238ff-38a1-4aa2-90fa-4cf7868e7e00.png</url>
      <title>DEV Community: Manan Gupta</title>
      <link>https://dev.to/mgupta28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mgupta28"/>
    <language>en</language>
    <item>
      <title>How to install ROS on Brainy Pi</title>
      <dc:creator>Manan Gupta</dc:creator>
      <pubDate>Tue, 01 Nov 2022 08:39:11 +0000</pubDate>
      <link>https://dev.to/mgupta28/how-to-install-ros-on-brainy-pi-1ebc</link>
      <guid>https://dev.to/mgupta28/how-to-install-ros-on-brainy-pi-1ebc</guid>
      <description>&lt;p&gt;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’&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Brainy-Pi?
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
To know more about it head on to the official &lt;a href="https://brainypi.com"&gt;BrainyPi&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--49fJuEHm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjpqlewlgkmrtzeqyucg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--49fJuEHm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjpqlewlgkmrtzeqyucg.png" alt="Brainy-pi dev board" width="880" height="730"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is ROS?
&lt;/h2&gt;

&lt;p&gt;The Robot Operating System &lt;a href="https://www.ros.org/"&gt;(ROS)&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JfQnGWj7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7vqv3st6un4krmpwiei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JfQnGWj7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7vqv3st6un4krmpwiei.png" alt="ROS" width="436" height="115"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing ROS on Brainy-pi
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;
&lt;h3&gt;
  
  
  Flashing Brainy-pi with ubuntu
&lt;/h3&gt;

&lt;p&gt;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). &lt;/p&gt;

&lt;p&gt;To add Ubuntu to the download options follow these steps&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Configure brainypi-recovery to install Ubuntu
&lt;/h4&gt;

&lt;p&gt;We need to create a file at location /boot/settings/os-sources.list and change the source variable in the file to Ubuntu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /boot/settings
&lt;span class="nb"&gt;sudo touch&lt;/span&gt; /boot/settings/os-sources.list
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt; | sudo tee /boot/settings/os-sources.list
SOURCE_URL="http://releases.brainypi.com/ubuntu"
SOURCE_REPO="testing"
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now the brainypi-recovery is configured and it will install Ubuntu 18.04.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Enable Console on the Monitor, Ubuntu 18.04 does not have a GUI, so console needs to be enabled manually.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt; | 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
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now reboot to the Recovery OS.&lt;/p&gt;

&lt;p&gt;Now you should be able to install ubuntu 18.04 on brainy-pi.&lt;/p&gt;

&lt;p&gt;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)&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation of ROS
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Setup your source list
&lt;/h4&gt;

&lt;p&gt;Setup your pc/pi to accept software from packages.ros.org.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" &amp;gt; /etc/apt/sources.list.d/ros-latest.list'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setup your keys
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Curl needs to be installed if you haven't already&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;curl
curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-key add -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;

&lt;p&gt;Update your packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install ROS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;ros-melodic-desktop-full
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration Steps
&lt;/h3&gt;

&lt;p&gt;Now that you have ROS installed in your device, you need to configure it so that you can use it to the fullest.&lt;/p&gt;

&lt;p&gt;Adding environment variables: To Automatically add ROS environment variables to your bash session every time a new shell (terminal) is launched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"source /opt/ros/melodic/setup.bash"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
&lt;span class="nb"&gt;sudo &lt;/span&gt;rosdep init
rosdep update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installing additional packages
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;You may or may not need these packages but it's good to have them in case you ever need it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Catkin tools&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;ros-melodic-catkin python3-catkin-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;std_msgs package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;ros-melodic-std-msgs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Turtlesim&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;ros-melodic-ros-tutorials
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating the workspace
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Create the root workspace directory. You can name your directory anything but by ROS convention we will use catkin_ws as the name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/catkin_ws/src/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialise the workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;catkin_ws
catkin init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build the workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;catkin_make
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to make your installation detectable in ROS, we have to source the workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/catkin_ws/devel/setup.bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The setup.bash needs to be sourced everytime. So to avoid that we will simply add this command to your bashrc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/catkin_ws/devel/setup.bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: make sure to add this line at the end of your bashrc file.&lt;br&gt;
Now simply save(ctrl+o) and exit(ctrl+x)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that your installation is done and your workspace has been successfully created, you can create packages, scripts etc according to your use.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a ROS package
&lt;/h3&gt;

&lt;p&gt;Software in ROS is organized in packages. A package might contain ROS nodes, a ROS- independent library, a dataset, conﬁguration ﬁles, 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.&lt;/p&gt;

&lt;p&gt;To create a ROS package you first nee to  navigate to the source space directory of the catkin workspace you’ve created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/catkin_ws/src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, use the catkin_create_pkg script to create a new package called pkg_ros_basics which depends on std_msgs, roscpp, and rospy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;catkin_create_pkg pkg_ros_basics std_msgs rospy roscpp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you need to build the packages in the catkin workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/catkin_ws
catkin_make
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Inside the package, there are src folder, package.xml , CMakeLists.txt , and the include folders.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Creating a ROS node and running a basic script
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Navigate to pkg_ros_basics&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/catkin_ws/src/pkg_ros_basics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a scripts folder for your Python scripts and navigate into the folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;scripts
&lt;span class="nb"&gt;cd &lt;/span&gt;scripts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a Python script called node_hello_ros.py .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;node_hello_ros.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the script in any text-editor and start editing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gedit node_hello_ros.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;First line of all your Python ROS scripts should be the following shebang, i.e.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env python3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now write a ROS Node to print Hello World! on the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env python&lt;/span&gt;
import rospy
def main&lt;span class="o"&gt;()&lt;/span&gt;:
&lt;span class="c"&gt;#Initialize the new node&lt;/span&gt;
rospy.init_node&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'node_hello_ros'&lt;/span&gt;, &lt;span class="nv"&gt;anonymous&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;True&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;#  Print info on console.&lt;/span&gt;
rospy.loginfo&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;__name__ &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'__main__'&lt;/span&gt;:

    try:
        main&lt;span class="o"&gt;()&lt;/span&gt;
    except rospy.ROSInterruptException:
        pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;save the script and exit the gedit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Make your node executable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; +x node_hello_ros.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to run your node&lt;/p&gt;

&lt;p&gt;Open the terminal and run ROS master&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;roscore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the roscore is running open a new terminal and run the main node&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rosrun pkg_ros_basics node_hello_ros.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; This command will work only if you have sourced setup.bash of your catkin workspace either manually or using .bashrc .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Congratulations. Now your brainy-pi has ROS installed in it. Now you can use it in any way you like.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ros</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
