@@ -31,13 +31,63 @@ def acceleration_to_pedal_positions(acceleration : float, velocity : float, pitc
3131 if acceleration < - dry_decel * 0.5 or (acceleration <= 0 and velocity < 0.1 ): # a little deadband to avoid oscillation
3232 throttle_percent = 0.0 #drift to stop
3333 else :
34- throttle_percent = accel_active_range [0 ] + (acceleration + dry_decel )/ max_accel * (accel_active_range [1 ]- accel_active_range [0 ])
34+ throttle_percent = accel_active_range [0 ] + (( acceleration + dry_decel )/ max_accel * (accel_active_range [1 ]- accel_active_range [0 ]) )
3535 brake_percent = 0
3636 else :
37- brake_percent = brake_active_range [0 ] + - (acceleration + dry_decel )/ max_brake * (brake_active_range [1 ]- brake_active_range [0 ])
37+ brake_percent = brake_active_range [0 ] + ( - (acceleration + dry_decel )/ max_brake * (brake_active_range [1 ]- brake_active_range [0 ]) )
3838 throttle_percent = 0
39+ print (acceleration , (max (throttle_percent ,0.0 ),max (brake_percent ,0.0 ),1 ))
3940 return (max (throttle_percent ,0.0 ),max (brake_percent ,0.0 ),1 )
4041
42+
43+ # Model that's built on top of Hang's model.
44+ # Designed to allow for various scaling based on current vehicle velocity, and use of functions other than linear
45+ # for scaling.
46+ # DANGER: NEEDS TESTED
47+ elif model == 'avery_v1' :
48+ model = settings .get ('vehicle.dynamics.acceleration_model' , 'avery_v1' )
49+ if gear != 1 :
50+ print ("WARNING: Can't handle gears other than 1 yet" )
51+
52+ max_accel = settings .get ('vehicle.dynamics.max_accelerator_acceleration' )[1 ] # m/s^2
53+ max_brake = settings .get ('vehicle.dynamics.max_brake_deceleration' ) # m/s^2
54+ dry_decel = settings .get ('vehicle.dynamics.internal_dry_deceleration' ) # m/s^2
55+ accel_active_range = settings .get ('vehicle.dynamics.accelerator_active_range' ) # pedal position fraction
56+ brake_active_range = settings .get ('vehicle.dynamics.brake_active_range' ) # pedal position fraction
57+ mapping_function = settings .get ('vehicle.dynamics.pedal_mapping_function' , 'linear' )
58+ velocity_scalar = settings .get ('vehicle.dynamics.velocity_scaling_factor' , 0 ) # Adjust sensitivity based on velocity
59+
60+
61+ def apply_function (value , function = 'linear' ):
62+ if function == 'linear' :
63+ value = value # already linear mapping
64+
65+ # no guarantee that these functions will give good results until we get more test data about accel -> pedal mapping.
66+ elif function == 'quadratic' :
67+ value = value ** 2 # value squared
68+ elif function == 'exponential' :
69+ value = (math .exp (value ) - 1 ) / 2
70+ elif function == 'log' :
71+ value = math .sqrt (math .log (value + 1 )) + 0.2
72+
73+ value += velocity * velocity_scalar
74+ return value
75+
76+ if acceleration > - dry_decel :
77+ if acceleration < - dry_decel * 0.5 or (acceleration <= 0 and velocity < 0.1 ): # a little deadband to avoid oscillation
78+ throttle_percent = 0.0 #drift to stop
79+ else :
80+ throttle_percent = accel_active_range [0 ] + ((acceleration + dry_decel )/ max_accel * (accel_active_range [1 ]- accel_active_range [0 ]))
81+ throttle_percent = apply_function (throttle_percent , mapping_function )
82+ brake_percent = 0
83+ else :
84+ brake_percent = brake_active_range [0 ] + (- (acceleration + dry_decel )/ max_brake * (brake_active_range [1 ]- brake_active_range [0 ]))
85+ brake_percent = apply_function (brake_percent , mapping_function )
86+ throttle_percent = 0
87+ print (acceleration , (max (throttle_percent ,0.0 ),max (brake_percent ,0.0 ),1 ))
88+ return (max (throttle_percent ,0.0 ),max (brake_percent ,0.0 ),1 )
89+
90+
4191 elif model == 'kris_v1' :
4292 brake_max = settings .get ('vehicle.dynamics.max_brake_deceleration' )
4393 reverse_accel_max = settings .get ('vehicle.dynamics.max_accelerator_acceleration_reverse' )
0 commit comments