Skip to content

Commit c1465fc

Browse files
authored
Merge pull request #24 from eiyooooo/master
提升可用性
2 parents 5c1e446 + f1cc761 commit c1465fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+380
-109
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
engines/
2+
.vscode/settings.json
3+
*.pyc
-1.13 KB
Binary file not shown.
-1.5 KB
Binary file not shown.
-1.14 KB
Binary file not shown.
-5.08 KB
Binary file not shown.
-2.97 KB
Binary file not shown.
-576 Bytes
Binary file not shown.

Control/controllers/purepursuit_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def Purepursuit(truck, nav_line):
66
robot_state = np.zeros(2) # 定义车辆位置
77
robot_state[0] = truck.x
8-
robot_state[1] = truck.y+60 # 后轴中心位置
8+
robot_state[1] = truck.y + truck.bev_l # 后轴中心位置
99
dx, dy = np.average(nav_line[-12:], axis=0) - robot_state
1010
alpha = np.arctan(-dx/dy) # dx, dy夹角
1111
ang = math.atan2(2.0 * truck.bev_l * np.sin(alpha), truck.ld) + 0.5 # pure pursuit controller

Control/drive.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ def __init__(self): # L:wheel base
1515
self.dtheta = 0
1616
self.ang = 0
1717
self.acc = 0
18-
self.l = 6.0 # 轴距
19-
self.bev_l = 60 # bev下轴距
18+
self.l = 12.0 # 轴距
19+
self.bev_l = 120 # bev下轴距
20+
self.ld = 120 # 预瞄距离
21+
self.lf = 160 # 预瞄距离补偿
2022
self.speed = 0 # 速度
2123
self.bev_speed = 0 # bev下的速度
2224
self.dv = 0 # 速度变量
23-
self.L = 6.0 # 车辆全长
24-
self.k = 1.0
25-
self.ld = self.k * self.bev_speed + self.L # 后轮到观察点距离
2625
self.dt = 0.2 # 决策间隔时间
2726
self.delta = 0 # 车辆与轨迹夹角
2827

@@ -32,13 +31,46 @@ def update(self, ang, acc, refer_time, speed): # update ugv's state
3231
self.dv = speed - self.speed
3332
self.speed = speed
3433
self.bev_speed = self.speed / 3.6 * 6
35-
self.ld = self.k * self.bev_speed + self.bev_l
34+
self.ld = 1.0 * self.bev_speed + self.lf
3635
self.dt = refer_time # 更新推理时间
3736
self.dx = self.speed * np.cos(self.theta) * self.dt
3837
self.dy = self.speed * np.sin(self.theta) * self.dt
3938
self.dtheta = self.speed * np.tan(self.ang) / self.l * self.dt
4039

4140

41+
class Info:
42+
def __init__(self):
43+
self.activeAP = False # 是否激活自动驾驶
44+
self.roads_type = 0 # 0:普通道路 1:高速公路 2:高速公路超车速度
45+
self.road_speed = [50, 50, 45, 40, 30] # 道路速度
46+
self.AP_exit_reason = 0 # 自动驾驶退出原因 0:正常退出 1:地图导航获取路线出错
47+
self.direction = 0 # -2: 左转 -1:左变道 0:直行 1:右变道 2:右转
48+
self.change_lane = 0 # <0:左变道 0:不变道 >0:右变道
49+
self.change_lane_dest = 0 # 变道目标车道
50+
51+
def update(self, roads_type): # 更新道路类型
52+
self.roads_type = roads_type
53+
self.AP_exit_reason = 0
54+
if self.roads_type == 0:
55+
self.road_speed[0] = 50
56+
self.road_speed[1] = 50
57+
self.road_speed[2] = 45
58+
self.road_speed[3] = 40
59+
self.road_speed[4] = 30
60+
elif self.roads_type == 1:
61+
self.road_speed[0] = 90
62+
self.road_speed[1] = 90
63+
self.road_speed[2] = 80
64+
self.road_speed[3] = 70
65+
self.road_speed[4] = 60
66+
elif self.roads_type == 2:
67+
self.road_speed[0] = 95
68+
self.road_speed[1] = 95
69+
self.road_speed[2] = 80
70+
self.road_speed[3] = 70
71+
self.road_speed[4] = 60
72+
73+
4274
def driver(ang, acc):
4375
j.data.wAxisX = int(ang * 32767)
4476
j.data.wAxisY = int(acc * 32767)

Navigation/BevDraw.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
import cv2
23
import numpy as np
34

@@ -93,7 +94,7 @@ def display_bev_lanes(bevmap, bev_lanes, stop_line, width=2):
9394

9495
return bevmap
9596

96-
def print_info(bevmap, refer_time, truck, speed_limit, state, weather):
97+
def print_info(bevmap, refer_time, truck, speed_limit, state, weather, info, planetrigger):
9798
cv2.putText(bevmap, 'Infer time: {:.4f}s'.format(refer_time), (10, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
9899
fontScale=0.5, color=(200, 200, 200), thickness=1)
99100
cv2.putText(bevmap, "Steer angle: {:.2f}".format((truck.ang - 0.5) * 180), (10, 30), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
@@ -104,10 +105,46 @@ def print_info(bevmap, refer_time, truck, speed_limit, state, weather):
104105
fontScale=0.5, color=(255, 255, 255), thickness=1)
105106
cv2.putText(bevmap, "power: {:.1f}".format((1-truck.acc)*10), (10, 75), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
106107
fontScale=0.5, color=(255, 255, 255), thickness=1)
108+
109+
110+
if not info.activeAP:
111+
cv2.putText(bevmap, "AP: inactive", (10, 120), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
112+
fontScale=0.5, color=(255, 255, 255), thickness=1)
113+
if info.AP_exit_reason == 1:
114+
cv2.putText(bevmap, "AP exited, please take control immediately!!!", (10, 332), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
115+
fontScale=0.5, color=(0, 0, 255), thickness=1)
116+
elif info.roads_type == 0:
117+
cv2.putText(bevmap, "AP: road", (10, 120), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
118+
fontScale=0.5, color=(255, 255, 255), thickness=1)
119+
elif info.roads_type == 1 or info.roads_type == 2:
120+
cv2.putText(bevmap, "AP: highway", (10, 120), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
121+
fontScale=0.5, color=(255, 255, 255), thickness=1)
122+
123+
124+
if info.direction == 0:
125+
cv2.putText(bevmap, "straight", (10, 135), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
126+
fontScale=0.5, color=(255, 255, 255), thickness=1)
127+
elif info.direction < 0:
128+
cv2.putText(bevmap, "left", (10, 135), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
129+
fontScale=0.5, color=(255, 255, 255), thickness=1)
130+
elif info.direction > 0:
131+
cv2.putText(bevmap, "right", (10, 135), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
132+
fontScale=0.5, color=(255, 255, 255), thickness=1)
133+
107134

108135
if state is not None:
109136
cv2.putText(bevmap, state, (10, 90), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
110137
fontScale=0.5, color=(255, 255, 255), thickness=1)
138+
139+
if state == 'Passing' or state == 'Follow':
140+
t = int(time.time() - planetrigger.t)
141+
if t > 45 or t < 0:
142+
t = 0
143+
cv2.putText(bevmap, "time: {}".format(t), (10, 150), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
144+
fontScale=0.5, color=(255, 255, 255), thickness=1)
145+
if state == 'Passing':
146+
cv2.putText(bevmap, "passing: {}".format(planetrigger.change_lane_state), (10, 165), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
147+
fontScale=0.5, color=(255, 255, 255), thickness=1)
111148

112149
cv2.putText(bevmap, "weather: {}".format(weather), (10, 105), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
113150
fontScale=0.5, color=(255, 255, 255), thickness=1)

0 commit comments

Comments
 (0)