Quiz 1 -inf value

Hello! For quiz 1, I am able to get my robot to move and turn. However, the robot gets to a point where it’s too close to the wall and I get an inf value. I’m not sure why this is happening. My code is attached below. Any advice would be greatly appreciated.

#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

def callback(msg):
    if msg.ranges[360] > 1.0: 
        move.linear.x = 0.10
        move.angular.z = 0.0
        print('Moving forward', msg.ranges[360])
    if msg.ranges[360] < 1.0:
        move.linear.x = 0.0
        move.angular.z = 0.30
        print('Turning', msg.ranges[360])
    pub.publish(move)

rospy.init_node('topics_quiz_node')
pub = rospy.Publisher('/cmd_vel',Twist, queue_size = 1)
sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback)
move = Twist()
rospy.spin()

Hi, welcome to the community!

Yes, the scan will return an infinite value once it is right up against a wall. This is common in most lidars. You can account for this in your code though in your if statements though.

I’m not sure but, I think that it doesn’t enter 2dn if, try using elif instead of 2dn if, and also make sure you account for the value when it is =1 either in 1st if or elif