Greetings I am trying to complete the first project ROS Basic in 5 days. I wrote the code and launch file for that even then the robot is not moving when I am launching the file.
This is launch file
<node pkg="turtlebot3" type="turtlebot3.py" name="turtlebot3_node" output="screen">
</node>
This is the code that I am using
#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
def callback(msg):
rospy.loginfo(rospy.get_caller_id()+ 'The distance to obstacle is - %s',msg.ranges[300])
if msg.ranges[0] > .3:
print('in')
move.linear.x = .1
move.angular.z = .2
pub.publish(move)
if msg.ranges[0] < .2:
print('out')
move.linear.x = 1
move.angular.z = -2
pub.publish(move)
if msg.ranges[0] > .2 and msg.ranges[0] < 0.3:
print('out')
move.linear.x = 1
move.angular.z = 0
pub.publish(move)
if msg.ranges[360] < .5:
print('out')
move.linear.x = 1
move.angular.z = 5
pub.publish(move)
rospy.init_node(‘turtlebot3_node’)
move = Twist()
pub = rospy.Publisher(’/cmd_vel’,Twist,queue_size = 1)
sub = rospy.Subscriber(’/kobuki/laser/scan’,LaserScan,callback)
rospy.spin()