Added function to set custom carsim simfile. Added option to use ue4 carsim road definition or unreal callback method.

This commit is contained in:
Axel 2020-11-23 16:04:17 +01:00 committed by bernat
parent 7739b5eb94
commit 802f941fae
9 changed files with 71 additions and 12 deletions

View File

@ -88,8 +88,12 @@ namespace client {
return boost::static_pointer_cast<TrafficLight>(GetWorld().GetActor(id));
}
void Vehicle::SetCarSimEnabled(bool enabled) {
GetEpisode().Lock()->SetCarSimEnabled(*this, enabled);
void Vehicle::SetCarSimEnabled(bool enabled, std::string simfile_path) {
GetEpisode().Lock()->SetCarSimEnabled(*this, enabled, simfile_path);
}
void Vehicle::UseCarSimRoad(bool enabled) {
GetEpisode().Lock()->UseCarSimRoad(*this, enabled);
}
} // namespace client

View File

@ -88,7 +88,10 @@ namespace client {
SharedPtr<TrafficLight> GetTrafficLight() const;
/// Enables CarSim simulation if it is availiable
void SetCarSimEnabled(bool enabled);
void SetCarSimEnabled(bool enabled, std::string simfile_path);
/// Enables the use of CarSim internal road definition instead of unreal's
void UseCarSimRoad(bool enabled);
private:

View File

@ -330,8 +330,12 @@ namespace detail {
_pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
}
void Client::SetCarSimEnabled(rpc::ActorId vehicle, bool enabled) {
_pimpl->AsyncCall("set_carsim_enabled", vehicle, enabled);
void Client::SetCarSimEnabled(rpc::ActorId vehicle, bool enabled, std::string simfile_path) {
_pimpl->AsyncCall("set_carsim_enabled", vehicle, enabled, simfile_path);
}
void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
_pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
}
void Client::ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control) {

View File

@ -212,6 +212,11 @@ namespace detail {
const rpc::VehicleControl &control);
void SetCarSimEnabled(
rpc::ActorId vehicle,
bool enabled,
std::string simfile_path);
void UseCarSimRoad(
rpc::ActorId vehicle,
bool enabled);

View File

@ -445,8 +445,12 @@ namespace detail {
_client.SetLightStateToVehicle(vehicle.GetId(), light_state);
}
void SetCarSimEnabled(Vehicle &vehicle, bool enabled) {
_client.SetCarSimEnabled(vehicle.GetId(), enabled);
void SetCarSimEnabled(Vehicle &vehicle, bool enabled, std::string simfile_path) {
_client.SetCarSimEnabled(vehicle.GetId(), enabled, simfile_path);
}
void UseCarSimRoad(Vehicle &vehicle, bool enabled) {
_client.UseCarSimRoad(vehicle.GetId(), enabled);
}
/// @}

View File

@ -141,7 +141,8 @@ void export_actor() {
.def("get_traffic_light_state", &cc::Vehicle::GetTrafficLightState)
.def("is_at_traffic_light", &cc::Vehicle::IsAtTrafficLight)
.def("get_traffic_light", &cc::Vehicle::GetTrafficLight)
.def("set_carsim_enabled", &cc::Vehicle::SetCarSimEnabled)
.def("set_carsim_enabled", &cc::Vehicle::SetCarSimEnabled, (arg("enabled"), arg("simfile_path") = ""))
.def("use_carsim_road", &cc::Vehicle::UseCarSimRoad, (arg("enabled")))
.def(self_ns::str(self_ns::self))
;

View File

@ -1083,9 +1083,11 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success();
};
//-----CARSIM--------------------------------
BIND_SYNC(set_carsim_enabled) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>
bool bEnabled,
std::string SimfilePath) -> R<void>
{
REQUIRE_CARLA_EPISODE();
auto ActorView = Episode->FindActor(ActorId);
@ -1098,9 +1100,29 @@ void FCarlaServer::FPimpl::BindActions()
{
RESPOND_ERROR("unable to set carsim: not actor is not a vehicle");
}
Vehicle->SetCarSimEnabled(bEnabled);
Vehicle->SetCarSimEnabled(bEnabled, carla::rpc::ToFString(SimfilePath));
return R<void>::Success();
};
BIND_SYNC(use_carsim_road) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>
{
REQUIRE_CARLA_EPISODE();
auto ActorView = Episode->FindActor(ActorId);
if (!ActorView.IsValid())
{
RESPOND_ERROR("unable to set carsim road: actor not found");
}
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
if (Vehicle == nullptr)
{
RESPOND_ERROR("unable to set carsim road: not actor is not a vehicle");
}
Vehicle->UseCarSimRoad(bEnabled);
return R<void>::Success();
};
//-----CARSIM--------------------------------
// ~~ Traffic lights ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BIND_SYNC(set_traffic_light_state) << [this](

View File

@ -183,6 +183,7 @@ void ACarlaWheeledVehicle::FlushVehicleControl()
{
if (bCarSimEnabled)
{
//-----CARSIM--------------------------------
CarSimMovementComponent->SetThrottleInput(InputControl.Control.Throttle);
CarSimMovementComponent->SetSteeringInput(InputControl.Control.Steer);
CarSimMovementComponent->SetBrakeInput(InputControl.Control.Brake);
@ -205,6 +206,7 @@ void ACarlaWheeledVehicle::FlushVehicleControl()
// }
// }
InputControl.Control.Gear = CarSimMovementComponent->GetCurrentGear();
//-----------------------------------------
}
else
{
@ -487,14 +489,16 @@ void ACarlaWheeledVehicle::SetVehicleLightState(const FVehicleLightState &LightS
}
//-----CARSIM--------------------------------
void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled)
void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath)
{
carla::log_warning("Enabling CarSim", bEnabled);
bCarSimEnabled = bEnabled;
if (bCarSimEnabled)
{
carla::log_warning("Loading simfile:", carla::rpc::FromFString(SimfilePath));
GetVehicleMovementComponent()->SetComponentTickEnabled(false);
GetVehicleMovementComponent()->Deactivate();
CarSimMovementComponent->VsConfigFile = SimfilePath;
CarSimMovementComponent->Activate();
CarSimMovementComponent->ResetVsVehicle(false);
CarSimMovementComponent->SyncVsVehicleLocOri();
@ -507,7 +511,16 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled)
GetVehicleMovementComponent()->Activate();
CarSimMovementComponent->SetComponentTickEnabled(false);
CarSimMovementComponent->Deactivate();
CarSimMovementComponent->VsConfigFile = "";
GetMesh()->SetSimulatePhysics(true);
}
}
void ACarlaWheeledVehicle::UseCarSimRoad(bool bEnabled)
{
carla::log_warning("Enabling CarSim Road", bEnabled);
CarSimMovementComponent->UseVehicleSimRoad = bEnabled;
CarSimMovementComponent->ResetVsVehicle(false);
CarSimMovementComponent->SyncVsVehicleLocOri();
}
//-------------------------------------------

View File

@ -245,7 +245,10 @@ private:
public:
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable)
void SetCarSimEnabled(bool bEnabled);
void SetCarSimEnabled(bool bEnabled, FString SimfilePath = "");
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable)
void UseCarSimRoad(bool bEnabled);
private: