Skip to content

Commit

Permalink
add setVelocityLimit function
Browse files Browse the repository at this point in the history
Signed-off-by: Masaya Kataoka <[email protected]>
  • Loading branch information
hakuturu583 committed Feb 29, 2024
1 parent 3330855 commit 7c8d7e5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class EntityBase
double min_velocity, double max_velocity, double min_acceleration, double max_acceleration,
double min_jerk, double max_jerk) -> void;

virtual auto setVelocityLimit(double) -> void;
virtual auto setVelocityLimit(double) -> void = 0;

virtual auto setMapPose(const geometry_msgs::msg::Pose & map_pose) -> void;

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

void setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &) override;

void setVelocityLimit(double) override{};

void setAccelerationLimit(double) override {}

void setAccelerationRateLimit(double) override {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class PedestrianEntity : public EntityBase

void setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &);

void setVelocityLimit(double linear_velocity) override;

void setAccelerationLimit(double acceleration) override;

void setAccelerationRateLimit(double acceleration_rate) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class VehicleEntity : public EntityBase

void requestLaneChange(const traffic_simulator::lane_change::Parameter &) override;

void setVelocityLimit(double linear_velocity) override;

void setAccelerationLimit(double acceleration) override;

void setAccelerationRateLimit(double acceleration_rate) override;
Expand Down
2 changes: 0 additions & 2 deletions simulation/traffic_simulator/src/entity/entity_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,6 @@ void EntityBase::activateOutOfRangeJob(
[this]() {}, job::Type::OUT_OF_RANGE, true, job::Event::POST_UPDATE);
}

auto EntityBase::setVelocityLimit(double) -> void {}

void EntityBase::startNpcLogic() { npc_logic_started_ = true; }

void EntityBase::stopAtCurrentPosition()
Expand Down
10 changes: 10 additions & 0 deletions simulation/traffic_simulator/src/entity/pedestrian_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ void PedestrianEntity::setBehaviorParameter(
behavior_plugin_ptr_->setBehaviorParameter(behavior_parameter);
}

void PedestrianEntity::setVelocityLimit(double linear_velocity)
{
if (linear_velocity <= 0.0) {
THROW_SEMANTIC_ERROR("Acceleration limit should be over zero.");
}
auto behavior_parameter = getBehaviorParameter();
behavior_parameter.dynamic_constraints.max_speed = linear_velocity;
setBehaviorParameter(behavior_parameter);
}

void PedestrianEntity::setAccelerationLimit(double acceleration)
{
if (acceleration <= 0.0) {
Expand Down
10 changes: 10 additions & 0 deletions simulation/traffic_simulator/src/entity/vehicle_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ void VehicleEntity::requestLaneChange(const traffic_simulator::lane_change::Para
behavior_plugin_ptr_->setLaneChangeParameters(parameter);
}

void VehicleEntity::setVelocityLimit(double linear_velocity)
{
if (linear_velocity <= 0.0) {
THROW_SEMANTIC_ERROR("Acceleration limit should be over zero.");
}
auto behavior_parameter = getBehaviorParameter();
behavior_parameter.dynamic_constraints.max_speed = linear_velocity;
setBehaviorParameter(behavior_parameter);
}

void VehicleEntity::setAccelerationLimit(double acceleration)
{
if (acceleration <= 0.0) {
Expand Down

0 comments on commit 7c8d7e5

Please sign in to comment.