simple_action_server_deadlock_companion.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 #
3 # Copyright (c) 2013, Miguel Sarabia
4 # Imperial College London
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of Imperial College London nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31 
32 
33 class Constants:
34  node = "simple_action_server_deadlock_companion"
35  topic = "deadlock"
36  max_action_duration = 3
37 
38 
39 import random
40 
41 import actionlib
42 from actionlib.msg import TestAction, TestGoal
43 from actionlib_msgs.msg import GoalStatus
44 import rospy
45 
46 
48 
49  def __init__(self):
50  # Seed random with fully resolved name of node and current time
51  random.seed(rospy.get_name() + str(rospy.Time.now().to_sec()))
52 
53  # Create actionlib client
55  Constants.topic,
56  TestAction)
57 
58  def run(self):
59  while not rospy.is_shutdown():
60  # Send dummy goal
61  self.action_client.send_goal(TestGoal())
62 
63  # Wait for a random amount of time
64  action_duration = random.uniform(0, Constants.max_action_duration)
65  self.action_client.wait_for_result(rospy.Duration(action_duration))
66 
67  state = self.action_client.get_state()
68  if state == GoalStatus.ACTIVE or state == GoalStatus.PENDING:
69  self.action_client.cancel_goal()
70 
71 
72 if __name__ == '__main__':
73  rospy.init_node(Constants.node)
74  try:
75  companion = DeadlockCompanion()
76  companion.run()
77  except (KeyboardInterrupt, SystemExit):
78  raise
79  except:
80  pass
A Simple client implementation of the ActionInterface which supports only one goal at a time...


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Mon Aug 24 2020 03:40:47