-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.py
47 lines (40 loc) · 1.03 KB
/
auto.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
# -*- coding: utf-8 -*-
'''
Time: 2021/8/20 16:04
Author: Sanzo
Github: github.com/Sanzo00
Email: [email protected]
'''
from move import Move
from distance import Distance
import time
import collections
class Auto():
def __init__(self, move, distance):
self.distance = distance
self.move = move
self.off = False
self.pre = (0, 0) # time, distance
def stop(self):
self.off = True
def backoff(self):
old = self.move.speed_type
self.move.speed('medium')
self.move.back()
self.move.speed(old)
time.sleep(0.30)
# self.move.left45()
self.move.right45()
self.move.forward()
def go(self):
self.move.speed("slow")
self.move.forward()
while True:
if self.off is True: # exit the thread
self.move.stop()
break
dis = float(self.distance.dis()[:-3])
if time.time() - self.pre[0] > 1.5: # 2s
self.pre = (time.time(), dis)
if dis <= 30.0 or (time.time() - self.pre[0] > 1.0 and abs(dis - self.pre[1]) < 2):
self.backoff()