ROS and Raspberry Pi for Beginners | Tutorial #0 – Topics Packages RosMaster

ROS and Raspberry Pi for controlling a
robo car my name is Tiziano and if you're new to
the channel consider subscribing because I'll be posting contents about drones,
robotics, ROS, technical reviews right here Today we're going to start a mini
series about ROS and what's better than applying ROS on an actual example for
controlling a robot car with a Raspberry Pi 3 what's the purpose of
this first tutorial: we want to control our robot car using the keyboard on our
laptop and how can we accomplish that well we're gonna create a node that is
gonna control the servos and it's gonna subscribe to a topic that is called
servos_absolute and we're gonna create another node called donkey low level control
that is gonna publish on the servo topic and is also gonna subscribe to a cmd_vel
topic that is gonna come from the keyboard on our laptop in this first
video we're going to be covering the very basics so we're gonna be installing
the environment I'm gonna show you how to create and install a package and most
importantly I'm gonna talk about topics and messages so let's dive into the
tutorial our first step is installing ROS kinetic on our Ubuntu machine.

You
can also use a virtual machine but I'd rather use a dual boot computer because
it makes things much smoother For installing ROS on Ubuntu we just follow the wiki.ros.org/kinetic/installation and
here you just follow the instructions step by step I won't be going through
all them then you type sudo apt-get install ros-kinetic-desktop-full last we need to initialize the rosdep so we type sudo rosdep init and then rosdep update now we set up the catkin workspace first we source
the current development environment typing source … – this is important because you could have more than one ROS installation at the same time then we create the catkin_ws/src folder then we navigate into catkin_ws and we type catkin_make this will build
the development environment and then we source the file setup.bash in the
folder devel now you should be running this particular step every time you open
a new terminal in order to avoid to do that every time we just write this line
in the ~/.bashrc file that is the file that is read every time you open a new
terminal so we sudo nano ~/.bashrc at the end of the file we just type the
source devel/setup.bash we save it and you're done if you want to know more
about catkin just go on the and what about the RC car well we're going to be using the donkey car
from the donkey car robocar project and you can find all information about
it on I also
wrote in the description all the main parts that you would need for building
one yourself you can click on one of those links and get your parts already
on Amazon the donkey car is made up of a cheap but powerful RC car like the
magnet model a Raspberry Pi 3 model B or B+ a camera with a wide angle lens a servo control board from Adafruit follow the instruction in the link that
I provided in the description below and you'll be up and running in 20 minutes for the Raspberry Pi we're going to download a pre-baked SD car from
ubiquity robotics this image is great because it has ROS already installed
and running plus the Raspberry Pi works as an access point so we can connect our
computer to the car without bringing our access point when we work outdoor we connect to the donkey car using SSH connection now there are two ways for
connecting to the robocar one is connected to the access point and the
other one is to an Ethernet connection now we're going to be using the Ethernet
connection because we need to install some packages and update the car on Linux we open a terminal we connect to the donkey car through ssh and
password is Ubuntu the first thing we're gonna do is update and then we install
Samba for sharing the folder then we open the samba config file we set win_support as yes and then we set up the folder that we want to share in our
cases the source of the catkin workspace then we set up the Samba password as
Ubuntu and we reboot now we connect back to the donkey car and if we type a roscore we realize that ROS is already running don't turn on your RC car yet
and every time you turn it on make sure that the wheels don't touch anything
they can spin freely you don't want to end up chasing your RC car in case you
make any mistake right the first thing that we need to do is installing the
servo control board node now there is a great package developed from Bradanlan Studio and we're going to install it from github we first need to install
the lib_i2c library then we navigate into the source folder in our
catkin workspace and here we clone the repository from BradanLane then we go
back home folder and we write catkin_make and catkin compiles the packages
and builds the messages when it's done remember to source the development
environment typing source devel/setup.bash now from our Ubuntu laptop let's browse
into the donkey car folders and let's go into the i2c control board
package inside we can find multiple files and folders let's open the launch file first of all let's remove the launch
prefix sudo -e as you can see the launch file is written in XML format it starts
and finishes with launch and then it creates a node as you can see in the
node I define a package has the current name and then the name as the name of
the node and in type we write the name of the file we're actually running now let's open the message folder and in particular let's open the message ServoArray as you can see the ServoArray message is defined as an array of Servo
objects if we open the Servo message we can see that each Servo message is
defined by an int16 servo, that is going to be the ID and value that is a
float32 now in each package there are two important files one is package.xml
and other is CMakeList package.xml contains all information about the
package like name, version, the contact , the website.

But also all the important
features for building and all the dependencies like for example in this
case roscpp, rospy CMakeList instead contains all the directories and
the files we are going to be covering those files in much more detail in another
video now that we have installed a package
from github let's talk a little bit about topics. So topics are kind of like
pipes that connects nodes together in which they can send messages.

One node that has
a message that wanna share can publish into a topic and and know that it is
interested that message can subscribe to the topic and read a message everything
is handled by a central node called ROS MASTER that can run everywhere on your network and in our case it'll be running on the donkey car and we're gonna
connect our laptop to the ROS master node okay let's run the node i2c
control board and let's see what topics are available right now now on one
terminal we'll run the i2c control board node and on another
terminal we list the topics typing rostopic list as you can see
servos_absolute is one of the topic that is currently active when you want to
have details about the topic you just type rostopic info and the name of the
topic and here for example we see that the topic of servos_absolute has a
message of type i2cpwm_board/ServoArray and the current subscriber is the
i2cpwm_controller and if we want to have any detail about the message
AervoArray we just type rosmsg show and the name of the message and
here we are with all the details about our message in our case is an array of
servos and each of the servo is composed of servo and value now let's say that we
want to publish on this topic it's pretty easy we just type rostopic pub
and then the name of the topic and then hitting tab tab twice ros compiles the
message for us for example let's set the throttle that is servo 1 to idle.

In
our case idle corresponds to 333 if you want to fill up we just put something
that is higher than 333 and if you want to move the steering wheel we just type
2 as a servo and then again a straight ceiling will correspond to 333 and we
want to go right is higher than the value is it if you want to go left
it's something that is less than the value and now it's time for us to create our
package in order to create our package we navigate into the source of our
catkin workspace folder and then we type catkin_create_pkg the name of our package and then our dependency rospy because
we're going to develop in Python if we open CMakeList we realize that the
name is donkey_llc and rospy is a required component the basic idea is
creating a class or handling the low level control of our donkey car that is going
to publish on the topic servo_absolute and it's going to subscribe to the topic
cmd_vel t he message on cmd_vel is a geometry message
Twist.

Now Twist is made up of multiple fields there is linear and angular
controls and for linear and angular or XYZ de for our car we're just gonna be
publishing on the linear dot X and the angular dot theta so forward backward
right left we write the path to python then we import Russ py in time and then
from I square CPW on board we pour the messages server and server array and
from the geometry messages we import twist then we create a simple class
called servo convert that is going to convert our command values in negative
one to one into something that AI square see PWM bore understands that is a
center value in my case about 333 and a range of about 90 and they will write
the get value out function that converts the input from negative 1 to 1 into the
actual server range nice time for the actual class decay low-level control we
initialize there know the decay LLC and then we create a dictionary of
activators each element in the dictionary is a server convert object
and then we create a server message as a server array object a server array is an
array of two servers so we have to initialize both of them with this for
loop and then we create the object publisher
Ross py publisher and then the topic we want to publish to the message type in
our case disturb are a and Q asides equal to one so the publisher is gonna
publish every single time and then we create a subscriber object that it's
gonna subscribe to the command Val topic reading a message of type twist and it's
gonna call the function onset of Twitter's from command Bell that we have
still to right now we probably want to stop the car in case we don't receive
any message for at least five seconds and here it is and I'm gonna write a
time out of five seconds now let's create a function that is gonna write to
the servo from a command bail message first we save at the time we received a
message and then for the throttle will read from the message linear acts and
for the steering angle we read from the message angular Zeta and here you write
the sense server message that is going to be the actual publisher so we cycle
in the dictionary and for each of the servos we're going to assign the servo
ID and the value last we're going to create a property for checking out
whether the controller is connected and they write if simple run function that
is an infinite wire loop we compile our package
typing catkin and the score make now everything is set up so on the donkey
car we're going to be launching two terminals one is for launching the
control board node and the second one is for launching our low-level control node
on another terminal on our Abunda machine we're gonna setting up the Ross
environments and launching the keyboard node using the SSH we open two terminals
on the Raspberry Pi on one we around the I square C control board node and on the
other one we around our own donkey LLC node now on our car we plug the battery
on our Lubuntu laptop we open at our terminal and now we need to connect our
a boon to laptop to the roastmaster running on the Raspberry Pi this is
pretty easy we just type export and then the global variable
Ross underscore master underscore URI equal to the
dress in our case is ubiquity robot lot local I'm using the hostname and the
port is 11 311 we also want to ensure that the current cross IP global
variable is set correctly so we type export ross underscore IP equal and IP
address of this machine in my case i can also retrieve it from post name – i and
in fact if i type hostname – capital i i get the IP address now in order to check
that our laptops actually connected to the roastmaster running on the Raspberry
Pi let's just type Ross topic list and as you see here are all the topics that
are active on the Raspberry Pi finally we can launch the Tilly op twist
keyboard node for controlling the keyboard Tilly openers chord twist and
is called keyboard should be a package that comes pre-installed with Ross
kinetic if you don't have it you just install it follow the link in the
description below okay that was fun so in order to make
things even easier on your Robo car let's create a launch file so we can
launch the two notes together let's create a launch folder in our donkey LLC
package and here we create a keyboard underscore demo dot launch file we put
the standard launch tags and here you wanna include the launch file of the I
Square C PWM board in order to do that we got to find the I square C PWM
package and Ross has a very convenient way of finding packages you just type
dollar and then in parentheses fine and then the name of the package you're
looking for and that's for the donkey cart control node we create another node
tag and they will write package equal the donkey LLC the name of the package
and then to name the name of the note and then as type we write the low level
controlled opy that is our script and then we save it and run it
alright enough for the into our testing let's move this beast out door for the
door test let's connect to the obesity robots access point created by the
Raspberry Pi then our one terminal connected with the Raspberry Pi through
SSH we launch the donkey LLC launch file and on a local terminal we launch the
keyboard node and now let's the fun begin now that is what I call fun that was a
real-life example we set up an environment we install a package we
create our low-level control node and we control everything to another computer
that was really an achievement now if you guys have any other package that we
want to try and run on the robocar just write it in the comments below for
example we're gonna be trying and follow a line or recognize a signal or an
Arouca marker if you guys have already developed some package you want to give
it a run in this tutorial series write it in the comments below don't forget
subscribe so you don't miss anything and I'll see you guys next time bye

As found on YouTube

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *