Skip to content

Commit 9554120

Browse files
committed
[fix] optimize the codebase. fix some typo.
1 parent 73ee99d commit 9554120

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

scripts/realworld/controllers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313

1414
class Mpc_controller:
1515
def __init__(self, global_planed_traj, N=20, desired_v=0.3, v_max=0.4, w_max=0.4, ref_gap=4):
16+
"""Initialize the MPC controller.
17+
18+
Args:
19+
global_planed_traj (np.ndarray): The global planned trajectory, shape (n, 2).
20+
N (int): Prediction horizon.
21+
desired_v (float): Desired linear velocity.
22+
v_max (float): Maximum linear velocity.
23+
w_max (float): Maximum angular velocity.
24+
ref_gap (int): Gap between reference points in the prediction horizon.
25+
"""
1626
self.N, self.desired_v, self.ref_gap, self.T = N, desired_v, ref_gap, 0.1
1727
self.ref_traj = self.make_ref_denser(global_planed_traj)
1828
self.ref_traj_len = N // ref_gap + 1
@@ -141,6 +151,16 @@ def find_reference_traj(self, x0, global_planed_traj):
141151

142152
class PID_controller:
143153
def __init__(self, Kp_trans=1.0, Kd_trans=0.1, Kp_yaw=1.0, Kd_yaw=1.0, max_v=1.0, max_w=1.2):
154+
"""Initialize the PID controller.
155+
156+
Args:
157+
Kp_trans (float): Proportional gain for translational error.
158+
Kd_trans (float): Derivative gain for translational error.
159+
Kp_yaw (float): Proportional gain for yaw error.
160+
Kd_yaw (float): Derivative gain for yaw error.
161+
max_v (float): Maximum linear velocity.
162+
max_w (float): Maximum angular velocity.
163+
"""
144164
self.Kp_trans = Kp_trans
145165
self.Kd_trans = Kd_trans
146166
self.Kp_yaw = Kp_yaw

scripts/realworld/http_internvla_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def planning_thread():
108108

109109
while True:
110110
start_time = time.time()
111-
DISIRED_TIME = 0.3
111+
DESIRED_TIME = 0.3
112112
time.sleep(0.05)
113113

114114
if not manager.new_image_arrived:
@@ -193,7 +193,7 @@ def planning_thread():
193193
)
194194
time.sleep(0.1)
195195

196-
time.sleep(max(0, DISIRED_TIME - (time.time() - start_time)))
196+
time.sleep(max(0, DESIRED_TIME - (time.time() - start_time)))
197197

198198

199199
class Go2Manager(Node):
@@ -344,7 +344,8 @@ def move(self, vx, vy, vyaw):
344344
if __name__ == '__main__':
345345
control_thread_instance = threading.Thread(target=control_thread)
346346
planning_thread_instance = threading.Thread(target=planning_thread)
347-
347+
control_thread_instance.daemon = True
348+
planning_thread_instance.daemon = True
348349
rclpy.init()
349350

350351
try:

scripts/realworld/http_internvla_server.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import argparse
22
import json
33
import os
4-
import sys
54
import time
6-
7-
import numpy as np
8-
9-
sys.path.append('/home/pjlab/yq_ws/InternNav')
10-
115
from datetime import datetime
126

7+
import numpy as np
138
from flask import Flask, jsonify, request
149
from PIL import Image
1510

0 commit comments

Comments
 (0)