Hello,
I have finished my task for 4.3 Quiz and I don’t get any error but I don’t know why my robot is not moving in Gazebo simulation. After doing catkin_make and sourcing the setup.bash I did roslaunch realrobotlab main.launch and then Launched my topics_quiz.launch. Below is my scripts and launch file for reference. Can anyone please help me out.
script
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
def callback(laser):
if laser.ranges[360] < 1:
print("Detected Obstacle in Front")
print("Turning Left")
move.linear.z = 0.3
move.linear.x = 0.5
elif laser.ranges[0] < 1:
print("Detected Obstacle on Right")
print("Turning Left again")
move.linear.z = - 0.3
move.linear.x = 0.5
elif laser.ranges[719] < 1:
print("Detected Obstacle on Left")
print("Turning Right")
move.linear.z = - 0.3
move.linear.x = 0.5
else:
move.linear.x = 0.5
print("Forward")
rospy.init_node("topics_quiz_node")
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
rate = rospy.Rate(2)
move = Twist()
while not rospy.is_shutdown():
rospy.Subscriber("/kobuki/laser/scan", LaserScan, callback)
pub.publish(move)
rospy.spin()
Launch file
<launch>
<node name="topics_quiz_node" pkg="topics_quiz" type="topics_quiz_scripts.py" output="screen">
</node>
</launch>