11import numpy as np
2+ import rospy
23from math import sin , cos , atan2
34
45# These imports match your existing project structure
@@ -70,7 +71,6 @@ def __init__(
7071 i = settings .get ('control.longitudinal_control.pid_i' )
7172 self .pid_speed = PID (p , d , i , windup_limit = 20 )
7273
73- self .enable_launch_control = settings .get ('control.launch_control.enable' , False )
7474 self .stage_duration = settings .get ('control.launch_control.stage_duration' , 0.5 )
7575 self .launch_start_time = None
7676
@@ -306,6 +306,8 @@ def __init__(self, vehicle_interface=None, **kwargs):
306306 self .stanley = Stanley (** kwargs )
307307 self .vehicle_interface = vehicle_interface
308308 self .desired_speed_source = settings .get ('control.stanley.desired_speed' , 'path' )
309+ self .stage_duration = settings .get ('control.launch_control.stage_duration' , 0.5 )
310+ self .enable_launch_control = settings .get ('control.launch_control.enable' , False ) # and vehicle.v < 0.1
309311
310312 def rate (self ):
311313 """Control frequency in Hz."""
@@ -337,7 +339,6 @@ def update(self, vehicle: VehicleState, trajectory: Trajectory):
337339 else :
338340 self .stanley .set_path (trajectory )
339341 accel , f_delta = self .stanley .compute (vehicle , self )
340- launch_control = self .stanley .enable_launch_control and vehicle .v < 0.01
341342
342343 # If your low-level interface expects steering wheel angle:
343344 steering_angle = front2steer (f_delta )
@@ -347,7 +348,26 @@ def update(self, vehicle: VehicleState, trajectory: Trajectory):
347348 settings .get ('vehicle.geometry.max_steering_angle' , 0.5 )
348349 )
349350
350- cmd = self .vehicle_interface .simple_command (accel , steering_angle , vehicle , launch_control = launch_control )
351+ cmd = self .vehicle_interface .simple_command (accel , steering_angle , vehicle )
352+
353+ if self .enable_launch_control :
354+ print ("launch control active" )
355+ if not hasattr (self ,'_launch_start_time' ):
356+ self ._launch_start_time = rospy .get_time ()
357+ elapsed = rospy .get_time () - self ._launch_start_time
358+ if elapsed < self .stage_duration :
359+ cmd .accelerator_pedal_position = 0.0
360+ cmd .brake_pedal_position = 1.0
361+ elif elapsed < 2 * self .stage_duration :
362+ cmd .accelerator_pedal_position = 1.0
363+ cmd .brake_pedal_position = 1.0
364+ elif elapsed < 3 * self .stage_duration :
365+ cmd .accelerator_pedal_position = 1.0
366+ cmd .brake_pedal_position = 0.0
367+ else :
368+ self .enable_launch_control = False
369+
370+
351371 self .vehicle_interface .send_command (cmd )
352372
353373 def healthy (self ):
0 commit comments