Creating new batch command for walkers
This commit is contained in:
parent
9dd7f30e4e
commit
c05ed8a0f2
|
@ -594,11 +594,12 @@ Static presets
|
|||
- `actor_id`
|
||||
- `transform`
|
||||
|
||||
## `carla.command.ApplyTransform2D`
|
||||
## `carla.command.ApplyWalkerState`
|
||||
|
||||
- `__init__(actor, transform)`
|
||||
- `__init__(actor, transform, speed)`
|
||||
- `actor_id`
|
||||
- `transform`
|
||||
- `speed`
|
||||
|
||||
## `carla.command.ApplyVelocity`
|
||||
|
||||
|
|
|
@ -37,10 +37,7 @@ namespace detail {
|
|||
// get the transform of the walker
|
||||
if (_nav.GetWalkerTransform(handle.walker, trans)) {
|
||||
float speed = _nav.GetWalkerSpeed(handle.walker);
|
||||
commands.emplace_back(Cmd::ApplyTransform2D{ handle.walker, trans });
|
||||
commands.emplace_back(Cmd::ApplyWalkerControl{ handle.walker,
|
||||
rpc::WalkerControl(trans.GetForwardVector(), speed,
|
||||
false)});
|
||||
commands.emplace_back(Cmd::ApplyWalkerState{ handle.walker, trans, speed });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,12 +85,13 @@ namespace rpc {
|
|||
MSGPACK_DEFINE_ARRAY(actor, transform);
|
||||
};
|
||||
|
||||
struct ApplyTransform2D : CommandBase<ApplyTransform2D> {
|
||||
ApplyTransform2D() = default;
|
||||
ApplyTransform2D(ActorId id, const geom::Transform &value) : actor(id), transform(value) {}
|
||||
struct ApplyWalkerState : CommandBase<ApplyWalkerState> {
|
||||
ApplyWalkerState() = default;
|
||||
ApplyWalkerState(ActorId id, const geom::Transform &value, const float speed) : actor(id), transform(value), speed(speed) {}
|
||||
ActorId actor;
|
||||
geom::Transform transform;
|
||||
MSGPACK_DEFINE_ARRAY(actor, transform);
|
||||
float speed;
|
||||
MSGPACK_DEFINE_ARRAY(actor, transform, speed);
|
||||
};
|
||||
|
||||
struct ApplyVelocity : CommandBase<ApplyVelocity> {
|
||||
|
@ -149,7 +150,7 @@ namespace rpc {
|
|||
ApplyVehicleControl,
|
||||
ApplyWalkerControl,
|
||||
ApplyTransform,
|
||||
ApplyTransform2D,
|
||||
ApplyWalkerState,
|
||||
ApplyVelocity,
|
||||
ApplyAngularVelocity,
|
||||
ApplyImpulse,
|
||||
|
|
|
@ -113,11 +113,12 @@ void export_commands() {
|
|||
.def_readwrite("transform", &cr::Command::ApplyTransform::transform)
|
||||
;
|
||||
|
||||
class_<cr::Command::ApplyTransform2D>("ApplyTransform2D")
|
||||
.def("__init__", &command_impl::CustomInit<ActorPtr, cg::Transform>, (arg("actor"), arg("transform")))
|
||||
.def(init<cr::ActorId, cg::Transform>((arg("actor_id"), arg("transform"))))
|
||||
.def_readwrite("actor_id", &cr::Command::ApplyTransform2D::actor)
|
||||
.def_readwrite("transform", &cr::Command::ApplyTransform2D::transform)
|
||||
class_<cr::Command::ApplyWalkerState>("ApplyWalkerState")
|
||||
.def("__init__", &command_impl::CustomInit<ActorPtr, cg::Transform, float>, (arg("actor"), arg("transform"), arg("speed")))
|
||||
.def(init<cr::ActorId, cg::Transform, float>((arg("actor_id"), arg("transform"), arg("speed"))))
|
||||
.def_readwrite("actor_id", &cr::Command::ApplyWalkerState::actor)
|
||||
.def_readwrite("transform", &cr::Command::ApplyWalkerState::transform)
|
||||
.def_readwrite("speed", &cr::Command::ApplyWalkerState::speed)
|
||||
;
|
||||
|
||||
class_<cr::Command::ApplyVelocity>("ApplyVelocity")
|
||||
|
@ -160,7 +161,7 @@ void export_commands() {
|
|||
implicitly_convertible<cr::Command::ApplyVehicleControl, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyWalkerControl, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyTransform, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyTransform2D, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyWalkerState, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyVelocity, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyAngularVelocity, cr::Command>();
|
||||
implicitly_convertible<cr::Command::ApplyImpulse, cr::Command>();
|
||||
|
|
|
@ -396,16 +396,19 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(set_actor_transform_2D) << [this] (
|
||||
BIND_SYNC(set_walker_state) << [this] (
|
||||
cr::ActorId ActorId,
|
||||
cr::Transform Transform) -> R<void>
|
||||
cr::Transform Transform,
|
||||
float Speed) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
auto ActorView = Episode->FindActor(ActorId);
|
||||
if (!ActorView.IsValid())
|
||||
{
|
||||
RESPOND_ERROR("unable to set actor transform: actor not found");
|
||||
RESPOND_ERROR("unable to set walker state: actor not found");
|
||||
}
|
||||
|
||||
// apply walker transform
|
||||
FTransform NewTransform = Transform;
|
||||
FVector NewLocation = NewTransform.GetLocation();
|
||||
|
||||
|
@ -421,6 +424,21 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
false,
|
||||
nullptr,
|
||||
ETeleportType::TeleportPhysics);
|
||||
|
||||
// apply walker speed
|
||||
auto Pawn = Cast<APawn>(ActorView.GetActor());
|
||||
if (Pawn == nullptr)
|
||||
{
|
||||
RESPOND_ERROR("unable to set walker state: actor is not a walker");
|
||||
}
|
||||
auto Controller = Cast<AWalkerController>(Pawn->GetController());
|
||||
if (Controller == nullptr)
|
||||
{
|
||||
RESPOND_ERROR("unable to set walker state: walker has an incompatible controller");
|
||||
}
|
||||
cr::WalkerControl Control(Transform.GetForwardVector(), Speed, false);
|
||||
Controller->ApplyWalkerControl(Control);
|
||||
|
||||
return R<void>::Success();
|
||||
};
|
||||
|
||||
|
@ -886,12 +904,12 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
[=](auto, const C::ApplyVehicleControl &c) { MAKE_RESULT(apply_control_to_vehicle(c.actor, c.control)); },
|
||||
[=](auto, const C::ApplyWalkerControl &c) { MAKE_RESULT(apply_control_to_walker(c.actor, c.control)); },
|
||||
[=](auto, const C::ApplyTransform &c) { MAKE_RESULT(set_actor_transform(c.actor, c.transform)); },
|
||||
[=](auto, const C::ApplyTransform2D &c) { MAKE_RESULT(set_actor_transform_2D(c.actor, c.transform)); },
|
||||
[=](auto, const C::ApplyVelocity &c) { MAKE_RESULT(set_actor_velocity(c.actor, c.velocity)); },
|
||||
[=](auto, const C::ApplyAngularVelocity &c) { MAKE_RESULT(set_actor_angular_velocity(c.actor, c.angular_velocity)); },
|
||||
[=](auto, const C::ApplyImpulse &c) { MAKE_RESULT(add_actor_impulse(c.actor, c.impulse)); },
|
||||
[=](auto, const C::SetSimulatePhysics &c) { MAKE_RESULT(set_actor_simulate_physics(c.actor, c.enabled)); },
|
||||
[=](auto, const C::SetAutopilot &c) { MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); });
|
||||
[=](auto, const C::SetAutopilot &c) { MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
|
||||
[=](auto, const C::ApplyWalkerState &c) { MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); });
|
||||
|
||||
#undef MAKE_RESULT
|
||||
|
||||
|
|
Loading…
Reference in New Issue