Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 PKG = 'gazebo_taskboard'
00012 NAME = 'test_rocker_switch_a01'
00013
00014 import math
00015 import roslib
00016 roslib.load_manifest(PKG)
00017
00018 import sys, unittest
00019 import os, os.path, threading, time
00020 import rospy, rostest
00021
00022 from std_msgs.msg import String
00023 from helper import *
00024 from gazebo_taskboard.msg import *
00025 from gazebo_taskboard.srv import *
00026
00027 rocker_switch_state = 'CENTER'
00028 led_top_state = 'OFF'
00029 led_bottom_state = 'OFF'
00030
00031 def onMessage(message):
00032 global rocker_switch_state
00033 if rocker_switch_state != message.A01_ROCKER_SWITCH:
00034 rospy.loginfo("Rocker switch A01: " + message.A01_ROCKER_SWITCH)
00035 rocker_switch_state = message.A01_ROCKER_SWITCH
00036
00037 global led_top_state
00038 if led_top_state != message.A01_ROCKER_LED_TOP:
00039 rospy.loginfo("Rocker LED TOP: " + message.A01_ROCKER_LED_TOP)
00040 led_top_state = message.A01_ROCKER_LED_TOP
00041
00042 global led_bottom_state
00043 if led_bottom_state != message.A01_ROCKER_LED_BOTTOM:
00044 rospy.loginfo("Rocker LED BOTTOM: " + message.A01_ROCKER_LED_BOTTOM)
00045 led_bottom_state = message.A01_ROCKER_LED_BOTTOM
00046
00047
00048 class RockerSwitchA01Test(unittest.TestCase):
00049 def __init__(self, *args):
00050 super(RockerSwitchA01Test, self).__init__(*args)
00051
00052 def test_rocker_switch_a01(self):
00053 rospy.init_node(NAME, anonymous=True)
00054
00055 rospy.Subscriber(TOPIC_NAME, TaskboardPanelA, onMessage)
00056
00057 rospy.loginfo("Waiting for gazebo ...")
00058 rospy.wait_for_service(SERVICE_MANIPULATE_POWER_COVER)
00059 rospy.wait_for_service(SERVICE_MANIPULATE_POWER_SWITCH)
00060 rospy.wait_for_service(SERVICE_MANIPULATE_ROCKER_SWITCH)
00061 wait(GUI_WAIT_TIME)
00062 rospy.loginfo("Testing has started")
00063
00064 try:
00065 manipulatePowerCover = rospy.ServiceProxy(SERVICE_MANIPULATE_POWER_COVER, ManipulatePowerCover)
00066 manipulatePowerSwitch = rospy.ServiceProxy(SERVICE_MANIPULATE_POWER_SWITCH, ManipulatePowerSwitch)
00067 manipulateRockerSwitchA01 = rospy.ServiceProxy(SERVICE_MANIPULATE_ROCKER_SWITCH, ManipulateRockerSwitch)
00068
00069
00070
00071 manipulatePowerCover(deg2rad(50), 1)
00072 wait()
00073
00074 manipulatePowerSwitch(deg2rad(30), 1)
00075 wait()
00076
00077
00078
00079 manipulateRockerSwitchA01(10, 1)
00080 wait(4)
00081 assert rocker_switch_state == 'CENTER'
00082 assert led_top_state == 'OFF'
00083 assert led_bottom_state == 'OFF'
00084 rospy.loginfo("Case 1 Done.")
00085
00086
00087 manipulateRockerSwitchA01(10, 8)
00088 wait(1)
00089 assert rocker_switch_state == 'UP'
00090 assert led_top_state == 'ON'
00091 assert led_bottom_state == 'OFF'
00092 rospy.loginfo("Case 2 Done.")
00093
00094
00095 manipulateRockerSwitchA01(-10, 1)
00096 wait(4)
00097 assert rocker_switch_state == 'CENTER'
00098 assert led_top_state == 'OFF'
00099 assert led_bottom_state == 'OFF'
00100 rospy.loginfo("Case 3 Done.")
00101
00102
00103 manipulateRockerSwitchA01(-10, 8)
00104 wait(1)
00105 assert rocker_switch_state == 'DOWN'
00106 assert led_top_state == 'OFF'
00107 assert led_bottom_state == 'ON'
00108 rospy.loginfo("Case 4 Done.")
00109
00110
00111
00112 manipulatePowerSwitch(deg2rad(-30), 1)
00113 wait()
00114
00115 manipulatePowerCover(deg2rad(-50), 1)
00116 wait()
00117
00118
00119
00120 manipulateRockerSwitchA01(10, 8)
00121 wait(1)
00122 assert rocker_switch_state == 'UP'
00123 assert led_top_state == 'OFF'
00124 assert led_bottom_state == 'OFF'
00125 rospy.loginfo("Case 5 Done.")
00126
00127
00128 manipulateRockerSwitchA01(-10, 8)
00129 wait(1)
00130 assert rocker_switch_state == 'DOWN'
00131 assert led_top_state == 'OFF'
00132 assert led_bottom_state == 'OFF'
00133 rospy.loginfo("Case 6 Done.")
00134
00135
00136 wait(9)
00137 assert rocker_switch_state == 'CENTER'
00138 assert led_top_state == 'OFF'
00139 assert led_bottom_state == 'OFF'
00140 rospy.loginfo("Case 7 Done.")
00141
00142 except rospy.ServiceException, e:
00143 print "Service call failed: %s"%e
00144
00145 time.sleep(1.0)
00146
00147 if __name__ == '__main__':
00148 print "Waiting for test to start at time "
00149 rostest.run(PKG, 'test_rocker_switch_a01', RockerSwitchA01Test)