Hi simon.steinmann91
Thank you for your reply. I tried the same thing without the rospy.spin() line but I have the following error :
roslaunch topics_quiz topics_quiz.launch
… logging to /home/user/.ros/log/a69e5cb0-323f-11ea-9872-0aeecc1a3ff6/roslaunch-rosdscomputer-11900.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://rosdscomputer:37111/
SUMMARY
PARAMETERS
- /rosdistro: kinetic
- /rosversion: 1.12.14
NODES
/
topics_quiz_node (topics_quiz/topics_quiz.py)
ROS_MASTER_URI=http://master:11311
process[topics_quiz_node-1]: started with pid [12007]
Traceback (most recent call last):
File “/home/user/catkin_ws/src/topics_quiz/src/topics_quiz.py”, line 26, in
if scan.ranges[360] < 1:
IndexError: list index out of range
[topics_quiz_node-1] process has died [pid 12007, exit code 1, cmd /home/user/catkin_ws/src/topics_quiz/src/topics_quiz.py __name:=topics_quiz_node __log:=/home/user/.ros/log/a69e5cb0-323f-11ea-9872-0aeecc1a3ff6/topics_quiz_node-1.log].
log file: /home/user/.ros/log/a69e5cb0-323f-11ea-9872-0aeecc1a3ff6/topics_quiz_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor…
… shutting down processing monitor complete
done
I tried to understand what does that mean but I think I don’t have enough knowledges for the moment.
Just the code below, so you can see what I modified (just removed the line as you said) : #! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
rospy.init_node(‘topics_quiz_node’)
pub = rospy.Publisher(’/cmd_vel’, Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()
move.linear.x = 0.5
def callback(msg):
print msg
sub = rospy.Subscriber(‘kobuki/laser/scan’, LaserScan, callback)
scan = LaserScan()
while not rospy.is_shutdown():
pub.publish(move)
move.linear.x = 0.3
if scan.ranges[360] < 1:
move.angular.z = 0.5
rate.sleep()
if scan.ranges[0] < 1:
move.angular.z = 0.5
if scan.ranges[720] < 1:
move.angular.z = -0.5
rate.sleep()