Skip to content

Commit 1fd2a56

Browse files
authored
Update acceleration limits in dynamics calculations and obs normalization (#456)
fix: update acceleration limits in dynamics calculations
1 parent 60630e3 commit 1fd2a56

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

pufferlib/ocean/drive/drive.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@
139139
#define CLASSIC 0
140140
#define JERK 1
141141

142+
static const float ACCEL_LONG_LIMIT[2] = {-5.0f, 2.5f};
143+
static const float ACCEL_LAT_LIMIT[2] = {-4.0f, 4.0f};
142144
#define STEERING_LIMIT 0.667f
145+
143146
// Jerk action space (for JERK dynamics model)
144147
static const float JERK_LONG[4] = {-15.0f, -4.0f, 0.0f, 4.0f};
145148
static const float JERK_LAT[3] = {-4.0f, 0.0f, 4.0f};
146-
147149
// Classic action space (for CLASSIC dynamics model)
148150
static const float ACCELERATION_VALUES[7] = {-4.0000f, -2.6670f, -1.3330f, -0.0000f, 1.3330f, 2.6670f, 4.0000f};
149151
static const float STEERING_VALUES[9] = {-0.667f, -0.500f, -0.333f, -0.167f, 0.000f, 0.167f, 0.333f, 0.500f, 0.667f};
@@ -4313,8 +4315,8 @@ static int write_ego_obs(Drive *env, Agent *ego, float *obs, int obs_idx) {
43134315
obs[obs_idx++] = ego->sim_width / env->obs_norm_veh_width_m;
43144316
obs[obs_idx++] = ego->sim_length / env->obs_norm_veh_length_m;
43154317
obs[obs_idx++] = ego->steering_angle / STEERING_LIMIT;
4316-
obs[obs_idx++] = (ego->a_long < 0) ? ego->a_long / (-JERK_LONG[0]) : ego->a_long / JERK_LONG[3];
4317-
obs[obs_idx++] = ego->a_lat / JERK_LAT[2];
4318+
obs[obs_idx++] = ego->a_long / fabsf(ACCEL_LONG_LIMIT[0]);
4319+
obs[obs_idx++] = ego->a_lat / ACCEL_LAT_LIMIT[1];
43184320
obs[obs_idx++] = fmaxf(-1.0f, fminf(1.0f, ego->metrics_array[LANE_DIST_IDX] / LANE_DISTANCE_NORMALIZATION));
43194321
obs[obs_idx++] = ego->metrics_array[LANE_ANGLE_IDX];
43204322
float current_lane_speed_limit
@@ -4456,7 +4458,7 @@ static int write_partner_obs(Drive *env, Agent *ego, int agent_idx, float *obs,
44564458
obs[obs_idx++] = other->sim_width / env->obs_norm_veh_width_m;
44574459
obs[obs_idx++] = rel_heading_x;
44584460
obs[obs_idx++] = rel_heading_y;
4459-
obs[obs_idx++] = other->sim_speed / MAX_SPEED;
4461+
obs[obs_idx++] = other->sim_speed_signed / MAX_SPEED;
44604462
partners_written++;
44614463
}
44624464

@@ -4844,7 +4846,7 @@ static void move_dynamics(Drive *env, int action_idx, int agent_idx) {
48444846
if (agent->a_long * a_long_new < 0) {
48454847
a_long_new = 0.0f;
48464848
} else {
4847-
a_long_new = clip(a_long_new, -5.0f, 2.5f * c_acc);
4849+
a_long_new = clip(a_long_new, ACCEL_LONG_LIMIT[0], ACCEL_LONG_LIMIT[1] * c_acc);
48484850
}
48494851

48504852
// Calculate new lateral acceleration from jerk (Eq. 2 in paper)
@@ -4854,7 +4856,7 @@ static void move_dynamics(Drive *env, int action_idx, int agent_idx) {
48544856
if (agent->a_lat * a_lat_new < 0) {
48554857
a_lat_new = 0.0f;
48564858
} else {
4857-
a_lat_new = clip(a_lat_new, -4.0f, 4.0f);
4859+
a_lat_new = clip(a_lat_new, ACCEL_LAT_LIMIT[0], ACCEL_LAT_LIMIT[1]);
48584860
}
48594861

48604862
float heading_x = agent->cos_heading;

0 commit comments

Comments
 (0)