I have written the code. I hope everything is working fine but when I do rosrun or roslaunch it is not showing any simulation. It is staying normal on screen and no error is also found.
Hi @saitarak.padarthi i would be helpful if you show a screenshot of the error or a console log.
#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
def callback(msg):
if msg.ranges[360] > 1:
move.linear.x = 0.1
if msg.ranges[360] < 1:
move.angular.z = -0.5
move.linear.x = 0
if msg.ranges[0] < 1:
move.angular.z = -0.5
move.linear.x = 0
if msg.ranges[719] < 1:
move.angular.z = 0.5
move.linear.x = 0
rospy.init_node(“topics_quiz_node”)
pub = rospy.Publisher("/cmd_vel",Twist,queue_size = 1)
sub = rospy.Subscriber("/kobuki/laser/scan",LaserScan,callback)
rate = rospy.Rate(2)
move = Twist()
rospy.spin()
Roslaunch file is given below
One more doubt is regarding service server launch.
def my_callback(request):
rospy.loginfo(“The Service move_bb8_in_circle has been called”)
move = Twist()
move.linear.x = 0.2
move.angular.z = 0.2
pub.publish(move)
rospy.loginfo(“Finished service move_bb8_in_circle”)
return EmptyResponse()
rospy.init_node(‘service_move_bb8_in_circle_server’)
pub = rospy.Publisher("/cmd_vel",Twist,queue_size = 1)
move = Twist()
my_service = rospy.Service(’/move_bb8_in_circle’, Empty , my_callback)
rospy.loginfo(“Service /move_bb8_in_circle Ready”)
rospy.spin()
Roslaunch:
Seems like you forgot to share the launch file. What exactly you want to achieve here?
Like @u1802520 says, your question refers to a launch file. Please share your launch file and useful information like the terminal output when you try to use roslaunch
For 1st part about topics quiz launch file is here below:
This is the output coming. But no simulation happening.
~user:~/catkin_ws/src/topics_quiz_last$ roslaunch topics_quiz_last topics_quiz.launch
… logging to /home/user/.ros/log/2abaf4a2-be14-11eb-a684-0242c0a89008/roslaunch-4_xterm-1531.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://4_xterm:33627/
SUMMARY
PARAMETERS
- /rosdistro: noetic
- /rosversion: 1.15.9
NODES
/
topic_quiz_node (topics_quiz_last/topics_quiz.py)
ROS_MASTER_URI=http://4_simulation:11311
process[topic_quiz_node-1]: started with pid [1539]
For 2nd part that is for services.
<node pkg = "unit_5_services_final" type = "bb8_move_in_circle_service_server.py" name = "service_move_bb8_in_circle_server" output = "screen"/>
Same problem like in the first case.
One more important thing is recently I tried creating one more package like this with rospy dependency with every file being same with the codes as I have shared even with file names and the procedure followed was also same but at the end when I launch it is displaying this launch file nor package is not correct.