How To setup Raspberry Pi to identify two Arduino devices

The applications that run on Raspberry Pi can’t always identify the serial port that belongs to each Arduino board. If we don’t use an identifier for each board, the serial port may change every time we disconnect or connect the Arduino board to Raspberry Pi.

In this tutorial, I’ll show you how to configure Raspberry Pi to automatically identify two Arduino boards. The procedure can be extended to multiple boards, but in this tutorial, I’ve used two identical Arduino boards.

How To setup Raspberry Pi to identify two Arduino devices

How To setup Raspberry Pi to identify two Arduino devices

Below are the steps to identify each board separately, regardless of which USB port of the Pi is used.

Step 1: navigate to /etc/udev/rules.d/99-arduino.rules
Step 2: this command returns the two serial ports connected to the Arduino boards

ls /dev/ttyACM*
ls /dev/ttyACM* for two Arduino boards

ls /dev/ttyACM* for two Arduino boards

Step 3: after finding the KERNEL of the two Arduino boards, run for each board the command:

udevadm info -a -n /dev/ttyACM00 | less

Instead of ttyACM00, use the serial port of the Arduino board
Step 4: for each Arduino’s KERNEL, add a line to the file 99-arduino.rules

Setup Raspberry Pi

Step 5: refresh udev

sudo /etc/init.d/udev reload

Template for a Simple ROS Subscriber and Publisher in Python

A few days ago I started writing a series of tutorials that ease the work of beginners in ROS. The first tutorial was about a template for a publisher node, and the second tutorial was about a template for a subscriber node in ROS.

Today, I continue the series of tutorials with a template for a publisher and a subscriber node in Python. In addition, I’ll test it by writing and running a publisher and subscriber node.

Template for a Simple ROS Subscriber and Publisher in Python

Template for a Simple ROS Subscriber and Publisher in Python (image source)

Copy the template into a ‘. py’ file, delete the information that you don’t need and replace the text in capital letters.

#ROS Node Subscriber & Publisher template

#!/usr/bin/env python

#remove or add the library/libraries for ROS
import rospy, time, math, cv2, sys

#remove or add the message type
from std_msgs.msg import String, Float32, Image, LaserScan, Int32

varS=None

#define function/functions to provide the required functionality
def fnc_callback(msg):
    global varS
    varS==do_something(msg.data)

if __name__=='__main__':
    #Add here the name of the ROS. In ROS, names are unique named.
    rospy.init_node('NODE_NAME')
    #subscribe to a topic using rospy.Subscriber class
    sub=rospy.Subscriber('TOPIC_NAME', THE_TYPE_OF_THE_MESSAGE, fnc_callback)
    #publish messages to a topic using rospy.Publisher class
    pub=rospy.Publisher('TOPIC_NAME', THE_TYPE_OF_THE_MESSAGE, queue_size=1)
    rate=rospy.Rate(10)

    while not rospy.is_shutdown():
        if varS<= var2:
            varP=something()
        else:
            varP=something()

        pub.publish(varP)
        rate.sleep()
   

I used the above template to write a ROS node that will display the random numbers received from another node, then I add some conditional statements, and finally I publish the results.

#!/usr/bin/env python

import rospy

from std_msgs.msg import Int32

varS=None

def fnc_callback(msg):
    global varS
    varS=msg.data
   
if __name__=='__main__':
    rospy.init_node('NODE_SUB_AND_PUB')
   
    sub=rospy.Subscriber('rand_no', Int32, fnc_callback)
    pub=rospy.Publisher('sub_pub', Int32, queue_size=1)
    rate=rospy.Rate(10)

    while not rospy.is_shutdown():
        if varS<= 2500:
            varP=0
        else:
             varP=1
   
        pub.publish(varP)
        rate.sleep()

To run the above node, navigate to the .py file and make it executable. The command is:

chmod u+x my_python_file.py

After the file is executable, you can run the node.

Step 1: open a new Terminal and run the command:

roscore

Step 2: open a new Terminal and run the publisher node with the following command:

rosrun your_package your_ros_node_that_generates_random_number.py

Step 3: open a new Terminal and run the publisher and subscriber node with the following command:

rosrun your_package your_ros_node_for_publisher_and_subscriber.py

Robot Tractors to Work The Land

This article was last modified on 19 July 2017.

Some of the farmer’s responsibilities have already been taken over by the machines. The robot tractors capable of turning around, cultivating or maintaining the land are a common presence in the landscape.

The main objective of the manufacturers is to replace the manual labor for all types of farming activities. But I know, it is too early to talk about such intelligent machines. Until then, in this article, you will find the best robot tractors capable of autonomous operations in agriculture.

  • Greenbot – safety first

    Added on 19 July 2017

    Greenbot

    Greenbot

    Greenbot is an autonomous tractor that uses a diesel engine to generate power.

    Is guided by GPS and has software specially designed to be used by the operator for commands and data analysis.

    The tractor robot comes with a series of systems for detecting obstacles, animals, people, etc. In front, it has mounted a radar and a bumper bar with mobile parts to detect the impact. Additionally, in the bumper are installed other few sensors for detection.

  • Read more →

Template for a ROS Subscriber in Python

A few days ago I wrote a tutorial about a template for a Publisher node in Python. In the same tutorial, I used the template to write a ROS node to generate a random number.

Today, I continue the series of tutorials that ease the work of beginners in ROS, with a template for Subscriber in Python. In addition, in the article, you will find a template implementation with a ROS node that displays the data generated by the Publisher node from the previous tutorial.

Below you will find the template for a ROS Publisher node in Python. All you have to do is copy the text into a ‘. py’ file, delete the extra text and replace the text with capital letters.

Template for a ROS Publisher in Python

Template for a ROS Publisher in Python (image source)

#The ROS Node Subscriber template

#!/usr/bin/env python

#remove or add the library/libraries for ROS
import rospy, time, math, cv2, sys

#remove or add the message type
from std_msgs.msg import String, Float32, Image, LaserScan, Int32

#define function/functions to provide the required functionality
def name_callback(msg):
    make_something_here_with msg.data
    rospy.loginfo("I heard %s", msg.data)

if __name__=='__main__':
    #Add here the name of the ROS. In ROS, names are unique named.
    rospy.init_node('THE_NAME_OF_THE_NODE')
    #subscribe to a topic using rospy.Subscriber class
    sub=rospy.Subscriber('TOPIC_NAME', TOPIC_MESSAGE_TYPE, name_callback)
    rospy.spin()
 

I used the above template to write a ROS node that will display the random numbers sent by the node created to test the Publisher template.

#!/usr/bin/env python
import rospy

from std_msgs.msg import Int32
from random import randint


def random_callback(msg):
    rospy.loginfo("I heard %s", msg.data)

if __name__=='__main__':
    rospy.init_node('rand_subscriber')
   
    sub=rospy.Subscriber('rand_no', Int32, random_callback)
    rospy.spin()

To run the above node, navigate to the .py file and make it executable. The command is:

chmod u+x my_python_file.py

After the file is executable, you can run the node.

Step 1: open a new Terminal and run the command:

roscore

Step 2: open a new Terminal and run the Publisher node with the following command:

rosrun your_package your_ros_node_that_generates_random_number.py

Step 3: open a new Terminal and run the subscriber node with the following command:

rosrun your_package your_ros_node_for_subscriber.py

CORE2-ROS: A development board for autonomous robots

The Raspberry Pi boards, and especially Raspberry Pi 3, are very often used in robotics. The list of reasons is long and includes WiFi connection, GPIO, USB ports, a powerful processor, 1GB RAM, compatibility with a number of Linux distributions, documentation for almost anything you need, and a large community.

It’s hard to match the Raspberry Pi records, no matter which version of the board we’re talking about. The only option is to fill a niche where Pi is not useful enough.

The Husarion company from Poland (and an office in the US) has been launched a fundraising campaign on Crowd Supply to launch two development boards for Internet-connected robots. One of the boards is CORE2, and the second one is CORE2-ROS, an enhanced version of the CORE2.

In this article, I will focus on the advanced CORE2-ROS version. As described in the presentation of the board, this version is designed to be used in particular for the development of autonomous robots. That being said, I made a list of the most important features of the board.

left: CORE2; right: CORE2-ROS

left: CORE2; right: CORE2-ROS


Read more →

Template for a ROS Publisher in Python

I do not like to memorize definitions, methods, procedures, etc., but I like to find solutions to help me reach my final goal.

In ROS, the structure of a simple node is repeated almost every time. To write the Publisher nodes as easily as possible, I’ve made a template that you can modify as you needed.

The template below represents a ROS Publisher node written in Python. All you have to do is to copy the template into a ‘. py’ file, delete the extra text and replace the text in capital letters.

Template for a ROS Publisher in Python

Template for a ROS Publisher in Python (image source)

#The ROS Node Publisher template

#!usr/bin/env python

#remove or add the library/libraries for ROS
import rospy, time, math, random

#remove or add the message type
from std_msgs.msg import Int32, Float32, String
from basics.msg import TimerAction, TimerGoal, TimeResult
from time import sleep

#you can define functions to provide the required functionality
def body(arg):
    def_body_here
    return the_value

if __name__=='__main__':
    #add here the node name. In ROS, nodes are unique named.
    rospy.init_node('THE_NAME_OF_THE_NODE')

    #publish messages to a topic using rospy.Publisher class
    name_pub=rospy.Publisher('THE_NAME_OF_THE_TOPIC', THE_TYPE_OF_THE_MESSAGE, queue_size=1)

    #you can define functions to provide the required functionality
    if var1==var2:
        make_something()
        else:
            make_something()

    #set a publishing rate. Below is a publishing rate of 10 times/second
    rate=rospy.Rate(10)

    while not rospy.is_shutdown():
        #some calculation here
        if a1==a2:
            pub.publish(message1)
            else:
                pub.publish(message2)
rate.sleep()

I used the above template to make a ROS node that generates a random number between 0 and 5000.

#!/usr/bin/env python
import rospy

from std_msgs.msg import Int32
from random import randint

#a function to generate the random number
def generate_random_number():
    rnd= randint(0,5000)
    return rnd

if __name__=='__main__':
    rospy.init_node('random_number')
    pub=rospy.Publisher('rand_no', Int32, queue_size=10)
    rate= rospy.Rate(5)

    while not rospy.is_shutdown():
        rnd_gen=generate_random_number()
       
        if rnd_gen<=2500:
         rospy.loginfo("The number generated is lower than 2500: %s", rnd_gen)
         pub.publish(rnd_gen)
        else:
         rospy.loginfo("The number generated is higher than 2500: %s", rnd_gen)
         pub.publish(rnd_gen)

rate.sleep()

To run the above node, navigate to the .py file and make it executable. The command is:

chmod u+x my_python_file.py

After the file is executable, you can run the node.

Step 1: open a new Terminal and run the command:

roscore

Step 2: open a new Terminal and run the node with the following command:

rosrun your_package your_ros_node_file.py

Intel Euclid worth or not?

After reading more articles about Intel Euclid, I was surprised by the enthusiasm created around the product. LinuxGizmos, LiLiPuting, The Verge, Engadget, are just some of the online publications that have written about the new product from Intel, a product designed to build robots.

But to make sure there is no false enthusiasm, I did an analysis of the kit to see if is worth it or not to use it in robotics projects. The conclusion is below and it is worth reading to the end.

Intel Euclid

Intel Euclid

The first step was to make a list of the advantages and disadvantages of the Euclid kit.

Advantages:

  • it has WiFi, 3D sensor, and other sensors in a very small box
  • it runs Linux Ubuntu (not a surprise)
  • it runs ROS Kinetic
  • is Arduino compatible
  • Intel has launched tutorials to make the introduction for users
  • double processor power and four times more RAM than Raspberry Pi 3

Disadvantages:

  • few ports for accessories
  • it does not have GPIO pins to attach other sensors (other than those already integrated)
  • inside, the GPS module is useless
  • the product is not modular. You use it as it is. If you want to replace a hardware component, you need an expert or a service

Read more →

Installing and Setting Up Arduino with ROS Kinetic (Raspberry Pi 3)

This guide will walk you through how to install and setting up an Arduino board to work with Raspberry Pi 3 having in common ROS Kinetic.

To walk through this guide, you must have a Raspberry Pi 3 with ROS Kinetic installed, an Arduino UNO board connected via the USB port to Pi, and some Linux knowledge.

Arduino is an open-source development tool very easy to use both as hardware and software. This development board simplifies the robot construction process and is therefore used together with Raspberry Pi and ROS to control sensors, motors or any other component that can be controlled with a microcontroller.

The Arduino microcontroller can only run one ROS node at a time.

Read now the best books to learn ROS:

Install the Arduino IDE

Arduino is connected to Raspberry Pi 3 through the USB port. To program Arduino, you need to install the Arduino IDE on the Pi.

To install the Arduino IDE on the Ubuntu Mate operating system, use the following commands in the Linux terminal.

sudo apt-get update
sudo apt-get install arduino arduino-core

Read more →

A Must-See List of TensorFlow Examples

This article was last modified on 24 July 2017.

TensorFlow can become for machine learning what is OpenCV for computer vision and ROS as a robot operating system. Machine learning is getting more and more attractive to the public, and impressive results are not to be expected.

TensorFlow is an open-source library developed by Google and launched in 2015 for the general public. Ever since it was launched to be used by anyone who wants to work with artificial intelligence, the library broke all the records in terms of projects on GitHub.

Read now the best books to learn TensorFlow:

Returning to Google products, TensorFlow has a special place in the company’s projects, including Google Search, YouTube, Google Translate, Gmail, and more. Since the library is a very important resource of intelligence, in this article I made a list of examples using TensorFlow to do robotics applications. Furthermore, some of these examples are made by amateurs in the field of artificial intelligence.

  • Self-driving RC car using Raspberry Pi 3 and Tensorflow (added on 24.07.2017)
    DeepTesla is a deep neural network designed to drive a car. The neural network is used in this project to recognize a path delimited by line.

    The robot uses a simple webcam to capture images. The images are processed in real-time on a Raspberry Pi 3 at a rate of 30-50ms / frame.

    The artificial intelligence module has been trained on a computer with a GTX 1060 graphics processor.

  • Read more →

ROS Kinetic: Publisher and Subscriber in Python

The first time I started reading about ROS was last year. Also at that time, I made the decision to learn as much about ROS and make as many projects as possible based on it. After reading the first tutorials, I was sure it would be painful until I’ll build the first robot based on ROS. And I was right.

The first step in ROS begins with this tutorial. Or better, everything starts with two nodes, the so-called basic elements. A node to publish data, and a node to read and display the data received. As an autodidact, I know how hard it is to learn things that are not explained in detail. In this tutorial, I put a lot of attention on resources and the steps needed to write and run two nodes: a Publisher node and a Subscriber node.

Read now the best books to learn ROS:

Note: I have written with capital letters the Publisher and Subscriber to highlight the two ROS concepts.

What you find in this tutorial
  1. Resources needed
  2. A short description of the Publisher and Subscriber nodes
  3. A schema of the nodes
  4. Creating the workspace and the package that will contain the nodes
  5. The Publisher
  6. The Subscriber
  7. Run nodes with an automatic launch file
  8. Helpful commands
  9. Statistics
  10. Conclusion

1. Resources needed

To write the two ROS nodes you need hardware and software resources. Below I made a list of mandatory resources, and in the end, I added an optional resource that can be helpful in developing complex projects.
Read more →