elevator.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #################################################################
00003 ##\file
00004 #
00005 # \note
00006 # Copyright (c) 2012 \n
00007 # Fraunhofer Institute for Manufacturing Engineering
00008 # and Automation (IPA) \n\n
00009 #
00010 #################################################################
00011 #
00012 # \note
00013 # Project name: Care-O-bot
00014 # \note
00015 # ROS stack name: cob_environments
00016 # \note
00017 # ROS package name: cob_gazebo_worlds
00018 #
00019 # \author
00020 # Author: Nadia Hammoudeh Garcia
00021 # \author
00022 # Supervised by: Nadia Hammoudeh Garcia
00023 #
00024 # \date Date of creation: 26.06.2012
00025 #
00026 #
00027 #################################################################
00028 #
00029 # Redistribution and use in source and binary forms, with or without
00030 # modification, are permitted provided that the following conditions are met:
00031 #
00032 # - Redistributions of source code must retain the above copyright
00033 # notice, this list of conditions and the following disclaimer. \n
00034 # - Redistributions in binary form must reproduce the above copyright
00035 # notice, this list of conditions and the following disclaimer in the
00036 # documentation and/or other materials provided with the distribution. \n
00037 # - Neither the name of the Fraunhofer Institute for Manufacturing
00038 # Engineering and Automation (IPA) nor the names of its
00039 # contributors may be used to endorse or promote products derived from
00040 # this software without specific prior written permission. \n
00041 #
00042 # This program is free software: you can redistribute it and/or modify
00043 # it under the terms of the GNU Lesser General Public License LGPL as
00044 # published by the Free Software Foundation, either version 3 of the
00045 # License, or (at your option) any later version.
00046 #
00047 # This program is distributed in the hope that it will be useful,
00048 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00049 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00050 # GNU Lesser General Public License LGPL for more details.
00051 #
00052 # You should have received a copy of the GNU Lesser General Public
00053 # License LGPL along with this program.
00054 # If not, see <http://www.gnu.org/licenses/>.
00055 #
00056 #################################################################
00057 
00058 import time
00059 import sys
00060 import roslib
00061 roslib.load_manifest('cob_gazebo_worlds')
00062 import rospy
00063 import random
00064 from math import *
00065 
00066 #from gazebo.srv import *
00067 from gazebo_msgs.srv import *
00068 from gazebo_msgs.msg import *
00069 
00070 
00071 apply_effort_service = rospy.ServiceProxy('/gazebo/apply_joint_effort', ApplyJointEffort)
00072 door_closed = True
00073 
00074 
00075 
00076 def callback(ContactsState):
00077 
00078         if door_closed:
00079                 if (ContactsState.states != []):
00080                         rospy.loginfo("button pressed") 
00081                         rand = (random.randint(0,1))
00082                         if rand == 0:
00083                                 move_door("left")
00084                         else:
00085                                 move_door("right")
00086                 else:
00087                         rospy.logdebug("button not pressed")
00088         else:
00089                 rospy.loginfo("Door Opened")
00090 
00091 
00092 
00093 def listener():
00094     
00095     rospy.init_node('listener', anonymous=True)
00096     rospy.Subscriber("/elevator_button1_bumper/state", ContactsState, callback, queue_size=1)
00097     rospy.spin()
00098 
00099 def move_door(side):
00100 
00101         door_closed = False
00102         req = ApplyJointEffortRequest()
00103         req.joint_name = 'joint_elevator_'+side
00104         req.start_time.secs = 0
00105         req.duration.secs = -10
00106         req.effort = 500
00107         rospy.loginfo("door is opening")
00108         res = apply_effort_service(req)
00109 
00110         rospy.sleep(10)
00111         req.effort = -1000
00112         rospy.loginfo("door is closing")
00113         res = apply_effort_service(req)
00114 
00115         rospy.sleep(10)
00116         req.effort = 500
00117         res = apply_effort_service(req)
00118         door_closed = True
00119 
00120 
00121 if __name__ == '__main__':
00122     listener()
00123 
00124 
00125 


cob_gazebo_worlds
Author(s): Florian Weisshardt
autogenerated on Thu Aug 27 2015 12:48:11