Skip to content
Snippets Groups Projects
Commit 20d02045 authored by Ouhouuhu's avatar Ouhouuhu
Browse files

possibilite de conduire la voiture pour avoir commande fiable

parent aa0c4529
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ def close_ser(ser): ...@@ -14,7 +14,7 @@ def close_ser(ser):
ser.close() ser.close()
def send_infos(ser, a,b,c): def send_infos(ser, a,b,c):
n = str(a)+' '+str(b)+' '+str(c) n = f"['{a} {b} {c}']"
#print("input: "+str(n)) #print("input: "+str(n))
ser.write((str(n)+'\n').encode("utf-8")) ser.write((str(n)+'\n').encode("utf-8"))
cc=str(ser.readline()) cc=str(ser.readline())
......
import keyboard
def get_command():
forward = 0
direction = 30
if keyboard.is_pressed('q'):
direction=-50
elif keyboard.is_pressed('d'):
direction=110
if keyboard.is_pressed('z'):
forward = 10
if keyboard.is_pressed('s'):
forward = -10
return forward, direction, 0
\ No newline at end of file
...@@ -27,7 +27,7 @@ from shapely.geometry import Polygon, Point, LineString ...@@ -27,7 +27,7 @@ from shapely.geometry import Polygon, Point, LineString
from yolov3.car_interface import get_ser, start_ser, close_ser, send_infos from yolov3.car_interface import get_ser, start_ser, close_ser, send_infos
from MCL import get_position from MCL import get_position
import yolov3.pilote as pilot
class liste_pos: class liste_pos:
...@@ -221,24 +221,26 @@ def draw_bbox(image, bboxes,liste_pos_car, CLASSES=YOLO_COCO_CLASSES, show_label ...@@ -221,24 +221,26 @@ def draw_bbox(image, bboxes,liste_pos_car, CLASSES=YOLO_COCO_CLASSES, show_label
plt.plot([i for i,j in track_points], [j for i,j in track_points]) plt.plot([i for i,j in track_points], [j for i,j in track_points])
plt.show() plt.show()
speed, commande, a = pilot.get_command()
"""calculate distance""" """calculate distance"""
front_center = Point(np.array([x_car,y_car])) #front_center = Point(np.array([x_car,y_car]))
error = track.distance(front_center) #error = track.distance(front_center)
"""calculate PID response""" """calculate PID response"""
pid = PidController(50,0.005,5) #P, I, D #pid = PidController(50,0.005,5) #P, I, D
commande = pid.get_control(error) #commande = pid.get_control(error)
commande -= 30 #commande -= 30
print(f"command: {commande}") print(f"command: {commande}")
"""sending info to car""" """sending info to car"""
try: try:
print(f"poten: {send_infos(ser,10,commande,0)}") print(f"poten: {send_infos(ser,speed,commande,0)}")
except: except:
pass pass
return image, commande, liste_pos_car return image, speed, commande, liste_pos_car
def bboxes_iou(boxes1, boxes2): def bboxes_iou(boxes1, boxes2):
...@@ -584,11 +586,12 @@ def detect_realtime(Yolo, output_path, input_size=416, show=False, CLASSES=YOLO_ ...@@ -584,11 +586,12 @@ def detect_realtime(Yolo, output_path, input_size=416, show=False, CLASSES=YOLO_
codec = cv2.VideoWriter_fourcc(*'XVID') codec = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(output_path, codec, fps, (width, height)) # output_path must be .mp4 out = cv2.VideoWriter(output_path, codec, fps, (width, height)) # output_path must be .mp4
liste_pos_car = liste_pos((278/225, 200/225,3.1415/2), 50) liste_pos_car = liste_pos((1, 0.5,3.1415/2), 50)
ser = get_ser() ser = get_ser()
start_ser(ser) start_ser(ser)
command=0 command=0
speed=0
while True: while True:
ret, frame = vid.read() ret, frame = vid.read()
...@@ -633,7 +636,7 @@ def detect_realtime(Yolo, output_path, input_size=416, show=False, CLASSES=YOLO_ ...@@ -633,7 +636,7 @@ def detect_realtime(Yolo, output_path, input_size=416, show=False, CLASSES=YOLO_
print("Time: {:.2f}ms, {:.1f} FPS".format(ms, fps)) print("Time: {:.2f}ms, {:.1f} FPS".format(ms, fps))
frame, command, liste_pos_car = draw_bbox(original_frame, bboxes,liste_pos_car, CLASSES=CLASSES, rectangle_colors=rectangle_colors, ser=ser, previous_command=(10, command, fps)) frame, speed, command, liste_pos_car = draw_bbox(original_frame, bboxes,liste_pos_car, CLASSES=CLASSES, rectangle_colors=rectangle_colors, ser=ser, previous_command=(speed, command, fps))
# CreateXMLfile("XML_Detections", str(int(time.time())), original_frame, bboxes, read_class_names(CLASSES)) # CreateXMLfile("XML_Detections", str(int(time.time())), original_frame, bboxes, read_class_names(CLASSES))
image = cv2.putText(frame, "Time: {:.1f}FPS".format(fps), (0, 30), image = cv2.putText(frame, "Time: {:.1f}FPS".format(fps), (0, 30),
cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 2) cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment