Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rescaling of agent coordinates #101

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/level_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
// values are retained so that on an episode reset they can be restored to
// their initial values.
auto &trajectory = ctx.get<Trajectory>(agent);
auto length = agentInit.length/2;
auto width = agentInit.width/2;
for(CountT i = 0; i < agentInit.numPositions; i++)
{
trajectory.positions[i] = Vector2{.x = agentInit.position[i].x - ctx.data().mean.x + length, .y = agentInit.position[i].y - ctx.data().mean.y + width};
trajectory.positions[i] = Vector2{.x = agentInit.position[i].x - ctx.data().mean.x, .y = agentInit.position[i].y - ctx.data().mean.y};
trajectory.velocities[i] = Vector2{.x = agentInit.velocity[i].x, .y = agentInit.velocity[i].y};
Comment on lines +80 to 81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's happening here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each position in the trajectory, we subtract the precomputed means. The mean is computed over all the positions of all the trajectories while ignoring the invalid positions.

We also subtract the same means from road object positions and goal positions. So everything is translated by the same amount.

trajectory.headings[i] = toRadians(agentInit.heading[i]);
trajectory.valids[i] = agentInit.valid[i];
Expand Down
7 changes: 2 additions & 5 deletions tests/bicyclemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ class BicycleKinematicModelTest : public ::testing::Test {
}
agent_length_map[n_agents] = (float)obj["length"];
agent_width_map[n_agents] = (float)obj["width"];
auto length = agent_length_map[n_agents] / 2;
auto width = agent_width_map[n_agents] / 2;
auto x = float(obj["position"][0]["x"]);
initialState.push_back(float(obj["position"][0]["x"]) - mean.first + length);
initialState.push_back(float(obj["position"][0]["y"]) - mean.second + width);
initialState.push_back(float(obj["position"][0]["x"]) - mean.first);
initialState.push_back(float(obj["position"][0]["y"]) - mean.second);
initialState.push_back(test_utils::degreesToRadians(obj["heading"][0]));
initialState.push_back(math::Vector2{.x = obj["velocity"][0]["x"], .y = obj["velocity"][0]["y"]}.length());
n_agents++;
Expand Down
Loading