0
$\begingroup$

Rosanswers logo

Hey, I'm quite new to ROS and trying to read some encoder data from my robot. The robot published its encoder data on a rostopic with type: msgs/Encoder. I would like to make a python script to collect this information.

I have currently done most ROS tutorials including the listerner.py scripts, but my problem is that I cannot find where to import the Encoder type from. and I have not had any luck finding a site with information about the Encoder data type.

Can any of you give me the code line for importing msgs/Encoder, it would be very helpful.

Any link to were I can find information about the topic types would also be most appriciated


Originally posted by toxicburn on ROS Answers with karma: 1 on 2014-03-03

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Normally encoder data is published using the geometry_msgs::Twist type or the nav_msgs::Odometry type.

In your Python node you would use

from geometry_msgs.msg import Twist
...
sub_encoders = rospy.Subscriber("encoders", Twist, encoder_callback)

or

from nav_msgs.msg import Odometry
...
sub_encoders = rospy.Subscriber("encoders", Odometry, encoder_callback)

Elsewhere in your code you would create your callback function.

def encoder_callback(msg):
    # Do something with encoder data. Only use one of the lines below.
    linear_velocity = msg.linear.x # Twist
    linear_velocity = msg.twist.twist.linear.x # Odometry

Originally posted by Thomas D with karma: 4347 on 2014-03-04

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.