Added ShowDebugTelemetry to API

This commit is contained in:
Daniel Santos-Oliván 2021-06-30 13:18:41 +02:00 committed by bernat
parent a55bafeacd
commit ec64374db6
11 changed files with 90 additions and 0 deletions

View File

@ -44,6 +44,10 @@ namespace client {
}
}
void Vehicle::ShowDebugTelemetry(bool enabled) {
GetEpisode().Lock()->ShowVehicleDebugTelemetry(*this, enabled);
}
void Vehicle::ApplyControl(const Control &control) {
if (!_is_control_sticky || (control != _control)) {
GetEpisode().Lock()->ApplyControlToVehicle(*this, control);

View File

@ -41,6 +41,9 @@ namespace client {
/// Switch on/off this vehicle's autopilot.
void SetAutopilot(bool enabled = true, uint16_t tm_port = TM_DEFAULT_PORT);
/// Switch on/off this vehicle's autopilot.
void ShowDebugTelemetry(bool enabled = true);
/// Apply @a control to this vehicle.
void ApplyControl(const Control &control);

View File

@ -385,6 +385,10 @@ namespace detail {
_pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
}
void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
_pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
}
void Client::ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control) {
_pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
}

View File

@ -218,6 +218,10 @@ namespace detail {
rpc::ActorId vehicle,
bool enabled);
void ShowVehicleDebugTelemetry(
rpc::ActorId vehicle,
bool enabled);
void ApplyControlToVehicle(
rpc::ActorId vehicle,
const rpc::VehicleControl &control);

View File

@ -441,6 +441,10 @@ namespace detail {
_client.SetActorAutopilot(vehicle.GetId(), enabled);
}
void ShowVehicleDebugTelemetry(Vehicle &vehicle, bool enabled = true) {
_client.ShowVehicleDebugTelemetry(vehicle.GetId(), enabled);
}
void SetLightsToVehicle(Vehicle &vehicle, const rpc::VehicleControl &control) {
_client.ApplyControlToVehicle(vehicle.GetId(), control);
}

View File

@ -208,6 +208,18 @@ namespace rpc {
MSGPACK_DEFINE_ARRAY(actor, enabled);
};
struct ShowDebugTelemetry : CommandBase<ShowDebugTelemetry> {
ShowDebugTelemetry() = default;
ShowDebugTelemetry(
ActorId id,
bool value)
: actor(id),
enabled(value) {}
ActorId actor;
bool enabled;
MSGPACK_DEFINE_ARRAY(actor, enabled);
};
struct SetVehicleLightState : CommandBase<SetVehicleLightState> {
SetVehicleLightState() = default;
SetVehicleLightState(
@ -237,6 +249,7 @@ namespace rpc {
SetSimulatePhysics,
SetEnableGravity,
SetAutopilot,
ShowDebugTelemetry,
SetVehicleLightState>;
CommandType command;

View File

@ -165,6 +165,7 @@ void export_actor() {
.def("apply_physics_control", &cc::Vehicle::ApplyPhysicsControl, (arg("physics_control")))
.def("get_physics_control", CONST_CALL_WITHOUT_GIL(cc::Vehicle, GetPhysicsControl))
.def("set_autopilot", CALL_WITHOUT_GIL_2(cc::Vehicle, SetAutopilot, bool, uint16_t), (arg("enabled") = true, arg("tm_port") = ctm::TM_DEFAULT_PORT))
.def("show_debug_telemetry", &cc::Vehicle::ShowDebugTelemetry, (arg("enabled") = true))
.def("get_speed_limit", &cc::Vehicle::GetSpeedLimit)
.def("get_traffic_light_state", &cc::Vehicle::GetTrafficLightState)
.def("is_at_traffic_light", &cc::Vehicle::IsAtTrafficLight)

View File

@ -194,6 +194,13 @@ void export_commands() {
.def_readwrite("enabled", &cr::Command::SetAutopilot::enabled)
;
class_<cr::Command::ShowDebugTelemetry>("ShowDebugTelemetry")
.def("__init__", &command_impl::CustomInit<ActorPtr, bool, uint16_t>, (arg("actor"), arg("enabled")))
.def(init<cr::ActorId, bool>((arg("actor_id"), arg("enabled"))))
.def_readwrite("actor_id", &cr::Command::ShowDebugTelemetry::actor)
.def_readwrite("enabled", &cr::Command::ShowDebugTelemetry::enabled)
;
class_<cr::Command::SetVehicleLightState>("SetVehicleLightState")
.def("__init__", &command_impl::CustomInit<ActorPtr, bool>, (arg("actor"), arg("light_state")))
.def(init<cr::ActorId, cr::VehicleLightState::flag_type>((arg("actor_id"), arg("light_state"))))

View File

@ -824,6 +824,23 @@ ECarlaServerResponse FVehicleActor::SetActorAutopilot(bool bEnabled, bool bKeepS
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::ShowVehicleDebugTelemetry(bool bEnabled)
{
if (IsDormant())
{
}
else
{
auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
if (Vehicle == nullptr)
{
return ECarlaServerResponse::NotAVehicle;
}
Vehicle->ShowDebugTelemetry(bEnabled);
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::EnableCarSim(const FString& SimfilePath)
{
if (IsDormant())

View File

@ -284,6 +284,11 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse EnableCarSim(const FString&)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -444,6 +449,8 @@ public:
virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState = false) final;
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final;
virtual ECarlaServerResponse EnableCarSim(const FString& SimfilePath) final;
virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final;

View File

@ -1285,6 +1285,31 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success();
};
BIND_SYNC(show_vehicle_debug_telemetry) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"show_vehicle_debug_telemetry",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
ECarlaServerResponse Response =
CarlaActor->ShowVehicleDebugTelemetry(bEnabled);
if (Response != ECarlaServerResponse::Success)
{
return RespondError(
"show_vehicle_debug_telemetry",
Response,
" Actor Id: " + FString::FromInt(ActorId));
}
return R<void>::Success();
};
BIND_SYNC(enable_carsim) << [this](
cr::ActorId ActorId,
std::string SimfilePath) -> R<void>
@ -1798,6 +1823,7 @@ void FCarlaServer::FPimpl::BindActions()
[=](auto, const C::SetEnableGravity &c) { MAKE_RESULT(set_actor_enable_gravity(c.actor, c.enabled)); },
// TODO: SetAutopilot should be removed. This is the old way to control the vehicles
[=](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::ApplyWalkerState &c) { MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); });