Got a result when we were already in the DONE state
Hi, I am trying to study the actionlib, I got the error in th client:
> Got a result when we were already in the DONE state
also I got another warn when I rosrun the client in the server:
[WARN] [WallTime: 1474144592.373342] Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.
Sometimes it retuns the good result and sometimes not.
I really want to figure out why that happens. I attached the code below:
fancyactionclient.py:
import rospy
import time
import actionlib
from talker_listern.msg import TimerAction, TimerFeedback, TimerGoal, TimerResult
def feedback_cb(feedback):
print ('[feedback] Time elapsed: %f'%(feedback.time_elapsed.to_sec()))
print ('[feedback] Time remaining: %f'%(feedback.time_remaining.to_sec()))
rospy.init_node('timer_action_client')
client = actionlib.SimpleActionClient('timer', TimerAction)
client.wait_for_server()
goal = TimerGoal()
goal.time_to_wait = rospy.Duration.from_sec(5.0)
client.send_goal(goal,feedback_cb=feedback_cb)
client.wait_for_result()
print('[Result] State: %d'%(client.get_state()))
print('[Result] Status: %s'%(client.get_goal_status_text()))
result = client.get_result()
print('[Result] Time elapsed: %f'%(result.time_elapsed.to_sec()))
print('[Result] Update sent: %d'%(result.updates_sent))
fancyactionserver.py:
import rospy
import actionlib
from talker_listern.msg import TimerAction, TimerGoal,TimerFeedback,TimerResult
import time
def do_timer(goal):
start_time = time.time()
update_count = 0
if goal.time_to_wait.to_sec() > 60.0:
result = TimerResult() # define a object
result.time_elapsed = rospy.Duration.from_sec(time.time()-start_time)
result.updates_sent = update_count
server.set_aborted(result,"Timer aborted due to too-long wait")
return
while (time.time()-start_time) < goal.time_to_wait.to_sec():
if (server.is_preempt_requested()):
result = TimerResult()
result.time_elapsed = rospy.Duration.from_sec(time.time()-start_time)
result.updates_sent = update_count
server.set_preempted(result,"Timer preempted")
return
feedback = TimerFeedback()
feedback.time_elapsed = rospy.Duration.from_sec(time.time()-start_time)
feedback.time_remaining = goal.time_to_wait-feedback.time_elapsed
server.publish_feedback(feedback)
update_count += 1
time.sleep(1.0)
result=TimerResult()
result.time_elapsed = rospy.Duration.from_sec(time.time()-start_time)
result.updates_sent = update_count
server.set_succeeded(result, "Timer completed successfully")
print '"result.updates_sent:" %d'%(result.updates_sent)
rospy.init_node('timer_action_server')
server = actionlib.SimpleActionServer('timer', TimerAction, do_timer, False)
server.start()
rospy.spin()
Asked by yunxiao on 2016-09-17 15:47:03 UTC
Comments
Would you mind adding the proper identation to the code?
Asked by joao.aguizo on 2021-09-28 07:43:27 UTC