Add function to enable autopilot from Python
This commit is contained in:
parent
ad876a282f
commit
c4c15cbb41
|
@ -41,5 +41,11 @@ namespace client {
|
|||
_client.call("apply_control_to_actor", actor.Serialize(), control);
|
||||
}
|
||||
|
||||
void Client::SetActorAutopilot(
|
||||
const Actor &actor,
|
||||
const bool enabled) {
|
||||
_client.call("set_actor_autopilot", actor.Serialize(), enabled);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
} // namespace carla
|
||||
|
|
|
@ -80,6 +80,10 @@ namespace client {
|
|||
const Actor &actor,
|
||||
const VehicleControl &control);
|
||||
|
||||
void SetActorAutopilot(
|
||||
const Actor &actor,
|
||||
bool enabled);
|
||||
|
||||
private:
|
||||
|
||||
carla::rpc::Client _client;
|
||||
|
|
|
@ -19,6 +19,10 @@ namespace client {
|
|||
GetWorld()->GetClient().ApplyControlToActor(*this, control);
|
||||
}
|
||||
|
||||
void SetAutopilot(bool enabled = true) {
|
||||
GetWorld()->GetClient().SetActorAutopilot(*this, enabled);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class Client;
|
||||
|
|
|
@ -84,6 +84,7 @@ void export_actor() {
|
|||
|
||||
class_<cc::Vehicle, bases<cc::Actor>, boost::noncopyable, boost::shared_ptr<cc::Vehicle>>("Vehicle", no_init)
|
||||
.def("apply_control", &cc::Vehicle::ApplyControl)
|
||||
.def("set_autopilot", &cc::Vehicle::SetAutopilot, (arg("enabled")=true))
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
Server.BindSync("apply_control_to_actor", [this](cr::Actor Actor, cr::VehicleControl Control) {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
|
||||
if (!ActorView.IsValid()) {
|
||||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to apply control: actor not found");
|
||||
}
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
|
||||
|
@ -203,6 +203,23 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
}
|
||||
Vehicle->ApplyVehicleControl(Control);
|
||||
});
|
||||
|
||||
Server.BindSync("set_actor_autopilot", [this](cr::Actor Actor, bool bEnabled) {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
|
||||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to set autopilot: actor not found");
|
||||
}
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(ActorView.GetActor());
|
||||
if (Vehicle == nullptr) {
|
||||
RespondErrorStr("unable to set autopilot: actor is not a vehicle");
|
||||
}
|
||||
auto Controller = Cast<AWheeledVehicleAIController>(Vehicle->GetController());
|
||||
if (Controller == nullptr) {
|
||||
RespondErrorStr("unable to set autopilot: vehicle has an incompatible controller");
|
||||
}
|
||||
Controller->SetAutopilot(bEnabled);
|
||||
});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
@ -75,6 +75,8 @@ AWheeledVehicleAIController::AWheeledVehicleAIController(const FObjectInitialize
|
|||
{
|
||||
RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT("RandomEngine"));
|
||||
|
||||
RandomEngine->Seed(RandomEngine->GenerateRandomSeed());
|
||||
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
PrimaryActorTick.TickGroup = TG_PrePhysics;
|
||||
}
|
||||
|
@ -98,6 +100,12 @@ void AWheeledVehicleAIController::Possess(APawn *aPawn)
|
|||
MaximumSteerAngle = Vehicle->GetMaximumSteerAngle();
|
||||
check(MaximumSteerAngle > 0.0f);
|
||||
ConfigureAutopilot(bAutopilotEnabled);
|
||||
|
||||
if (RoadMap == nullptr)
|
||||
{
|
||||
TActorIterator<ACityMapGenerator> It(GetWorld());
|
||||
RoadMap = (It ? It->GetRoadMap() : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void AWheeledVehicleAIController::Tick(const float DeltaTime)
|
||||
|
|
Loading…
Reference in New Issue