how can i pub on a topic for certain time with python

asked 2017-12-21 13:15:58 -0600

Taoying gravatar image

updated 2017-12-21 14:07:37 -0600

NEngelhard gravatar image

well this is my main function hier,when i try to run ,it did not show any error but also dosen't work

rospy.init_node('keyboard')
pub=rospy.Publisher('cmd_vel_command',Twist,queue_size=5)
rate=rospy.Rate(3)
beginntime=rospy.Time.now()
Duration=rospy.Duration(4.0)
endtime=beginntime+Duration
cmd = Twist()
cmd.angular.z = -5
while rospy.Time.now()<endtime:
    pub.publish(cmd)
    rate.sleep()
edit retag flag offensive close merge delete

Comments

2

What does

doesn't work

mean in this context?

jayess gravatar imagejayess ( 2017-12-21 14:28:12 -0600 )edit

i mean ,i want to pub a velocity on a topic with this context ,but doesn't work

Taoying gravatar imageTaoying ( 2018-01-03 04:09:50 -0600 )edit

What does

doesn't work

mean?

jayess gravatar imagejayess ( 2018-01-03 04:12:39 -0600 )edit

the terminal shows no error,but the robot does not move.

Taoying gravatar imageTaoying ( 2018-01-03 05:09:53 -0600 )edit

Maybe the robot is not moving because the topic name it is subscribed is /cmd_vel instead of cmd_vel_command.

If you are using gazebo, you can see the topics it subscribes with rosnode info /gazebo

Ruben Alves gravatar imageRuben Alves ( 2018-01-19 14:27:55 -0600 )edit