Skip to content

Commit

Permalink
feat(ego_entity): update BT, overwrite only FollowTrajectoryAction
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoszynski committed Jan 25, 2024
1 parent bb169ba commit e1286d6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ message DespawnEntityResponse {
message UpdateEntityStatusRequest {
repeated EntityStatus status = 1; // List of updated entity status in traffic simulator.
bool npc_logic_started = 2; // Npc logic started flag
bool overwrite_ego_status = 3;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class EntityBase

virtual void requestSpeedChange(const speed_change::RelativeTargetSpeed &, bool);

virtual auto isFollowTrajectoryActionRun() const -> bool;

virtual auto requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class EntityManager
FORWARD_TO_ENTITY(laneMatchingSucceed, const);
FORWARD_TO_ENTITY(requestAcquirePosition, );
FORWARD_TO_ENTITY(requestAssignRoute, );
FORWARD_TO_ENTITY(isFollowTrajectoryActionRun, );
FORWARD_TO_ENTITY(requestFollowTrajectory, );
FORWARD_TO_ENTITY(requestLaneChange, );
FORWARD_TO_ENTITY(requestWalkStraight, );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class PedestrianEntity : public EntityBase

void requestAssignRoute(const std::vector<geometry_msgs::msg::Pose> &) override;

auto isFollowTrajectoryActionRun() const -> bool override;

auto requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class VehicleEntity : public EntityBase

void requestAssignRoute(const std::vector<CanonicalizedLaneletPose> &) override;

auto isFollowTrajectoryActionRun() const -> bool override;

auto requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void override;

Expand Down
3 changes: 3 additions & 0 deletions simulation/traffic_simulator/src/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ bool API::updateEntitiesStatusInSim()
for (const auto & entity_name : entity_manager_ptr_->getEntityNames()) {
auto entity_status = entity_manager_ptr_->getEntityStatus(entity_name);
simulation_interface::toProto(static_cast<EntityStatus>(entity_status), *req.add_status());
if (entity_manager_ptr_->isEgo(entity_name)) {
req.set_overwrite_ego_status(entity_manager_ptr_->isFollowTrajectoryActionRun(entity_name));
}
}

simulation_api_schema::UpdateEntityStatusResponse res;
Expand Down
14 changes: 5 additions & 9 deletions simulation/traffic_simulator/src/entity/ego_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ auto EgoEntity::asFieldOperatorApplication() const -> concealer::FieldOperatorAp
auto EgoEntity::getCurrentAction() const -> std::string
{
const auto state = field_operator_application->getAutowareStateName();
return state.empty() ? "Launching" : state;
return (state.empty() ? "Launching" : state) +
(isFollowTrajectoryActionRun() ? " (" + VehicleEntity::getCurrentAction() + ")" : "");
}

auto EgoEntity::getBehaviorParameter() const -> traffic_simulator_msgs::msg::BehaviorParameter
Expand Down Expand Up @@ -154,16 +155,10 @@ auto EgoEntity::getWaypoints() -> const traffic_simulator_msgs::msg::WaypointsAr

void EgoEntity::onUpdate(double current_time, double step_time)
{
EntityBase::onUpdate(current_time, step_time);
setStatus(externally_updated_status_);

updateStandStillDuration(step_time);
updateTraveledDistance(step_time);

VehicleEntity::onUpdate(current_time, step_time);
field_operator_application->rethrow();
field_operator_application->spinSome();

EntityBase::onPostUpdate(current_time, step_time);
}

void EgoEntity::requestAcquirePosition(const CanonicalizedLaneletPose & lanelet_pose)
Expand Down Expand Up @@ -258,8 +253,9 @@ auto EgoEntity::setStatusExternally(const CanonicalizedEntityStatus & status) ->
externally_updated_status_ = status;
}

void EgoEntity::requestSpeedChange(double value, bool)
void EgoEntity::requestSpeedChange(double value, bool continuous)
{
VehicleEntity::requestSpeedChange(value, continuous);
field_operator_application->restrictTargetSpeed(value);
}

Expand Down
6 changes: 6 additions & 0 deletions simulation/traffic_simulator/src/entity/entity_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ void EntityBase::requestSpeedChange(
}
}

auto EntityBase::isFollowTrajectoryActionRun() const -> bool
{
THROW_SEMANTIC_ERROR(
getEntityTypename(), " type entities do not support follow trajectory action.");
}

auto EntityBase::requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void
{
Expand Down
5 changes: 5 additions & 0 deletions simulation/traffic_simulator/src/entity/pedestrian_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ void PedestrianEntity::requestAssignRoute(const std::vector<geometry_msgs::msg::
requestAssignRoute(route);
}

auto PedestrianEntity::isFollowTrajectoryActionRun() const -> bool
{
return behavior_plugin_ptr_->getCurrentAction() == "follow_polyline_trajectory";
}

auto PedestrianEntity::requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> & parameter) -> void
{
Expand Down
5 changes: 5 additions & 0 deletions simulation/traffic_simulator/src/entity/vehicle_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ void VehicleEntity::requestAssignRoute(const std::vector<geometry_msgs::msg::Pos
requestAssignRoute(route);
}

auto VehicleEntity::isFollowTrajectoryActionRun() const -> bool
{
return behavior_plugin_ptr_->getCurrentAction() == "follow_polyline_trajectory";
}

auto VehicleEntity::requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> & parameter) -> void
{
Expand Down

0 comments on commit e1286d6

Please sign in to comment.