You are on page 1of 11

SC-635 Advanced Topics in Mobile Robotics

Experiment Module : Custom messages and trilateration

February 10, 2020

Systems and Control Engineering


Indian Institute of Technology Bombay

1 / 11
Overview

1. Custom messages

2. Assignment

2 / 11
Custom messages

In assignment 0: we implemented
I Name publisher with String message type
I Roll number publisher with Numeric message type
We created separate nodes to publish each type.

With custom messages we can encode specialized information such


as collection of simple message types.
Some examples:
I Collection of robot poses in multi-agent setting.
I Sensor parameters

3 / 11
Custom message: Student info

Lets create a custom message student info with following fields


I Name
I Roll number
Custom messages are placed under the msg directory

Student info.msg contents


1 s t r i n g name
2 int64 roll number

4 / 11
Directory structure

The directory structure should look as follows:

5 / 11
Modifications 1
The custom message type we defined needs to be built with
catkin make
We notify catkin make by modifying the contents of package.xml
file
1 <? xml v e r s i o n=” 1 . 0 ” ?>
2 <p a c k a g e f o r m a t=” 2 ”>
3 <name>t e m p l a t e a 3</name>
4 <v e r s i o n>0 . 0 . 0</ v e r s i o n>
5 <d e s c r i p t i o n>The t e m p l a t e a 3 p a c k a g e</ d e s c r i p t i o n>
6 ...
7 <b u i l d t o o l d e p e n d>c a t k i n</ b u i l d t o o l d e p e n d>
8 <b u i l d d e p e n d>r o s p y</ b u i l d d e p e n d>
9
10 <b u i l d d e p e n d>m e s s a g e g e n e r a t i o n</ b u i l d d e p e n d>
11 <e x e c d e p e n d>m e s s a g e r u n t i m e</ e x e c d e p e n d>
12
13 <b u i l d e x p o r t d e p e n d>r o s p y</ b u i l d e x p o r t d e p e n d>
14 <e x e c d e p e n d>r o s p y</ e x e c d e p e n d>
15
16 <e x p o r t>
17 <!−− O t h e r t o o l s can r e q u e s t a d d i t i o n a l i n f o r m a t i o n be p l a c e d h e r e −−>
18 </ e x p o r t>
19 </ p a c k a g e>

Line 10,11 are added to let the build system know that we want to
use custom messages.
6 / 11
Modifications 2
We also need to modify CMakeLists.txt file
1 c m a k e m i n i m u m r e q u i r e d ( VERSION 2 . 8 . 3 )
2 project ( template a3 )
3 ## Components
4 f i n d p a c k a g e ( c a t k i n REQUIRED COMPONENTS
5 rospy
6 roscpp
7 std msgs ## m o d i f i e d
8 message generation ## m o d i f i e d
9 )
10 ## G e n e r a t e m e s s a g e s i n t h e ’ msg ’ f o l d e r
11 add message files (
12 FILES
13 S t u d e n t i n f o . msg ## m o d i f i e d
14 Landmark . msg ## m o d i f i e d
15 T r i l a t e r a t i o n . msg ## m o d i f i e d
16 )
17 ## G e n e r a t e added m e s s a g e s and s e r v i c e s w i t h any d e p e n d e n c i e s l i s t e d h e r e
18 generate messages (
19 DEPENDENCIES
20 std msgs ## m o d i f i e d
21 )
22 ## c a t k i n s p e c i f i c c o n f i g u r a t i o n
23 catkin package (
24 CATKIN DEPENDS m e s s a g e r u n t i m e ##m o d i f i e d
25 )
26
27 ## S p e c i f y a d d i t i o n a l l o c a t i o n s o f h e a d e r files
28 include directories (
29 ${catkin INCLUDE DIRS}
30 )

7 / 11
Custom message: Publisher

Lets use the custom message by writing a publisher:


1 #! / u s r / b i n / e nv p y t h o n
2 import rospy
3 from t e m p l a t e a 3 . msg i m p o r t S t u d e n t i n f o
4
5 def t a l k e r () :
6 pub = r o s p y . P u b l i s h e r ( ’ c h a t t e r ’ , S t u d e n t i n f o , q u e u e s i z e =10)
7 r o s p y . i n i t n o d e ( ’ t a l k e r ’ , anonymous=True )
8 r a t e = r o s p y . Rate ( 1 )
9 w h i l e not r o s p y . i s s h u t d o w n ( ) :
10 t = S t u d e n t i n f o ( ” v i v e k ” , 164230001)
11 pub . p u b l i s h ( t )
12 r o s p y . l o g i n f o ( ” Sent a message ! ” )
13 rate . sleep ()
14
15 if name == ’ m a i n ’ :
16 try :
17 talker ()
18 except rospy . ROSInterruptException :
19 pass

In line 5, we are creating a custom message.

8 / 11
Custom message : Result

We expect to see the following results:

9 / 11
Assignment 3

The robot loads with pose (0, 0, 0). Three landmarks are placed at [7,7], [-7,-7], [7,-7], the distance and identity of
the landmarks is being published under the topic name /trilateration data.
I Calculate the position (x,y) of robot using the trilateration data. This part of code should be written inside
the callback function (see line 30 of controller.py).
I Calculate the heading of the robot using two consecutive poses of the robot. This part will also go inside
the callback function (see line 32 of controller.py)
I Track a circular trajectory with radius 5 meter centered at origin.
I Plot the waypoints and the tracked trajectory. Save figure with labels and title.

I Calculate the mean squared error for one complete traversal of the circular trajectory.
I Sample 100 points along the tracked trajectory
I For each robot pose Xr = (x,y,θ) find the closest point Xc on the circle x 2 + y 2 = 52
I Calculate the distance to Derror and square it
I Sum all D 2
error terms and divide by 100 to obtain you MSE. Report this number in a file named
RESULT.txt.

The template project is located at :

http://bit.ly/2tdpTemplateA4

10 / 11
Thank you

11 / 11

You might also like