elevator.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 random
20 
21 import rospy
22 from gazebo_msgs.msg import ContactsState
23 from std_msgs.msg import Float64
24 
25 door_closed = True
26 
27 def callback(ContactsState):
28 
29  if door_closed:
30  if (ContactsState.states != []):
31  rospy.loginfo("button pressed")
32  rand = (random.randint(0,1))
33  if rand == 0:
34  move_door("left")
35  else:
36  move_door("right")
37  else:
38  rospy.logdebug("button not pressed")
39  else:
40  rospy.loginfo("Door Opened")
41 
42 def listener():
43 
44  rospy.init_node('listener', anonymous=True)
45  rospy.Subscriber("/elevator_button1_bumper", ContactsState, callback, queue_size=1)
46  rospy.spin()
47 
48 def move_door(side):
49 
50  door_closed = False
51  topic_name = '/world/elevator_%s_joint_position_controller/command' %side
52  pub = rospy.Publisher(topic_name,Float64,queue_size=10)
53  rospy.sleep(1)
54  pos = 0.87
55  pub.publish(pos)
56 
57  rospy.loginfo("%s door is opening" %side)
58 
59  try:
60  rospy.sleep(10)
61  except rospy.exceptions.ROSInterruptException:
62  return
63 
64  pos = 0
65  rospy.loginfo("%s door is closing" %side)
66  pub.publish(pos)
67 
68  try:
69  rospy.sleep(10)
70  except rospy.exceptions.ROSInterruptException:
71  return
72 
73  door_closed = True
74 
75 if __name__ == '__main__':
76  listener()
77 
78 
79 
def listener()
Definition: elevator.py:42
def move_door(side)
Definition: elevator.py:48
def callback(ContactsState)
Definition: elevator.py:27


cob_gazebo_worlds
Author(s): Felix Messmer , Nadia Hammoudeh Garcia , Florian Weisshardt
autogenerated on Fri Mar 20 2020 04:01:38