-
Notifications
You must be signed in to change notification settings - Fork 1
/
robot.py
executable file
·56 lines (40 loc) · 1.49 KB
/
robot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import rospy
import sys
from std_msgs.msg import Int32
from std_msgs.msg import Bool
from std_msgs.msg import String
class Robot():
def __init__ (self):
self.distance = 0
self.Trigger = False
self.response = False
self.lastResponse = False
self.loop_rate = rospy.Rate(10)
#Subscriber for the distance from utrasound
rospy.Subscriber("sensorData", Int32, self.callbackDist)
#Subscriber for trigger from ultrasound. (3seconds+ in front of the ultrasound within 30cm)
rospy.Subscriber("triggerData", Bool, self.callbackTrig)
self.pub = rospy.Publisher("/cyborg_controller/register_event", String, queue_size=10)
# takes in the data
def callbackDist(self, data):
self.distance = data.data
rospy.loginfo(self.distance)
def callbackTrig(self, data):
self.trigger = data.data
rospy.loginfo(self.trigger)
def run(self):
while not rospy.is_shutdown():
if(self.distance < 20):
self.lastResponse = self.response
self.response = True
else:
self.lastResponse = self.response
self.response = False
if(self.response and not self.lastResponse):
self.pub.publish("obstructionEvent")
self.loop_rate.sleep()
if __name__ == '__main__':
rospy.init_node("robotNode", anonymous = True)
robot = Robot()
robot.run()