ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

yunxiao's profile - activity

2021-09-24 08:51:23 -0500 received badge  Nice Question (source)
2020-01-22 00:07:43 -0500 received badge  Student (source)
2019-11-26 12:36:06 -0500 received badge  Taxonomist
2017-11-10 15:30:44 -0500 received badge  Famous Question (source)
2017-11-10 15:30:44 -0500 received badge  Popular Question (source)
2017-11-10 15:30:44 -0500 received badge  Notable Question (source)
2017-05-04 05:39:41 -0500 received badge  Famous Question (source)
2017-05-04 05:39:41 -0500 received badge  Notable Question (source)
2016-10-26 11:38:18 -0500 received badge  Popular Question (source)
2016-09-23 10:31:54 -0500 received badge  Enthusiast
2016-09-17 15:47:03 -0500 asked a question 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:

fancy_action_client.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))

fancy_action_server.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()
2016-07-21 01:04:19 -0500 asked a question no module named basics.srv

I swell I have tried several solutions existed, but none of them works. I am happening this problem when I try to learn from the book"programming robot with ros". I list the CMakeList.txt:

find_package(catkin REQUIRED COMPONENTS
            roscpp
            rospy
            std_msgs
            message_generation          #   Add message_generation  here,   after   the other   packages
)

add_service_files(
    FILES
    WordCount.srv
)

catkin_package(
    CATKIN_DEPENDS message_runtime
)

add_message_files(
    FILES
    Complex.msg
)

generate_messages(
    DEPENDENCIES
    std_msgs
)

rosbuild_init()

#uncomment if you have defined messages
rosbuild_genmsg()

#uncomment if you have defined services
rosbuild_gensrv()

Also I list the package.xml :

  <build_depend>rospy</build_depend>
  <run_depend>rospy</run_depend>
  <build_depend>message_generation</build_depend>
  <run_depend>message_runtime</run_depend>
  <depend package="rospy" />
  <depend package="actionlib_msgs" />

Actually I can find it with the command rossrv list, it shows basics/WordCount. The python file:

#!/usr/bin/env python

import rospy

from basics.srv import WordCount,WordCountResponse


def count_words(request):
    return WordCountResponse(len(request.words.split()))


rospy.init_node('service_server')

service = rospy.Service('word_count', WordCount, count_words)

rospy.spin()

So what a possible reason for that? it has took me a night to solve, but nothing works out.

2016-07-21 01:04:19 -0500 asked a question Error: No module named basics.srv

I have checked several solutions, but they can not solve my problem. The CMakeList.txt: ............................

find_package(catkin REQUIRED COMPONENTS
        roscpp
        rospy
        std_msgs
        message_generation          #   Add message_generation  here,   after   the other   packages

)

add_service_files(
FILES
WordCount.srv

)

catkin_package(
CATKIN_DEPENDS message_runtime

)

add_message_files(
FILES
Complex.msg

)

generate_messages(
DEPENDENCIES
std_msgs

)

rosbuild_init()
rosbuild_genmsg()
rosbuild_gensrv()

The package.xml:

 `<build_depend>rospy</build_depend>`
 <run_depend>rospy</run_depend>
<build_depend>message_generation</build_depend>
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
<depend package="rospy" />
 <depend package="actionlib_msgs" />

I use the rossrv list, I can see basics/WordCount. The following are the python code:

#!/usr/bin/env python

import rospy

from basics.srv import WordCount,WordCountResponse


def count_words(request):
return WordCountResponse(len(request.words.split()))
rospy.init_node('service_server')

service = rospy.Service('word_count', WordCount, count_words)

rospy.spin()

So what should be possible reason for that?