Ask Your Question
0

Publish on /mobile_base/commands/velocity for moving the turtlebot

asked 2017-01-09 14:06:37 -0600

Marcosdp gravatar image

updated 2017-01-09 15:04:35 -0600

NEngelhard gravatar image

Hey guys, I'm using gazebo an I want to publish message on /mobile_base/commands/velocity for moving the turtlebot but I don't succeded.

this is my class

import rospy
from geometry_msgs.msg import Twist
from geometry_msgs.msg import Vector3

class rosact(object):
    def __init__(self):
        rospy.init_node('act')
        self._pub = rospy.Publisher('mobile_base/commands/velocity',Twist,queue_size=10)
        rospy.spin()

    def write(self,linear,angular):
        self._pub.publish(Twist(Vector3(linear[0],linear[1],linear[2]),
                   Vector3(angular[0],angular[1],angular[2])))

def main():
    act=rosact()
    act.write([0.2,0,0],[0,0,0])


if __name__== '__main__':
    main()

Help me,please

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-01-09 15:07:57 -0600

NEngelhard gravatar image

In case you wonder why write is never called, rospy.spin() is a blocking function. A short sleep (rospy.sleep(1)) should be enough to create the publisher (and a sleep after the publish ensures that the message is also sent.

edit flag offensive delete link more

Comments

Yes, it works.. Thanks.. I'have another question: Can I implement Asyncio with rospy.Spin (),for doing a asynchronous call(because I need to acquire the results of sensors and the result of a algorithm of decision.

Thanks

Marcosdp gravatar imageMarcosdp ( 2017-01-09 20:09:49 -0600 )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: 2017-01-09 14:06:37 -0600

Seen: 1,428 times

Last updated: Jan 09 '17