ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The ROS Groovy release on Ubuntu Precise 12.04 uses Python 2.7, which is the default interpreter for that system.
Precise also provides Python 3.2, which you can install, but the ROS distribution was not built to use that. It is probably possible to get it working by building everything from source, but I do not recommend that approach.
If you are willing to use Python 2, things will be much easier for now.
First, you need to get comfortable with basic ROS programming in Python. This tutorial will explain how to publish ROS messages.
It's a little hard to untangle the code you posted. If you are new to Python, beware that indentation is significant because it defines the block structure of your program. So, be careful with that.
You should not try to create two ROS nodes in that single script. You don't need that, anyway. One node will suffice. Your main function will probably look more like this:
rospy.init_node('ticks')
lpub = rospy.Publisher('lwheel', Int16)
rpub = rospy.Publisher('rwheel', Int16)
hz_rate = rospy.Rate(80)
while not rospy.is_shutdown():
# read left encoder
lpub.publish(Int16(data=left))
# read right encoder
rpub.publish(Int16(data=right))
hz_rate.sleep()
That is just a simplified overview. Your actual logic will be more complex.
Note that handling of bytes and strings differs between Python 2 and Python 3. It is possible to write code that works with either, but that gets tricky.
2 | No.2 Revision |
The ROS Groovy release on Ubuntu Precise 12.04 uses Python 2.7, which is the default interpreter for that system.
Precise also provides Python 3.2, which you can install, but the ROS distribution was not built to use that. It is probably possible to get it working by building everything from source, but I do not recommend that approach.
If you are willing to use Python 2, things will be much easier for now.now. Note that handling of bytes and strings differs between Python 2 and Python 3. It is possible to write code that works with either, but that gets tricky. Keep it simple until you have something that works.
First, you need to get comfortable with basic ROS programming in Python. This tutorial will explain how to publish ROS messages.
It's a little hard to untangle the code you posted. If you are new to Python, Python: beware that indentation is significant because it defines the block structure of your program. So, be careful with that.careful.
You should not try to create two ROS nodes in that single script. You don't need that, anyway. One to, anyway, one node will suffice. Your main function will probably look more like this:
rospy.init_node('ticks')
lpub = rospy.Publisher('lwheel', Int16)
rpub = rospy.Publisher('rwheel', Int16)
hz_rate = rospy.Rate(80)
while not rospy.is_shutdown():
# read left encoder
lpub.publish(Int16(data=left))
# read right encoder
rpub.publish(Int16(data=right))
hz_rate.sleep()
That is just a simplified overview. Your actual logic will be more complex.
Note that handling of bytes and strings differs between Python 2 and Python 3. It is possible to write code that works with either, but that gets tricky.
3 | No.3 Revision |
The ROS Groovy release on Ubuntu Precise 12.04 uses Python 2.7, which is the default interpreter for that system.
Precise also provides Python 3.2, which you can install, but the ROS distribution was not built to use that. It is probably possible to get it working by building everything from source, but I do not recommend that approach.
If you are willing to use Python 2, things will be much easier for now. Note that handling of bytes and strings differs between Python 2 and Python 3. It is possible to write code that works with either, but that gets tricky. Keep it simple until you have something that works.
First, you need to get comfortable with basic ROS programming in Python. This tutorial will explain how to publish ROS messages.
It's a little hard to untangle the code you posted. If you are new to Python: beware that indentation is significant because it defines the block structure of your program. So, be careful.
You should not try to create two ROS nodes in that single script. You don't need to, anyway, one node will suffice. Your main function will probably look more like this:
rospy.init_node('ticks')
lpub = rospy.Publisher('lwheel', Int16)
rpub = rospy.Publisher('rwheel', Int16)
hz_rate = rospy.Rate(80)
while not rospy.is_shutdown():
# read left encoder
lpub.publish(Int16(data=left))
lpub.publish(Int16(data=int(left)))
# read right encoder
rpub.publish(Int16(data=right))
rpub.publish(Int16(data=int(right)))
hz_rate.sleep()
That is just a simplified overview. Your actual logic will be more complex.