Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 PKG = 'gazebo_taskboard'
00012 NAME = 'test_power_cover'
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 last_state = 'DOWN'
00028
00029 def onMessage(msg):
00030 global last_state
00031 if last_state != msg.PANEL_POWER_COVER:
00032 rospy.loginfo("NEW STATE: " + msg.PANEL_POWER_COVER)
00033 last_state = msg.PANEL_POWER_COVER
00034
00035 class PowerCoverTest(unittest.TestCase):
00036 def __init__(self, *args):
00037 super(PowerCoverTest, self).__init__(*args)
00038
00039 def test_power_cover(self):
00040 rospy.init_node(NAME, anonymous=True)
00041
00042 rospy.Subscriber(TOPIC_NAME, TaskboardPanelA, onMessage)
00043
00044 rospy.loginfo("Waiting for gazebo ...")
00045 rospy.wait_for_service(SERVICE_MANIPULATE_POWER_COVER)
00046 wait(GUI_WAIT_TIME)
00047 rospy.loginfo("Test started.")
00048
00049 try:
00050 manipulatePowerCover = rospy.ServiceProxy(SERVICE_MANIPULATE_POWER_COVER, ManipulatePowerCover)
00051
00052 manipulatePowerCover(deg2rad(20), 0.5)
00053 wait()
00054 assert last_state == 'DOWN'
00055 rospy.loginfo("Case 1 Done.")
00056
00057 manipulatePowerCover(deg2rad(40), 0.75)
00058 wait()
00059 assert last_state == 'DOWN'
00060 rospy.loginfo("Case 2 Done.")
00061
00062 manipulatePowerCover(deg2rad(50), 1)
00063 wait()
00064 assert last_state == 'UP'
00065 rospy.loginfo("Case 3 Done.")
00066
00067 manipulatePowerCover(deg2rad(-25), 0.5)
00068 wait()
00069 assert last_state == 'UP'
00070 rospy.loginfo("Case 4 Done.")
00071
00072 manipulatePowerCover(deg2rad(-40), 0.5)
00073 wait()
00074 assert last_state == 'UP'
00075 rospy.loginfo("Case 5 Done.")
00076
00077 manipulatePowerCover(deg2rad(-50), 0.5)
00078 wait()
00079 assert last_state == 'DOWN'
00080 rospy.loginfo("Case 6 Done.")
00081
00082 manipulatePowerCover(deg2rad(70), 0.75)
00083 wait()
00084 assert last_state == 'UP'
00085 rospy.loginfo("Case 7 Done.")
00086
00087 manipulatePowerCover(deg2rad(-80), 1.0)
00088 wait()
00089 assert last_state == 'DOWN'
00090 rospy.loginfo("Case 8 Done.")
00091
00092 except rospy.ServiceException, e:
00093 print "Service call failed: %s"%e
00094
00095 time.sleep(2.0)
00096
00097 if __name__ == '__main__':
00098 print "Waiting for test to start at time "
00099 rostest.run(PKG, 'test_power_cover', PowerCoverTest)