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

How to import msgs/Encoder for python scripts

asked 2014-03-03 20:16:39 -0500

toxicburn gravatar image

updated 2014-03-04 01:22:53 -0500

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-03-04 03:07:23 -0500

Thomas D gravatar image

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
edit flag offensive delete link more
0

answered 2014-03-04 02:55:39 -0500

fivef gravatar image

Probably your encoder message is defined in the package you are using. So you import should look something like this:

import  <package_name>.msg
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-03-03 20:16:39 -0500

Seen: 1,091 times

Last updated: Mar 04 '14