Interrupting teleop from custom package
Hi all.
Please I need some help with code I'm writing to interrupt the teleop node on my Turtlebot3. I have the following code:
#! /usr/bin/env python
import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
#defines a callback
def callback(msg):
# while not rospy.is_shutdown():
print('==================================')
# REAR
print('REAR [0]')
print msg.ranges[0]
# RIGHT
print('RIGHT [90]')
print msg.ranges[90]
# FRONT
print('FRONT [180]')
print msg.ranges[180]
if msg.ranges[180] == 0:
print "STOPPING FRONT MOTION"
move = Twist()
move.linear.x = 0.0
move.angular.z = 0.0
pub.publish(move)
# LEFT
print('LEFT [270]')
print msg.ranges[270]
if __name__ == '__main__':
try:
rospy.init_node('obstacle_avoidance')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
rospy.Subscriber('/scan', LaserScan, callback)
rospy.spin()
except rospy.ROSInterruptException:
pass
In the section of code commented # FRONT, the robot is in motion using the teleoperation package and I am attempting to stop the robot cold in it's tracks. However, what happens is the wheel splutter i:e stop and continues in very quick succession.
Can anyone help point out my error, please?
you're not blocking the incoming msg stream that tells the robot to move forward.
So the robot receives
0
and normal msgs in rapid succession, leading to the stuttering you experience.Thanks for your input @gvdhoorn but how do I block the msg stream?