when i start my realrobot session i really faced that problem many times the node is running every thing is perfect for the first seconds but then the robot freeze and do not move again until i terminate the program and starts it from the beginning my programm runs on the simulation without any error so what the causing of this i am very frustrated as this is the second session this happens to me
Hi @80601 ,
Additional information is required to diagnose if this problem is because of program or the robot itself.
Since you have not shared a video or screenshot of your problem, could you please tell when the problem happens?
What all tasks the robot successfully completes?
Briefly describe what all you do once the real robot session starts and at which point the robot freezes?
This info can help identify what type of issue you have.
Regards,
Girish
PS: Please use some Sentence Punctuation when you type your questions. You have basically typed one huge single sentence that is 4 lines long and does not end with a full-stop / period.
first : the robot reaches the wall successfully and the service is done.
second: the action server starts successfully.
third: the main program (wall following) starts and perform as expected for the first two seconds, then the robot stops moving.
in the screenshot you will be seeing the action server working and publishing (the robot is not moving) ,
you will be also able to see the main program publishing the laser front readings.
Hi @80601 ,
From your front laser scan output, I infer that your laser scan callback is not functioning well.
This is an issue in your programming side. You need to check your wall_follower code.
You can post your code here, I can probably debug and/or give you some suggestions to get your program working.
Please post your code as a Markdown Code-Block - this will help us help you better!
Regards,
Girish
here is the main file.
#! /usr/bin/env python
import time
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
from project.srv import FindWall, FindWallRequest
import actionlib
from project.msg import OdomRecordAction, OdomRecordGoal
from std_msgs.msg import Empty
def callback(msg):
rospy.loginfo("the distance in front of robot"+str(msg.ranges[360]))
if msg.ranges[360] > 0.5:
# perform wallfollower programm
if msg.ranges[180] > 0.3:
# approach the wall slowly
move.linear.x = 0.06
move.angular.z = -0.06
pub.publish(move)
elif msg.ranges[180] < 0.2:
# get away from the wall slowly
move.linear.x = 0.06
move.angular.z = 0.06
pub.publish(move)
elif (2 > msg.ranges[180] > 0.3):
# keep moving forward
move.linear.x = 0.06
move.angular.z = 0
pub.publish(move)
elif msg.ranges[360] < 0.5:
# turn left while moving forward
move.linear.x = 0.06
move.angular.z = 0.43 # left
pub.publish(move)
state_result = action_client.get_state()
if state_result == DONE:
rospy.loginfo("the action is done succesfully")
rospy.loginfo(action_client.get_result())
if __name__ == "__main__":
####service####
rospy.init_node("project_node") # start the node
rospy.wait_for_service('/find_wall') # wait till the service is available
FindWall_service = rospy.ServiceProxy(
'/find_wall', FindWall) # connect to teh service
result = FindWall_service(FindWallRequest()) # send the request
print(result)
####acttion####
PENDING = 0
ACTIVE = 1
DONE = 2
WARN = 3
ERROR = 4
nImage = 1
def feedback_callback(feedback):
print("feedback from action server:\ntotall distance moved so far\n"+str(feedback))
action_server_name = 'record_odom'
action_client = actionlib.SimpleActionClient(
action_server_name, OdomRecordAction) # establish the action client
rospy.loginfo('Waiting for action Server '+action_server_name)
action_client.wait_for_server()
rospy.loginfo('Action Server Found...'+action_server_name)
# send empty goal to start the action
action_client.send_goal(Empty(), feedback_cb=feedback_callback)
# initially it will be zero means pending
state_result = action_client.get_state()
rate = rospy.Rate(1)
rospy.loginfo("state_result: "+str(state_result))
####wall_following####
pub = rospy.Publisher("/cmd_vel", Twist, queue_size=1)
move = Twist()
rospy.loginfo("start wall fllowing")
# subscriber
sub = rospy.Subscriber("/scan", LaserScan, callback)
rospy.wait_for_message("/scan", LaserScan)
rospy.spin()
Hi @80601 ,
I am not sure if this line will be properly evaluated. Change it to:
elif ((msg.ranges[180] < 2.0) and (msg.ranges[180] > 0.3))
.
You do not need nImage
since you are not acquiring any image data.
You do not need wait_for_message
. Laser scanner provides data at 30 Hz (if I am correct) - which is 30 messages per second. wait_for_message
is only required where message acquisition is slow - like 1 message every 5 or 10 or 30 seconds.
Try to avoid controlling the robot in the scan callback. Use the scan callback to just get the values. Perform robot control in the while not ros.is_shutdown()
loop.
Also, you need to redesign your code - right now, you have just copy-pasted the code from tutorial notes and just modified the necessary values to suit the rosject. This is bad programming.
Add classing (OOPS) to your code. That will make the code easily readable to you (and for others).
Since your program logic is quite simple, I believe the issue is in the scan callback function in the elif
condition that I have mentioned above (in this post). if you fix that, your robot might respond better.
Try this fix and let me know if you still have issues. Please try to use OOPS concepts.
Regards,
Girish