Why have I State 1 when I return the feedback (current_state)?
My server_action_client give a feedback when success it’s true. So why my result_state is 1?
In this case, my robot keep moving because result_state >=2 is False. Despite the feedback has given.
Also, my robot stop a few seconds later and return the feedback again, but this time es 9!
Okay, first things first, When you post an error that is not a general error that you can search on the internet, you need to add supporting documents like your program code.
Looking at your error, it is very clear that you have a problem in your code, and you have done it without your knowledge.
In most cases, if the error is absurd or very specific, it is the error on the program code made by the programmer (which is you!).
If you need help fixing this, you need to provide your code so that we can help you out.
Please tell us what you are working on. From the output of your terminal I am sure you are working on ROS1 Basics Project, but I am not sure if it is Python or C++.
Also, please avoid using words like “Help” in the title. It is obvious that if someone posts in the forum, they are looking for help. You do not have to state the obvious.
Okay, I deleted these lines.
Is it okay that the robot keep moving for a 1-2 seconds, and then stop cause the result state = 9?
I just made only the changes that u said
That means when I print the result from callback the result is still 1, like in the first photo I sent, could you tell me why it doesn’t change to 2?
The action server successfully breaks out the loop when state >= 2, but since the state is 9, your client does not know that the goal is lost.
I am certain that your code has a problem. So when you call your action server using your action client program, I guess something happens on the action client side that it is unable to communicate with the server, although the server is (?) available.
The best way to debug your code is to make the action server and client separately and check if server and client code functions.
So do the following steps to check:
Create the action server with goal callback making the robot move for few (5 to 15) seconds. Record the odometry and send the result once complete.
Create the action client to just call the action server.
Once you get them working separately, you can integrate them into your main code.
I tried to do what you said and it works!
state_result returns 3 now, I though it returns that because the action_server stops before/after the client and I tried both, but I have the same state_result = 3.
Some advice?
I just change one line code on time_to_move (while condition)
def time_to_move(self):
rospy.loginfo("Time to move! Advance and follow the wall")
self._stop()
# Wait for the action server
self.action_client.wait_for_server()
goal = OdomRecordGoal()
self.action_client.send_goal(goal, feedback_cb=self._feedback_callback)
state_result = self.action_client.get_state()
while self._feedback.current_total < 1.0:
# + angular : left
# - angular : right
self.move.linear.x = 0.06
if((0.3 >= self.laser["right_laser"] and self.laser["right_laser"] >= 0.2) and 0.51 < self.laser["front_laser"]):
self.move.angular.z = 0.0
rospy.logdebug("Forward!")
elif 0.5 > self.laser["front_laser"]:
self.move.angular.z = 0.35
rospy.logdebug("Corner!")
elif self.laser["right_laser"] > 0.3:
self.move.angular.z = -0.080
rospy.logdebug("Turn to right!")
elif self.laser["right_laser"] < 0.2:
self.move.angular.z = 0.085
rospy.logdebug("Turn to left!")
self.vel_pub.publish(self.move)
state_result = self.action_client.get_state()
rospy.logdebug(state_result)
self._rate.sleep()
if state_result >= 2:
break
"""
PENDING = 0
ACTIVE = 1
DONE = 2
WARN = 3
ERROR = 4
"""
self._stop()
state_result = self.action_client.get_state()
rospy.loginfo("[Result] State: " + str(state_result))
if state_result == 2: # DONE
rospy.logerr("Project done!")
if state_result == 3: # WARN
rospy.logerr("There is a warning in the Server Side")
if state_result == 4: # ERROR
rospy.logwarn("There is a error in the Server Side")
def _feedback_callback(self, feedback):
self.current_distance = feedback.current_total
rospy.loginfo("Current distance: " + str(feedback.current_total))
if __name__ == "__main__":
# Create a node
rospy.init_node("wall_follower", anonymous=True, log_level=rospy.INFO)
robot_control = Robot()
try:
robot_control.time_to_move()
robot_control._stop()
except rospy.ROSInterruptException:
rospy.signal_shutdown("")
The good news is you have it working!
The warning is just stating that once the goal was complete, the action server completed the procedure.
This is clearly explained in the course tutorial. The paragraph on TCP/IP connection termination.
This is not something to worry about. But there is a way to get rid of this.
You can implement exception handling (try-except blocks) in python.
I am not going to tell you what to do, but a hint that I can provide you is: use try-except block in action server code.
You can also just ignore the warning and continue but that is your choice.
I also noticed something else in your code: your feedback is just printed once.
Are you updating the feedback every 1 second (as per the instructions)? So you must be getting a few feedback messages when the action is taking place.
You seem to have just one “reading” for the current_total, and that is right before the action is complete.
You need to implement the above logic correctly.
Ohh I don’t think that it was a problem.
It’s part of my code hahaha
state_result = self.action_client.get_state()
rospy.loginfo("[Result] State: " + str(state_result))
if state_result == 2: # DONE
rospy.logerr("Project done!")
if state_result == 3: # WARN
rospy.logerr("There is a warning in the Server Side")
if state_result == 4: # ERROR
rospy.logwarn("There is a error in the Server Side")
I guess I change the message that prints the condition
It is not a part of “your” code, rather it is a part of the code given to you.
Also, the indication of warning is actually correct. So you must find a way to get rid of that error. And, it is not by deleting that line from the code.
I have retained all these lines in my project and just got rid of the warning.