forked from ecwolf/p4_robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
123 lines (99 loc) · 3.61 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# BSD 3-Clause License
# Copyright (c) 2019, Fabricio Rodriguez, UNICAMP, Brazil
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import re
import string
import sys
import random
import socket
from random import shuffle
import argparse
from argparse import ArgumentParser
from subprocess import call
import collections
import time
#from lib.test_2 import *
def main(delay_ms):
#parser = ArgumentParser(description='Robot + P4', formatter_class=SmartFormatter)
#parser.add_argument('-t','--time', metavar='',
# help="R|Delay:\n",
# dest='delay', action="store", type=float, default='0')
#args = parser.parse_args()
delay = float(delay_ms)
HOST = "192.168.10.3" # The remote host
PORT = 30000 # The same port as used by the server
count = 0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT)) # Bind to the port
s.listen(5) # Now wait for client connection.
c, addr = s.accept()
print ("Starting RX")
print ("Delay ", delay)
val=0
val1=0
while (count < 1000):
try:
msg = c.recv(1024)
#print ("Pose Position = ", val,msg)
#print (datetime.now().strftime("%H:%M:%S.%f"))
#print ("Pose Position = ", val,msg)
msg2 = msg.split(",")
msg3 = msg2[0].split("[")
msg4=list(msg3[1])
#print(msg3[1])
msg5=float(msg3[1])
#print(msg5)
#print ("MATCH len ", len(msg4))
val=val+1
#print ("Pose Position = ", val,msg)
if msg5 >= 1.88:
#if 0 <= 5 <= len(msg4):
# if msg4[0] == "1":
# if msg4[2] == "8":
# print(msg4)
# if int(msg4[3]) > 7:
#if msg4[4] == "4" or msg4[4] == "5":
print(msg5)
print("------YES_______")
time.sleep(delay)
c.send("(0)");
val1=1
if val1 == 1:
print ("Pose Position = ", val,msg)
val1 = 0
s.close()
c.close()
#count = 1000
except socket.error as socketerror:
count = count + 1
s.close()
c.close()
print ("Program finish")
delay = [0,0.005,0.01,0.015,0.025,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5]
print delay
val = 0
for val in range(0,len(delay)):
main(delay[val])