Skip to content

Commit

Permalink
immediate stop on reset for cars, microsoft#815
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Mar 2, 2018
1 parent 71550d4 commit 695d8ac
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@ void UAirBlueprintLib::enableWorldRendering(AActor* context, bool enable)
}
}

void UAirBlueprintLib::setSimulatePhysics(AActor* actor, bool simulate_physics)
{
TInlineComponentArray<UPrimitiveComponent*> components;
actor->GetComponents(components);

for (UPrimitiveComponent* component : components)
{
component->SetSimulatePhysics(simulate_physics);
}
}

std::vector<UPrimitiveComponent*> UAirBlueprintLib::getPhysicsComponents(AActor* actor)
{
std::vector<UPrimitiveComponent*> phys_comps;
TInlineComponentArray<UPrimitiveComponent*> components;
actor->GetComponents(components);

for (UPrimitiveComponent* component : components)
{
if (component->IsSimulatingPhysics())
phys_comps.push_back(component);
}

return phys_comps;
}

void UAirBlueprintLib::resetSimulatePhysics(AActor* actor)
{
TInlineComponentArray<UPrimitiveComponent*> components;
actor->GetComponents(components);

for (UPrimitiveComponent* component : components)
{
if (component->IsSimulatingPhysics()) {
component->SetSimulatePhysics(false);
component->SetSimulatePhysics(true);
}
}
}

void UAirBlueprintLib::enableViewportRendering(AActor* context, bool enable)
{
// Enable/disable primary viewport rendering flag
Expand Down
3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary

static void enableWorldRendering(AActor* context, bool enable);
static void enableViewportRendering(AActor* context, bool enable);
static void setSimulatePhysics(AActor* actor, bool simulate_physics);
static void resetSimulatePhysics(AActor* actor);
static std::vector<UPrimitiveComponent*> getPhysicsComponents(AActor* actor);

private:
template<typename T>
Expand Down
13 changes: 12 additions & 1 deletion Unreal/Plugins/AirSim/Source/Car/CarPawnApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,25 @@ CarApiBase::CarState CarPawnApi::getCarState()
void CarPawnApi::reset()
{
last_controls_ = CarControls();
UAirBlueprintLib::RunCommandOnGameThread([this]() {
auto phys_comps = UAirBlueprintLib::getPhysicsComponents(pawn_->getPawn());
UAirBlueprintLib::RunCommandOnGameThread([this, &phys_comps]() {
pawn_->reset();
for (auto* phys_comp : phys_comps) {
phys_comp->SetPhysicsAngularVelocity(FVector::ZeroVector);
phys_comp->SetPhysicsLinearVelocity(FVector::ZeroVector);
phys_comp->SetSimulatePhysics(false);
}
//movement_->ResetMoveState();
//movement_->SetActive(false);
//movement_->SetActive(true, true);
setCarControls(CarControls());

}, true);

UAirBlueprintLib::RunCommandOnGameThread([this, &phys_comps]() {
for (auto* phys_comp : phys_comps)
phys_comp->SetSimulatePhysics(true);
}, true);
}

void CarPawnApi::simSetPose(const msr::airlib::Pose& pose, bool ignore_collision)
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/VehiclePawnWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void VehiclePawnWrapper::reset()
//}
pawn_->SetActorLocationAndRotation(state_.start_location, state_.start_rotation, false, nullptr, ETeleportType::TeleportPhysics);

//TODO: delete below
//TODO: refactor below code used for playback
//std::ifstream sim_log("C:\\temp\\mavlogs\\circle\\sim_cmd_006_orbit 5 1.txt.pos.txt");
//plot(sim_log, FColor::Purple, Vector3r(0, 0, -3));
//std::ifstream real_log("C:\\temp\\mavlogs\\circle\\real_cmd_006_orbit 5 1.txt.pos.txt");
Expand Down

0 comments on commit 695d8ac

Please sign in to comment.