-
Notifications
You must be signed in to change notification settings - Fork 1
/
beep.py
executable file
·71 lines (60 loc) · 2.65 KB
/
beep.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
from __future__ import print_function
import rospy
import sys
from pyModbusTCP.client import ModbusClient
from geometry_msgs.msg import Twist
from waypoint_ui.srv import ModbusSetDigitalOutput
import argparse
class beep(object):
def __init__(self,delay):
self.pub = rospy.Publisher('/vector/navigation/cmd_vel', Twist, queue_size=10)
self.vel_value=None
self.for_waiting=0
self.stop_value=Twist()
self.stop_value.linear.x=0
self.stop_value.linear.y=0
self.stop_value.linear.z=0
self.stop_value.angular.x=0
self.stop_value.angular.y=0
self.stop_value.angular.z=0
self.time_when_stopped=Time=None
self.time_when_started_moving=None
self.delay=delay
rospy.Subscriber('/vector/navigation/cmd_vel_no_warning', Twist, self.callback, queue_size=10)
def set_digital_output(self,io_name, value):
rospy.wait_for_service('/waypoint_db/retrieve_waypoint', timeout=5.0)
self.set_output = rospy.ServiceProxy('modbus_manager/set_digital_output', ModbusSetDigitalOutput)
return self.set_output(io_name,value)
def check_if_moving(self):
if self.vel_value.linear.x!=0 or self.vel_value.linear.y!=0 or self.vel_value.linear.z!=0 or self.vel_value.angular.x!=0 or self.vel_value.angular.y!=0 or self.vel_value.angular.z!=0:
self.in_motion=1
elif self.vel_value.linear.x==0 or self.vel_value.linear.y==0 or self.vel_value.linear.z==0 or self.vel_value.angular.x==0 or self.vel_value.angular.y==0 or self.vel_value.angular.z==0:
self.in_motion=0
def callback(self,data):
self.time_when_started_moving =rospy.get_rostime()
self.vel_value=Twist()
self.vel_value = data
self.check_if_moving()
if self.for_waiting==0:
# self.set_digital_output("y1",True)
rospy.sleep(int(self.delay))
self.pub.publish(self.vel_value)
if self.in_motion==0:
self.time_when_stopped=rospy.get_rostime()
diff = self.time_when_stopped.secs - self.time_when_started_moving.secs
self.for_waiting=0
if diff>=5:
# self.set_digital_output("y1",False)
rospy.loginfo("Parked")
else:
self.for_waiting = 1
rospy.loginfo("beep")
if __name__ == "__main__":
rospy.init_node('beep')
parser = argparse.ArgumentParser(description='delay parser')
parser.add_argument('--delay', action="store", dest='delay', default=3)
args=parser.parse_args()
print (args.delay)
beep(args.delay)
rospy.spin()