Added chrono library
This commit is contained in:
parent
4ba40e74f2
commit
7c3367325f
|
@ -96,5 +96,9 @@ namespace client {
|
|||
GetEpisode().Lock()->UseCarSimRoad(*this, enabled);
|
||||
}
|
||||
|
||||
void Vehicle::EnableChronoPhysics() {
|
||||
GetEpisode().Lock()->EnableChronoPhysics(*this);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
} // namespace carla
|
||||
|
|
|
@ -93,6 +93,8 @@ namespace client {
|
|||
/// Enables the use of CarSim internal road definition instead of unreal's
|
||||
void UseCarSimRoad(bool enabled);
|
||||
|
||||
void EnableChronoPhysics();
|
||||
|
||||
private:
|
||||
|
||||
const bool _is_control_sticky;
|
||||
|
|
|
@ -338,6 +338,10 @@ namespace detail {
|
|||
_pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
|
||||
}
|
||||
|
||||
void Client::EnableChronoPhysics(rpc::ActorId vehicle) {
|
||||
_pimpl->AsyncCall("enable_chrono_physics", vehicle);
|
||||
}
|
||||
|
||||
void Client::ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control) {
|
||||
_pimpl->AsyncCall("apply_control_to_walker", walker, control);
|
||||
}
|
||||
|
|
|
@ -219,6 +219,9 @@ namespace detail {
|
|||
rpc::ActorId vehicle,
|
||||
bool enabled);
|
||||
|
||||
void EnableChronoPhysics(
|
||||
rpc::ActorId vehicle);
|
||||
|
||||
void ApplyControlToWalker(
|
||||
rpc::ActorId walker,
|
||||
const rpc::WalkerControl &control);
|
||||
|
|
|
@ -454,6 +454,10 @@ namespace detail {
|
|||
_client.UseCarSimRoad(vehicle.GetId(), enabled);
|
||||
}
|
||||
|
||||
void EnableChronoPhysics(Vehicle &vehicle) {
|
||||
_client.EnableChronoPhysics(vehicle.GetId());
|
||||
}
|
||||
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with the recorder
|
||||
|
|
|
@ -55,3 +55,6 @@
|
|||
|
||||
#pragma push_macro("check")
|
||||
#undef check
|
||||
|
||||
#pragma push_macro("PI")
|
||||
#undef PI
|
||||
|
|
|
@ -17,5 +17,6 @@
|
|||
|
||||
#pragma pop_macro("check")
|
||||
#pragma pop_macro("TEXT")
|
||||
#pragma pop_macro("PI")
|
||||
|
||||
#undef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
|
|
@ -143,6 +143,7 @@ void export_actor() {
|
|||
.def("get_traffic_light", &cc::Vehicle::GetTrafficLight)
|
||||
.def("enable_carsim", &cc::Vehicle::EnableCarSim, (arg("simfile_path") = ""))
|
||||
.def("use_carsim_road", &cc::Vehicle::UseCarSimRoad, (arg("enabled")))
|
||||
.def("enable_chrono_physics", &cc::Vehicle::EnableChronoPhysics)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -173,6 +173,14 @@ public class Carla : ModuleRules
|
|||
{
|
||||
PublicAdditionalLibraries.Add(Path.Combine(LibCarlaInstallPath, "lib", GetLibName("carla_server")));
|
||||
}
|
||||
PublicAdditionalLibraries.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoEngine.so"));
|
||||
PublicAdditionalLibraries.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoEngine_vehicle.so"));
|
||||
PublicAdditionalLibraries.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoModels_vehicle.so"));
|
||||
RuntimeDependencies.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoEngine.so"));
|
||||
RuntimeDependencies.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoEngine_vehicle.so"));
|
||||
RuntimeDependencies.Add(Path.Combine(LibCarlaInstallPath, "lib/libChronoModels_vehicle.so"));
|
||||
bUseRTTI = true;
|
||||
|
||||
}
|
||||
|
||||
// Include path.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Carla/Game/Tagger.h"
|
||||
#include "Carla/Vehicle/MovementComponents/CarSimManagerComponent.h"
|
||||
#include "Carla/Vehicle/MovementComponents/ChronoMovementComponent.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/Functional.h>
|
||||
|
@ -1132,6 +1133,24 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(enable_chrono_physics) << [this](
|
||||
cr::ActorId ActorId) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
auto ActorView = Episode->FindActor(ActorId);
|
||||
if (!ActorView.IsValid())
|
||||
{
|
||||
RESPOND_ERROR("unable to set chrono physics: actor not found");
|
||||
}
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
|
||||
if (Vehicle == nullptr)
|
||||
{
|
||||
RESPOND_ERROR("unable to set chrono physics: not actor is not a vehicle");
|
||||
}
|
||||
UChronoMovementComponent::CreateChronoMovementComponent(Vehicle);
|
||||
return R<void>::Success();
|
||||
};
|
||||
|
||||
// ~~ Traffic lights ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
BIND_SYNC(set_traffic_light_state) << [this](
|
||||
|
|
|
@ -45,3 +45,20 @@ float UBaseCarlaMovementComponent::GetVehicleForwardSpeed() const
|
|||
{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
void UBaseCarlaMovementComponent::DisableUE4VehiclePhysics()
|
||||
{
|
||||
if(!CarlaVehicle)
|
||||
{
|
||||
UE_LOG(LogCarla, Warning, TEXT("Error: Owner is not properly set for UCarSimManagerComponent") );
|
||||
return;
|
||||
}
|
||||
CarlaVehicle->GetVehicleMovementComponent()->SetComponentTickEnabled(false);
|
||||
CarlaVehicle->GetVehicleMovementComponent()->Deactivate();
|
||||
CarlaVehicle->GetMesh()->PhysicsTransformUpdateMode = EPhysicsTransformUpdateMode::ComponentTransformIsKinematic;
|
||||
auto * Bone = CarlaVehicle->GetMesh()->GetBodyInstance(NAME_None);
|
||||
if (Bone)
|
||||
{
|
||||
Bone->SetInstanceSimulatePhysics(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,4 +33,6 @@ public:
|
|||
virtual int32 GetVehicleCurrentGear() const;
|
||||
|
||||
virtual float GetVehicleForwardSpeed() const;
|
||||
|
||||
void DisableUE4VehiclePhysics();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
// Copyright (c) 2019 Intel Corporation
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "ChronoMovementComponent.h"
|
||||
|
||||
using namespace chrono;
|
||||
using namespace chrono::vehicle;
|
||||
using namespace chrono::vehicle::hmmwv;
|
||||
|
||||
void UChronoMovementComponent::CreateChronoMovementComponent(
|
||||
ACarlaWheeledVehicle* Vehicle)
|
||||
{
|
||||
UChronoMovementComponent* ChronoMovementComponent = NewObject<UChronoMovementComponent>(Vehicle);
|
||||
ChronoMovementComponent->RegisterComponent();
|
||||
Vehicle->SetCarlaMovementComponent(ChronoMovementComponent);
|
||||
}
|
||||
|
||||
void UChronoMovementComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// DisableUE4VehiclePhysics();
|
||||
|
||||
// // // Chrono system
|
||||
sys.Set_G_acc(ChVector<>(0, 0, 0));
|
||||
sys.SetSolverType(ChSolver::Type::BARZILAIBORWEIN);
|
||||
sys.SetSolverMaxIterations(150);
|
||||
sys.SetMaxPenetrationRecoverySpeed(4.0);
|
||||
|
||||
// // Create the HMMWV vehicle, set parameters, and initialize.
|
||||
// // Typical aerodynamic drag for HMMWV: Cd = 0.5 and area ~5 m2
|
||||
my_hmmwv = HMMWV_Full(&sys);
|
||||
my_hmmwv.SetContactMethod(ChMaterialSurface::NSC);
|
||||
my_hmmwv.SetChassisFixed(false);
|
||||
my_hmmwv.SetInitPosition(ChCoordsys<>(ChVector<>(10, 10, 0), QUNIT));
|
||||
my_hmmwv.SetPowertrainType(PowertrainModelType::SHAFTS);
|
||||
my_hmmwv.SetDriveType(DrivelineType::FWD);
|
||||
my_hmmwv.SetTireType(TireModelType::PAC02);
|
||||
my_hmmwv.SetTireStepSize(0.001);
|
||||
my_hmmwv.SetAerodynamicDrag(0.5, 5.0, 1.2);
|
||||
my_hmmwv.Initialize();
|
||||
|
||||
// Create the terrain
|
||||
terrain = chrono_types::make_shared<RigidTerrain>(&sys);
|
||||
auto patch = terrain->AddPatch(ChCoordsys<>(ChVector<>(0, 0, 0), QUNIT), ChVector<>(200, 100, -10));
|
||||
patch->SetContactFrictionCoefficient(0.9f);
|
||||
patch->SetContactRestitutionCoefficient(0.01f);
|
||||
patch->SetContactMaterialProperties(2e7f, 0.3f);
|
||||
terrain->Initialize();
|
||||
|
||||
carla::log_warning("ChronoBeginPlay");
|
||||
}
|
||||
|
||||
void UChronoMovementComponent::ProcessControl(FVehicleControl &Control)
|
||||
{
|
||||
double Time = my_hmmwv.GetSystem()->GetChTime(); // this line crashes, my_hmmwv.GetSystem() returns an invalid pointer
|
||||
|
||||
double Throttle = 0; //Control.Throttle;
|
||||
double Steering = 0; //Control.Steer;
|
||||
double Brake = 0; //Control.Brake + Control.bHandBrake;
|
||||
|
||||
my_hmmwv.Synchronize(Time, {Throttle, Steering, Brake}, *terrain.get());
|
||||
terrain->Synchronize(Time);
|
||||
carla::log_warning("ChronoProcessControl");
|
||||
}
|
||||
|
||||
void UChronoMovementComponent::TickComponent(float DeltaTime,
|
||||
ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
double Time = my_hmmwv.GetSystem()->GetChTime(); // this line crashes, my_hmmwv.GetSystem() returns an invalid pointer
|
||||
terrain->Advance(DeltaTime);
|
||||
my_hmmwv.Advance(DeltaTime);
|
||||
sys.DoStepDynamics(DeltaTime);
|
||||
|
||||
auto* vehicle = &my_hmmwv.GetVehicle(); // this line crashes, my_hmmwv.GetVehicle() also returns an invalid pointer
|
||||
if(vehicle)
|
||||
{
|
||||
auto VehiclePos = vehicle->GetVehiclePos();
|
||||
auto VehicleRot = vehicle->GetVehicleRot();
|
||||
carla::log_warning("Time:", Time);
|
||||
carla::log_warning("vehicle pos (", VehiclePos.x(), VehiclePos.y(), VehiclePos.z(), ")");
|
||||
carla::log_warning("vehicle rot (", VehicleRot.e1(), VehicleRot.e2(), VehicleRot.e3(), VehicleRot.e0(), ")");
|
||||
CarlaVehicle->SetActorLocation(FVector(VehiclePos.x(), VehiclePos.y(), VehiclePos.z()));
|
||||
CarlaVehicle->SetActorRotation(FQuat(VehicleRot.e1(), VehicleRot.e2(), VehicleRot.e3(), VehicleRot.e0()));
|
||||
}
|
||||
else
|
||||
{
|
||||
carla::log_warning("vehicle not initialized");
|
||||
}
|
||||
|
||||
carla::log_warning("ChronoTick");
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
// Copyright (c) 2019 Intel Corporation
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseCarlaMovementComponent.h"
|
||||
#include "Carla/Vehicle/VehicleControl.h"
|
||||
|
||||
#include "compiler/disable-ue4-macros.h"
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wall"
|
||||
|
||||
#include "chrono/physics/ChSystemNSC.h"
|
||||
#include "chrono_vehicle/ChVehicleModelData.h"
|
||||
#include "chrono_vehicle/terrain/RigidTerrain.h"
|
||||
#include "chrono_vehicle/driver/ChDataDriver.h"
|
||||
#include "chrono_models/vehicle/hmmwv/HMMWV.h"
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#include "compiler/enable-ue4-macros.h"
|
||||
|
||||
#include "ChronoMovementComponent.generated.h"
|
||||
|
||||
UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent) )
|
||||
class CARLA_API UChronoMovementComponent : public UBaseCarlaMovementComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
chrono::ChSystemNSC sys;
|
||||
chrono::vehicle::hmmwv::HMMWV_Full my_hmmwv;
|
||||
std::shared_ptr<chrono::vehicle::RigidTerrain> terrain;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
static void CreateChronoMovementComponent(ACarlaWheeledVehicle* Vehicle);
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
void ProcessControl(FVehicleControl &Control) override;
|
||||
|
||||
void TickComponent(float DeltaTime,
|
||||
ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
};
|
Loading…
Reference in New Issue