I have created the topics_quiz package with the: catkin_create_pkg topics_quiz rospy command then created the launch file witch contains :
then created the python file :
#! /usr/bin/python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
class topics_quiz_node:
def init(self):
# init node
rospy.init_node(‘topics_quiz_node’)
# init subscriber and publisher
self.sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, self.callback)
self.pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
# optional: init Publisher msgs for easier access
self.move = Twist() # class Twist(genpy.Message)
# no need to init Subscriber msgs as you receive them in your `callback` function
# self.laser_scan = LaserScan() # class LaserScan(genpy.Message)
def callback(self, msg):
self.laser_scan = msg # class LaserScan(genpy.Message)
r = self.laser_scan.ranges # 720 len array; 0 is right side, 719 is left side
if r[180] > 1 and r[360] > 1 and r[540] > 1:
print('Moving forward!')
self.move.linear.x = .2
self.move.angular.z = 0
else:
print('Object in front! Turning Left!')
self.move.linear.x = .1
self.move.angular.z = .5
if r[0] < 1:
print('Object on right!')
if r[719] < 1:
print('Object on left!')
self.pub.publish(self.move)
def start(self):
rospy.spin() # loop: passes msg to callback in subscriber
if name==‘main’:
node = topics_quiz_node()
node.start()
then cd into the catkin_ws and used: catkin build then source the file with: source devel/setup.bash
After all this i get the massage: [rospack] Error: package ‘topics_quiz’ not found
And the bad part is that i get this error for all the exemples that i did in this course and they worked until now …
Please help me get out of this slump!