-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnocontrol_collect_line_data.py
90 lines (82 loc) · 2.43 KB
/
nocontrol_collect_line_data.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from joystick import JoyStick
from cart import Cart
import time
import cv2
import threading
import json
import config
from myfun import _main
#本文件用作无人驾驶车道数据采集
#本文将使用不使用手柄采集
cart = Cart()
class Logger:
def __init__(self):
self.camera = cv2.VideoCapture(config.front_cam)
self.started = False
self.stopped_ = False
self.counter = 3000
self.map = {}
self.last_x=0
self.result_dir = "/run/media/sda1/xunxian7_8_14/"
def start(self):
self.started = True
cart.steer(0)
pass
def stop(self):
if self.stopped_:
return
self.stopped_ = True
cart.stop()
path = "{}/result.json".format(self.result_dir)
with open(path, 'w') as fp:
json.dump(self.map.copy(), fp)
pass
def log(self, axis):
if self.started :
#print("axis:".format(axis))
#cart.steer(axis)
return_value, image = self.camera.read()
differ,_,self.last_x=_main(image,self.last_x)
if differ>1:
differ=1
elif differ<-1:
differ=-1
cart.steer(differ)
print('differ',differ)
path = "{}/{}.jpg".format(self.result_dir, self.counter)
self.map[self.counter] = differ
cv2.imwrite(path, image)
self.counter = self.counter + 1
def stopped(self):
return self.stopped_
js = JoyStick()
logger = Logger()
def joystick_thread():
js.open()
while not logger.stopped():
time, value, type_, number = js.read()
if js.type(type_) == "button":
#print("button:{} state: {}".format(number, value))
if number == 6 and value == 1:
logger.start()
if number == 7 and value == 1:
logger.stop()
if js.type(type_) == "axis":
print("axis:{} state: {}".format(number, value))
if number == 2:
# handle_axis(time, value)
js.x_axis = value * 1.0 / 32767
def main():
t = threading.Thread(target=joystick_thread, args=())
t.start()
cart.velocity=-25
# logger.start()
while not logger.stopped():
# time.sleep(0.01)
logger.log(js.x_axis)
t.join()
cart.stop()
if __name__ == "__main__":
main()