test_trigger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import sys
19 import unittest
20 
21 import rospy
22 import actionlib
23 from std_srvs.srv import Trigger, TriggerResponse
24 from move_base_msgs.msg import MoveBaseAction
25 from control_msgs.msg import FollowJointTrajectoryAction
26 from simple_script_server import *
28 
29 ## This test checks the correct call to commands from the cob_script_server. This does not cover the execution of the commands (this shoud be checked in the package where the calls refer to).
30 class TestTrigger(unittest.TestCase):
31  def __init__(self, *args):
32  super(TestTrigger, self).__init__(*args)
33  rospy.init_node('test_trigger')
34  self.cb_executed = False
35  self.component_name = "arm"
36  self.service_ns = "/" + self.component_name + "/driver"
37  rospy.set_param("/script_server/"+ self.component_name + "/service_ns", self.service_ns)
38  self.action_name = "/"+ self.component_name + "/joint_trajectory_controller/follow_joint_trajectory"
39  rospy.set_param("/script_server/"+ self.component_name + "/action_name", self.action_name)
40 
41  def test_init(self):
42  rospy.Service(self.service_ns + "/init", Trigger, self.srv_cb)
43  self.cb_executed = False
44  handle = sss.init(self.component_name)
45  if not self.cb_executed:
46  self.fail('sss.init() failed. script server error_code: ' + str(handle.get_error_code()))
47 
48  def test_stop(self):
49  as_name = "/move_base"
50  self.as_server = actionlib.SimpleActionServer(as_name, MoveBaseAction, execute_cb=self.action_cb)
51  handle = sss.stop("base")
52  if not handle.get_error_code() == 0:
53  self.fail('sss.stop("base") failed. script server error_code: ' + str(handle.get_error_code()))
54  handle = sss.stop("base", mode="omni")
55  if not handle.get_error_code() == 0:
56  self.fail('sss.stop("base", mode="omni") failed. script server error_code: ' + str(handle.get_error_code()))
57 
58  as_name = "/move_base_diff"
59  self.as_server = actionlib.SimpleActionServer(as_name, MoveBaseAction, execute_cb=self.action_cb)
60  handle = sss.stop("base", mode="diff")
61  if not handle.get_error_code() == 0:
62  self.fail('sss.stop("base", mode="diff") failed. script server error_code: ' + str(handle.get_error_code()))
63 
64  as_name = "/move_base_linear"
65  self.as_server = actionlib.SimpleActionServer(as_name, MoveBaseAction, execute_cb=self.action_cb)
66  handle = sss.stop("base", mode="linear")
67  if not handle.get_error_code() == 0:
68  self.fail('sss.stop("base", mode="linear") failed. script server error_code: ' + str(handle.get_error_code()))
69 
70  self.as_server = actionlib.SimpleActionServer(self.action_name, FollowJointTrajectoryAction, execute_cb=self.action_cb)
71  handle = sss.stop(self.component_name)
72  if not handle.get_error_code() == 0:
73  self.fail('sss.stop("arm") failed. script server error_code: ' + str(handle.get_error_code()))
74 
75  def test_recover(self):
76  rospy.Service(self.service_ns + "/recover", Trigger, self.srv_cb)
77  self.cb_executed = False
78  handle = sss.recover(self.component_name)
79  if not self.cb_executed:
80  self.fail('sss.recover() failed. script server error_code: ' + str(handle.get_error_code()))
81 
82  def test_halt(self):
83  rospy.Service(self.service_ns + "/halt", Trigger, self.srv_cb)
84  self.cb_executed = False
85  handle = sss.halt(self.component_name)
86  if not self.cb_executed:
87  self.fail('sss.halt() failed. script server error_code: ' + str(handle.get_error_code()))
88 
89  def srv_cb(self,req):
90  self.cb_executed = True
91  res = TriggerResponse()
92  res.success = True
93  return res
94 
95  def action_cb(self, goal):
96  while not self.as_server.is_preempt_requested():
97  rospy.Rate(1).sleep()
98  self.as_server.set_preempted()
99 
100 if __name__ == '__main__':
101  import rostest
102  rostest.rosrun('cob_script_server', 'trigger', TestTrigger)
def __init__(self, args)
Definition: test_trigger.py:31
def srv_cb(self, req)
Definition: test_trigger.py:89
def action_cb(self, goal)
Definition: test_trigger.py:95
This test checks the correct call to commands from the cob_script_server.
Definition: test_trigger.py:30


cob_script_server
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 03:03:06