Ranges[360] is out of range of tuple

Trying to solve rosject basic part1 and the ranges list is out of range. What is the length of ranges list? here is my code:

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

def callback(msg): 

  print(msg.ranges[360]) 
  print(msg.ranges[0]) 

  if msg.ranges[360] < 0.5:
      move.linear.x = 0
      move.angular.z = 0.49

  if msg.ranges[0] > 0.3:
      move.linear.x = 0.19
      move.angular.z = -0.49

  if msg.ranges[0] < 0.2:
      move.linear.x = 0.19
      move.angular.z = 0.49

  pub.publish(move)

  

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

Hello @ToniSolo ,

As far as I could notice, you are trying to reach the position 360
When a laser scan has 360 measurements, the positions go from 0 to 359

Please, do this adjustment and let me know if that works for you.

Regards