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

Teleport on agent done #121

Merged
merged 6 commits into from
May 23, 2024
Merged
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
47 changes: 39 additions & 8 deletions src/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ inline void movementSystem(Engine &e,
}
}

if(done.v)
{
// Case: Agent has not collided but is done.
// This can only happen if the agent has reached goal or the episode has ended.
// In that case we teleport the agent. The agent will not collide with anything.
position = consts::kPaddingPosition;
velocity.linear.x = 0;
velocity.linear.y = 0;
velocity.linear.z = 0;
velocity.angular = Vector3::zero();
Comment on lines +292 to +296
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why you zero-out velocities here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem to be necessary but also doesn't hurt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. It's just to be explicit. In the future, when we remove the agentZeroVelSystem, it would be useful to make sure velocities are zero.

return;
}

if (type == EntityType::Vehicle && controlledState.controlledState == ControlMode::BICYCLE)
{
// TODO: Handle the case when the agent is not valid. Currently, we are not doing anything.
Expand Down Expand Up @@ -527,23 +540,41 @@ inline void stepTrackerSystem(Engine &ctx,
void collisionDetectionSystem(Engine &ctx,
const CandidateCollision &candidateCollision) {

auto isExpertAgentInInvalidState = [&](const Loc &candidate) -> bool
auto isInvalidExpertOrDone = [&](const Loc &candidate) -> bool
{
auto controlledState = ctx.getCheck<ControlledState>(candidate);
if (controlledState.valid() && controlledState.value().controlledState == ControlMode::EXPERT)
if (controlledState.valid())
{
auto currStep = getCurrentStep(ctx.get<StepsRemaining>(candidate));
auto validState = ctx.get<Trajectory>(candidate).valids[currStep];
if (!validState)
if( controlledState.value().controlledState == ControlMode::EXPERT)
{
// Case: If an expert agent is in an invalid state, we need to ignore the collision detection for it.
auto currStep = getCurrentStep(ctx.get<StepsRemaining>(candidate));
auto validState = ctx.get<Trajectory>(candidate).valids[currStep];
if (!validState)
{
return true;
}
}
else if (controlledState.value().controlledState == ControlMode::BICYCLE)
{
return true;
// Case: If a controlled agent gets done, we teleport it to the padding position
// Hence we need to ignore the collision detection for it.
// The agent can also be done because it collided.
// In that case, we dont want to ignore collision. Especially if AgentStop is set.
auto done = ctx.get<Done>(candidate);
auto collisionEvent = ctx.getCheck<CollisionDetectionEvent>(candidate);
if(done.v && collisionEvent.valid() && !collisionEvent.value().hasCollided.load_relaxed())
{
return true;
}
}
}
return false;
};

if (isExpertAgentInInvalidState(candidateCollision.a) ||
isExpertAgentInInvalidState(candidateCollision.b)) {
if (isInvalidExpertOrDone(candidateCollision.a) ||
isInvalidExpertOrDone(candidateCollision.b)) {

return;
}

Expand Down
Loading