CarlaServer: Open/Close door logic implemented in plugin

This commit is contained in:
Daniel Santos-Olivan 2021-09-13 12:25:55 +02:00 committed by bernat
parent d814312d63
commit 9a81ecf045
4 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/MsgPack.h"
#include <cstdint>
namespace carla {
namespace rpc {
enum class VehicleDoor : uint8_t {
FL = 0,
FR = 1,
RL = 2,
RR = 3,
Hood = 4,
Trunk = 5,
All = 6
};
} // namespace rpc
} // namespace carla
MSGPACK_ADD_ENUM(carla::rpc::VehicleDoor);

View File

@ -667,6 +667,34 @@ ECarlaServerResponse FVehicleActor::GetVehicleLightState(FVehicleLightState& Lig
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::OpenVehicleDoor(const EVehicleDoor DoorIdx)
{
if (!IsDormant())
{
auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
if (Vehicle == nullptr)
{
return ECarlaServerResponse::NotAVehicle;
}
Vehicle->OpenDoor(DoorIdx);
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::CloseVehicleDoor(const EVehicleDoor DoorIdx)
{
if (!IsDormant())
{
auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
if (Vehicle == nullptr)
{
return ECarlaServerResponse::NotAVehicle;
}
Vehicle->CloseDoor(DoorIdx);
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::ApplyPhysicsControl(
const FVehiclePhysicsControl& PhysicsControl)
{

View File

@ -248,6 +248,16 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl&)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -428,6 +438,10 @@ public:
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState& LightState) final;
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final;
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final;
virtual ECarlaServerResponse ApplyPhysicsControl(
const FVehiclePhysicsControl& PhysicsControl) final;

View File

@ -48,6 +48,7 @@
#include <carla/rpc/Transform.h>
#include <carla/rpc/Vector2D.h>
#include <carla/rpc/Vector3D.h>
#include <carla/rpc/VehicleDoor.h>
#include <carla/rpc/VehicleControl.h>
#include <carla/rpc/VehiclePhysicsControl.h>
#include <carla/rpc/VehicleLightState.h>
@ -1082,6 +1083,57 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success();
};
BIND_SYNC(open_vehicle_door) << [this](
cr::ActorId ActorId,
cr::VehicleDoor DoorIdx) -> R<void>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"open_vehicle_door",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
ECarlaServerResponse Response =
CarlaActor->OpenVehicleDoor(static_cast<EVehicleDoor>(DoorIdx));
if (Response != ECarlaServerResponse::Success)
{
return RespondError(
"open_vehicle_door",
Response,
" Actor Id: " + FString::FromInt(ActorId));
}
return R<void>::Success();
};
BIND_SYNC(close_vehicle_door) << [this](
cr::ActorId ActorId,
cr::VehicleDoor DoorIdx) -> R<void>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"close_vehicle_door",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
ECarlaServerResponse Response =
CarlaActor->CloseVehicleDoor(static_cast<EVehicleDoor>(DoorIdx));
if (Response != ECarlaServerResponse::Success)
{
return RespondError(
"close_vehicle_door",
Response,
" Actor Id: " + FString::FromInt(ActorId));
}
return R<void>::Success();
};
BIND_SYNC(set_wheel_steer_direction) << [this](
cr::ActorId ActorId,
cr::VehicleWheelLocation WheelLocation,
@ -1826,6 +1878,8 @@ void FCarlaServer::FPimpl::BindActions()
[=](auto, const C::SetAutopilot &c) { MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
[=](auto, const C::ShowDebugTelemetry &c) { MAKE_RESULT(show_vehicle_debug_telemetry(c.actor, c.enabled)); },
[=](auto, const C::SetVehicleLightState &c) { MAKE_RESULT(set_vehicle_light_state(c.actor, c.light_state)); },
// [=](auto, const C::OpenVehicleDoor &c) { MAKE_RESULT(open_vehicle_door(c.actor, c.door_idx)); },
// [=](auto, const C::CloseVehicleDoor &c) { MAKE_RESULT(close_vehicle_door(c.actor, c.door_idx)); },
[=](auto, const C::ApplyWalkerState &c) { MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); });
#undef MAKE_RESULT