test_toggle_a04.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 ##
00003 # Copyright (C) 2013 TopCoder Inc., All Rights Reserved.
00004 #
00005 # @author KennyAlive
00006 # @version 1.0
00007 #
00008 
00009 ## Tests for toggle a04
00010 
00011 PKG = 'gazebo_taskboard'
00012 NAME = 'test_toggle_a04'
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 toggle_a04_state = 'DOWN'
00028 toggle_a04_led_top_state = 'OFF'
00029 toggle_a04_led_bottom_state = 'OFF'
00030 
00031 def onMessage(message):
00032     global toggle_a04_state
00033     if toggle_a04_state != message.A04_TOGGLE:
00034         rospy.loginfo("Toggle A03: " + message.A04_TOGGLE)
00035     toggle_a04_state = message.A04_TOGGLE
00036     
00037     global toggle_a04_led_top_state
00038     if toggle_a04_led_top_state != message.A04_LED_TOP:
00039         rospy.loginfo("Toggle A04 TOP LED: " + message.A04_LED_TOP)
00040     toggle_a04_led_top_state = message.A04_LED_TOP
00041     
00042     global toggle_a04_led_bottom_state
00043     if toggle_a04_led_bottom_state != message.A04_LED_BOTTOM:
00044         rospy.loginfo("Toggle A04 BOTTOM LED: " + message.A04_LED_BOTTOM)
00045     toggle_a04_led_bottom_state = message.A04_LED_BOTTOM
00046     
00047 
00048 class ToggleA04Test(unittest.TestCase):
00049     def __init__(self, *args):
00050        super(ToggleA04Test, self).__init__(*args)
00051 
00052     def test_toggle_a04(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_SAFE_TOGGLE)
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             manipulateSafeToggle = rospy.ServiceProxy(SERVICE_MANIPULATE_SAFE_TOGGLE, ManipulateSafeToggle)
00068 
00069             # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00070             # Open power cover
00071             manipulatePowerCover(deg2rad(50), 1)
00072             wait()
00073             # Turn on power
00074             manipulatePowerSwitch(deg2rad(30), 1)
00075             wait()
00076             ## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00077             
00078             # Try to move up A04 toggle without pulling out. We should fail.
00079             manipulateSafeToggle(1, 1, deg2rad(40), 1)
00080             wait()
00081             assert toggle_a04_state == 'DOWN'
00082             assert toggle_a04_led_top_state == 'OFF'
00083             assert toggle_a04_led_bottom_state == 'ON'
00084             rospy.loginfo("Case 1 Done.")
00085 
00086             # Perform successful switch to UP state
00087             manipulateSafeToggle(1, 0, 10, 2)
00088             manipulateSafeToggle(1, 1, deg2rad(40), 1)
00089             wait(4)
00090             assert toggle_a04_state == 'UP'
00091             assert toggle_a04_led_top_state == 'ON'
00092             assert toggle_a04_led_bottom_state == 'OFF'
00093             rospy.loginfo("Case 2 Done.")
00094 
00095             # Go to the center position
00096             manipulateSafeToggle(1, 0, 10, 2)
00097             manipulateSafeToggle(1, 1, deg2rad(-26), 1)
00098             wait(4)
00099             assert toggle_a04_state == 'CENTER'
00100             assert toggle_a04_led_top_state == 'OFF'
00101             assert toggle_a04_led_bottom_state == 'OFF'
00102             rospy.loginfo("Case 3 Done.")
00103 
00104         except rospy.ServiceException, e:
00105             print "Service call failed: %s"%e
00106 
00107         time.sleep(3.0)
00108 
00109 if __name__ == '__main__':
00110     print "Waiting for test to start at time "
00111     rostest.run(PKG, 'test_toggle_a04', ToggleA04Test)


gazebo_taskboard
Author(s): TCSASSEMBLER
autogenerated on Mon Oct 6 2014 02:45:46