77# import path setting
88import sys
99from pathlib import Path
10- from math import sin , cos
10+ from math import sin , cos , tan , atan2
1111
1212abs_dir_path = str (Path (__file__ ).absolute ().parent )
1313relative_path = "/../../../components/"
@@ -30,7 +30,7 @@ def __init__(self, spec, course=None):
3030 """
3131
3232 self .SPEED_PROPORTIONAL_GAIN = 1.0
33- self .CONTROL_GAIN = 0.5
33+ self .CONTROL_GAIN = 0.1
3434 self .WHEEL_BASE_M = spec .wheel_base_m
3535
3636 self .course = course
@@ -94,6 +94,22 @@ def _calculate_tracking_error(self, state):
9494 error_lon_m , error_lat_m , error_yaw_rad = self .course .calculate_lonlat_error (state , self .target_course_index )
9595 return error_lon_m , error_lat_m , error_yaw_rad
9696
97+ def _calculate_control_input (self , state , error_lat_m , error_yaw_rad ):
98+ """
99+ Private function to calculate yaw rate input
100+ state: State object of vehicle's front axle
101+ error_lat_m: Lateral error against reference course[m]
102+ error_yaw_rad: Yaw angle error against reference course[rad]
103+ """
104+
105+ # calculate steering angle input
106+ curr_spd = state .get_speed_mps ()
107+ error_steer_rad = atan2 (self .CONTROL_GAIN * error_lat_m , curr_spd )
108+ self .target_steer_rad = error_steer_rad + error_yaw_rad
109+
110+ # calculate yaw rate input
111+ self .target_yaw_rate_rps = curr_spd * tan (self .target_steer_rad ) / self .WHEEL_BASE_M
112+
97113 def update (self , state , time_s ):
98114 """
99115 Function to update data for path tracking
@@ -112,6 +128,9 @@ def update(self, state, time_s):
112128 self ._calculate_target_acceleration_mps2 (front_axle_state )
113129
114130 _ , error_lat_m , error_yaw_rad = self ._calculate_tracking_error (front_axle_state )
131+ print (error_lat_m , error_yaw_rad )
132+
133+ self ._calculate_control_input (front_axle_state , error_lat_m , error_yaw_rad )
115134
116135 def get_target_accel_mps2 (self ):
117136 """
0 commit comments