Reset Odometry poses

asked 2018-12-06 10:02:13 -0600

johnbryant gravatar image

Hi , I am trying to create a script in python that resets the odometry values I get from my odometry topic but does not seem to work. Any thoughts?? Thanks in advance.

#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist
from math import atan2,pi,pow,sqrt,radians   
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion, quaternion_from_euler
import math
import tf

rospy.init_node('reset_robot_node', anonymous=True)  
pub2 = rospy.Publisher('/marvin/diff_drive_controller/odom', Odometry,queue_size=1)

msg1=Odometry()

msg1.pose.pose.position.x=None
msg1.pose.pose.position.y=None
msg1.pose.pose.position.z=None
msg1.pose.pose.orientation.x=None
msg1.pose.pose.orientation.y=None
msg1.pose.pose.orientation.z=None
msg1.pose.pose.orientation.z=None
pub1.publish(msg1)
edit retag flag offensive close merge delete

Comments

Can you please tell us what it is that you really want to do? I have a suspicion that "reset[ting] the odometry values" is something you want to do to achieve something else. The code you show won't do what you think it does, so to avoid an xy-problem, please provide a little more info.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-07 02:58:16 -0600 )edit

Hi, thanks for your immediate response. Well, I want to do is exactly reset all the values given by odometry topic through a script and not by turning on and off my robot. So that´s why I thought of publishing an empty message to the odometry topic. Any suggestions on that?

johnbryant gravatar image johnbryant  ( 2018-12-07 03:07:22 -0600 )edit

Publishing a single msg like you do to a node does not reset the node nor the topic. I don't see anywhere in the docs for diff_drive_controller that is subscribes to that topic, so if your msg would be published, the next msg would contain the ..

gvdhoorn gravatar image gvdhoorn  ( 2018-12-07 03:53:38 -0600 )edit

.. values again that diff_drive_controller is maintaining internally.

Also, related, but tangentially: your script most likely exits before the middleware has had a chance to actually publish your msg, so it would not work even if diff_drive_controller supported this.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-07 03:54:44 -0600 )edit