Skip to content

Commit

Permalink
Merge pull request #4237 from zimmy87/fix-1004
Browse files Browse the repository at this point in the history
keep CollisionInfo.has_collided flag set until simGetCollisionInfo called
  • Loading branch information
Jonathan authored Jan 11, 2022
2 parents c1959b7 + 96ca307 commit c23a3a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions AirLib/include/api/VehicleSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace airlib
virtual const msr::airlib::Environment* getGroundTruthEnvironment() const = 0;

virtual CollisionInfo getCollisionInfo() const = 0;
virtual CollisionInfo getCollisionInfoAndReset() = 0;
virtual int getRemoteControlID() const = 0; //which RC to use, 0 is first one, -1 means disable RC (use keyborad)
virtual RCData getRCData() const = 0; //get reading from RC from simulator's host OS
virtual std::string getVehicleName() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ namespace airlib
});

pimpl_->server.bind("simGetCollisionInfo", [&](const std::string& vehicle_name) -> RpcLibAdaptorsBase::CollisionInfo {
const auto& collision_info = getVehicleSimApi(vehicle_name)->getCollisionInfo();
const auto& collision_info = getVehicleSimApi(vehicle_name)->getCollisionInfoAndReset();
return RpcLibAdaptorsBase::CollisionInfo(collision_info);
});

Expand Down
7 changes: 7 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ PawnSimApi::CollisionInfo PawnSimApi::getCollisionInfo() const
return state_.collision_info;
}

PawnSimApi::CollisionInfo PawnSimApi::getCollisionInfoAndReset()
{
CollisionInfo collision_info = getCollisionInfo();
state_.collision_info.has_collided = false;
return collision_info;
}

void PawnSimApi::toggleTrace()
{
state_.tracing_enabled = !state_.tracing_enabled;
Expand Down
1 change: 1 addition & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PawnSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class PawnSimApi : public msr::airlib::VehicleSimApiBase
virtual void setPose(const Pose& pose, bool ignore_collision) override;

virtual CollisionInfo getCollisionInfo() const override;
virtual CollisionInfo getCollisionInfoAndReset() override;
virtual int getRemoteControlID() const override;
virtual msr::airlib::RCData getRCData() const override;
virtual std::string getVehicleName() const override
Expand Down
11 changes: 7 additions & 4 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ PawnSimApi::CollisionInfo PawnSimApi::getCollisionInfo() const
return state_.collision_info;
}

PawnSimApi::CollisionInfo PawnSimApi::getCollisionInfoAndReset()
{
CollisionInfo collision_info = getCollisionInfo();
state_.collision_info.has_collided = false;
return collision_info;
}

FVector PawnSimApi::getUUPosition() const
{
return params_.pawn->GetActorLocation(); // - state_.mesh_origin
Expand Down Expand Up @@ -447,10 +454,6 @@ void PawnSimApi::setPoseInternal(const Pose& pose, bool ignore_collision)

bool enable_teleport = ignore_collision || canTeleportWhileMove();

//must reset collision before we set pose. Setting pose will immediately call NotifyHit if there was collision
//if there was no collision than has_collided would remain false, else it will be set so its value can be
//checked at the start of next tick
state_.collision_info.has_collided = false;
state_.was_last_move_teleport = enable_teleport;

if (enable_teleport)
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PawnSimApi : public msr::airlib::VehicleSimApiBase
virtual void setPose(const Pose& pose, bool ignore_collision) override;

virtual CollisionInfo getCollisionInfo() const override;
virtual CollisionInfo getCollisionInfoAndReset() override;
virtual int getRemoteControlID() const override;
virtual msr::airlib::RCData getRCData() const override;
virtual std::string getVehicleName() const override
Expand Down

0 comments on commit c23a3a5

Please sign in to comment.