ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Pubish custom odometry information for robot_localization

asked 2019-09-17 07:15:23 -0600

enthusiast.australia gravatar image

updated 2019-09-18 08:15:33 -0600

hello everyone. I am trying to publish a new custom odomtery information for robot_localization package. I have a sensor which is giving me a position x and y and i want to use that to locate my robot. Since i want to fuse this odomtery information with robot's wheel odometry information, Other things like Twist can be zero as i will use robot's odometry for that purpose.My sensor is recording the positioning information in a .txt file and i will be reading that values to use. How should i modify things to get ting running.

#!/usr/bin/env python
# license removed for brevity
import rospy
import time
from std_msgs.msg import String
from nav_msgs.msg import Odometry
def odom1():
    global x
    global y
    pub = rospy.Publisher('odom1', Odometry, queue_size=10)
    rospy.init_node('publisher_turtlebot', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        f= open ("x.txt", "r")
        x= f.readlines()
        f1= open ("y.txt", "r")
        y= f1.readlines()
        odom1= Odometry()
        odom1.header.frame_id = "odom"
        odom1.pose.pose.position.x= x
        odom1.pose.pose.position.y= y
if __name__ == '__main__':
    except rospy.ROSInterruptException:

One file read x and other read y. I am getting this error.

Error: Odometry object is not callable.

What should i do? I am using kinetic kame with ubuntu 16.04 and python.

edit retag flag offensive close merge delete


It sounds like you're trying to integrate a GPS like sensor, those also produce position information but without heading information. Have you looked at the instructions for GPS here?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-09-18 05:31:13 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-09-17 08:10:48 -0600

Choco93 gravatar image

updated 2019-09-18 02:53:02 -0600

You can take a look here, you can publish it as either Odometry message or as PoseWithCovarianceStamped. According to this frame_id should be map/odom and child_link should be base_link.

EDIT: You need to make and odom object of type Odometry(), and add information to it.

odom = Odometry()
odom.header.stamp =
odom.header.frame_id = "odom"
odom.child_frame = "base_link"
odom.pose.pose.position.x = x         # x you read through your text file
odom.pose.pose.position.y = y         # y you read through your text file
edit flag offensive delete link more


My frame id would be odom and child_link be base_link, But i am not sure how to add up this info. Should i format my data and the way it is recording or should i change my code? In either way, what should i do ? because if i run above code, i get this error.

Invalid number of arguments., arguments should be [header, child_frame_id, pose, twist] args are [x:1.25254689 y:1.23585785 theta=0]

In case of using Odometry or PoseWithCovarianceStamped, then what things should i do so that i could use it in robot_localization?

enthusiast.australia gravatar image enthusiast.australia  ( 2019-09-17 08:15:51 -0600 )edit

You cannot just read a text file and pass it to a publisher, when making publisher you specifically told it to expect Odometry type message, so you need to provide an Odometry message. Take a look at my edited answer.

Choco93 gravatar image Choco93  ( 2019-09-18 02:54:10 -0600 )edit

I have changed my question and also have updated the code, but i am still having the problem. Any suggestions??

enthusiast.australia gravatar image enthusiast.australia  ( 2019-09-18 08:16:24 -0600 )edit

change pub.publish(odom1()) to pub.publish(odom1)

Choco93 gravatar image Choco93  ( 2019-09-18 08:36:47 -0600 )edit

thanks. got it. Silly mistake

enthusiast.australia gravatar image enthusiast.australia  ( 2019-09-18 08:50:11 -0600 )edit

Question Tools

1 follower


Asked: 2019-09-17 07:15:23 -0600

Seen: 409 times

Last updated: Sep 18 '19