Ask Your Question
0

Pubish custom odometry information for robot_localization

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

enthusiast.australia gravatar image

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

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.stamp= rospy.Time.now()
        odom1.header.frame_id = "odom"
        odom1.pose.pose.position.x= x
        odom1.pose.pose.position.y= y
        pub.publish(odom1())
        rate.sleep()
if __name__ == '__main__':
    try:
        odom1()
    except rospy.ROSInterruptException:
        pass``

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

Comments

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 imagePeteBlackerThe3rd ( 2019-09-18 05:31:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

Choco93 gravatar image

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

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 = rospy.Time.now()
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
pub.publish(odom)
edit flag offensive delete link more

Comments

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 imageenthusiast.australia ( 2019-09-17 08:15:51 -0500 )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 imageChoco93 ( 2019-09-18 02:54:10 -0500 )edit

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

enthusiast.australia gravatar imageenthusiast.australia ( 2019-09-18 08:16:24 -0500 )edit

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

Choco93 gravatar imageChoco93 ( 2019-09-18 08:36:47 -0500 )edit

thanks. got it. Silly mistake

enthusiast.australia gravatar imageenthusiast.australia ( 2019-09-18 08:50:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 34 times

Last updated: Sep 18