Robot is not moving in the simulation

Greetings I tried to start the project to see in the simulator and make changes but it’s not working I don’t have any idea why can anyone help me with this?

1 Like

what project are you trying to load into the Gazebo simulator environment?

Just guessing, You need to set the below in your launch file to spawn the Robot urdf in Gazebo,

eg:

<!-- Run a python script to send a service call to gazebo_ros to spawn a URDF robot -->
<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
args="-urdf -x $(arg x) -y $(arg y) -z $(arg z)  -model $(arg robot_name) -param robot_description"/>

This one

One you have RDS open, in one shell use command 1 and another shell use command 2.
Command 1: roslaunch realrobotlab main.launch
Command 2: roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

Hope that helps!

1 Like

Hi there, after clicking on the run button, your rosject should start. Then in first shell you should use roscore which will run all ros services. Then open the second shell where you have to use command roslaunch realrobotlab main.launch which will start the simulation.Finally, you can use your roslaunch in the third terminal and so on. Everytime you start your rosject, you have to follow the same procedure.

1 Like

I tried running my file with that but my bot is still not moving. This is my code and launch file can you please check and let me know what’s wrong with it.

<node pkg="turtlebot3" type="turtlebot3.py" name="turtlebot3_node" output="screen">   

</node>

Code

#! /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[360])

if msg.ranges[360] > .3:

    print('in')

    move.linear.x = 10

    move.angular.z = 20

    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()

Use /scan topic in subscriber

1 Like

Do you know what this error is ? Thank you so much

Hi, here the complete range for the robot is 360 and also it starts from 0. So, 359 is the maximum range you can put. Put 359 instead of 360 as the max value and it should work.

Also, you put the laserscan when you had to put /scan and now do you know that, if you do the rostopic list after starting the gazebo simulation, then you should be able to see /scan topic and this is how you know which topics are available. I am also working on the same thing but I am in stage 2. If you need any help let me know.

2 Likes

Yeah, I find out that so if I put the range to 359 then it will give me a scan in front of the bot or the right side of the bot? As I tried it with 179.25 also it’s still giving an error. what should I do for it to go in the forward direction.

This is my code

#! /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[0])

print(len(msg.ranges))

if msg.ranges[0] > .3:

    print('in')

    move.linear.x = .5

    move.angular.z = .2

    pub.publish(move)

if msg.ranges[0] < .2:

    print('out')

    move.linear.x = .5

    move.angular.z = -.2

    pub.publish(move)

if msg.ranges[0] > .2 and msg.ranges[0] < .3:

    print('in')

    move.linear.x = .5

    move.angular.z = 0

    pub.publish(move)

rospy.init_node(‘turtlebot3_node’)

move = Twist()

pub = rospy.Publisher(’/cmd_vel’,Twist,queue_size = 1)

sub = rospy.Subscriber(’/scan’,LaserScan,callback)

rospy.spin()

Please refer to the attached link to understand how to check the laser data readings of the robot and do the exact same procedure. https://www.youtube.com/watch?v=RFNNsDI2b6c is the link. Watch it

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.