Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(follow_trajectory_action): adapt to work with considering slopes #1226

Merged
merged 30 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
62b9867
fix(entities_update): fix update time in EntityStatus
dmoszynski Apr 4, 2024
4d92606
fix(toLaneletPose): fix matching_distance in EgoEntity, EgoEntitySimu…
dmoszynski Apr 5, 2024
e107d22
fix(follow_trajectory): fix velocity vector and setting orientation -…
dmoszynski Apr 10, 2024
42f88f5
fix(action_node): add debug_marker OutputPort
dmoszynski Apr 10, 2024
46490d6
fix(ego_entity_simulation, sim_model_interface): add overwrite positi…
dmoszynski Apr 10, 2024
dfb711f
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski Apr 12, 2024
4eaa23e
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
yamacir-kit Apr 19, 2024
b74c9b0
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski Apr 23, 2024
e3034fd
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski Apr 29, 2024
eb63404
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 6, 2024
49bdda5
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
yamacir-kit May 8, 2024
8563ede
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 13, 2024
51b4641
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 20, 2024
6024371
ref(ego_entity_simulation, sim_model_interface): use world_relative_p…
dmoszynski May 20, 2024
81aec5b
ref(ego_entity_simulation): apply clang reforamt
dmoszynski May 21, 2024
53980e4
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 21, 2024
95c19cd
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 22, 2024
f97f731
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 24, 2024
b0614e3
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski May 28, 2024
f554789
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
yamacir-kit May 30, 2024
c08a7f7
ref(traffic_simulator, behavior_tree): apply requested changes
dmoszynski Jun 3, 2024
ea34460
ref(ego_entity_simulation): use world_relative_position, use only Oz
dmoszynski Jun 3, 2024
9daa0ac
ref(ego_entity_simulation): use world_relative_position_ in getCurren…
dmoszynski Jun 3, 2024
1f72837
feat(ego_entity_simulation): develop VehicleModelState
dmoszynski Jun 3, 2024
dfffa9b
Revert "feat(ego_entity_simulation): develop VehicleModelState"
dmoszynski Jun 3, 2024
d215afd
fix(ego_entity_simulation): fix world_relative_position_ for update()
dmoszynski Jun 3, 2024
84b5dbf
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski Jun 3, 2024
f75bf19
fix(ego_entity_simulation): fix assignment of world_relative_position…
dmoszynski Jun 3, 2024
73dc7c6
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
dmoszynski Jun 10, 2024
178560f
Merge branch 'master' into fix/RJD-955-fix-followtrajectoryaction-nan…
yamacir-kit Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
}
};

auto getMatchingDistance = [&]() -> double {
return entity_status->getBoundingBox().dimensions.y * 0.5 + 1.0;
};

if (getBlackBoardValues();
request != traffic_simulator::behavior::Request::FOLLOW_POLYLINE_TRAJECTORY or
not getInput<decltype(polyline_trajectory)>("polyline_trajectory", polyline_trajectory) or
Expand All @@ -76,7 +80,7 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
} else if (
const auto updated_status = traffic_simulator::follow_trajectory::makeUpdatedStatus(
static_cast<traffic_simulator::EntityStatus>(*entity_status), *polyline_trajectory,
behavior_parameter, hdmap_utils, step_time, getTargetSpeed())) {
behavior_parameter, hdmap_utils, step_time, getMatchingDistance(), getTargetSpeed())) {
setOutput(
"updated_status",
std::make_shared<traffic_simulator::CanonicalizedEntityStatus>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
}
};

auto getMatchingDistance = [&]() -> double {
return std::max(
vehicle_parameters.axles.front_axle.track_width,
vehicle_parameters.axles.rear_axle.track_width) *
0.5 +
1.0;
};

if (getBlackBoardValues();
request != traffic_simulator::behavior::Request::FOLLOW_POLYLINE_TRAJECTORY or
not getInput<decltype(polyline_trajectory)>("polyline_trajectory", polyline_trajectory) or
Expand All @@ -76,7 +84,7 @@ auto FollowPolylineTrajectoryAction::tick() -> BT::NodeStatus
} else if (
const auto updated_status = traffic_simulator::follow_trajectory::makeUpdatedStatus(
static_cast<traffic_simulator::EntityStatus>(*entity_status), *polyline_trajectory,
behavior_parameter, hdmap_utils, step_time, getTargetSpeed())) {
behavior_parameter, hdmap_utils, step_time, getMatchingDistance(), getTargetSpeed())) {
setOutput(
"updated_status",
std::make_shared<traffic_simulator::CanonicalizedEntityStatus>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class EgoEntitySimulation

const bool consider_pose_by_road_slope_;

Eigen::Vector3d world_relative_position_;

public:
const std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils_ptr_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,23 @@ void EgoEntitySimulation::overwrite(
const traffic_simulator_msgs::msg::EntityStatus & status, double current_scenario_time,
double step_time, bool npc_logic_started)
{
using quaternion_operation::convertQuaternionToEulerAngle;
using quaternion_operation::getRotationMatrix;

autoware->rethrow();

if (npc_logic_started) {
using quaternion_operation::convertQuaternionToEulerAngle;
using quaternion_operation::getRotationMatrix;

auto world_relative_position = [&]() -> Eigen::VectorXd {
auto v = Eigen::VectorXd(3);
v(0) = status.pose.position.x - initial_pose_.position.x;
v(1) = status.pose.position.y - initial_pose_.position.y;
v(2) = status.pose.position.z - initial_pose_.position.z;
return getRotationMatrix(initial_pose_.orientation).transpose() * v;
}();
/*
SimModelInterface only supports 2D, therefore the position in Oz is
considered unchangeable and stored in an additional variable
world_relative_position_ that is used in calculations.
*/
world_relative_position_ = getRotationMatrix(initial_pose_.orientation).transpose() *
Eigen::Vector3d(
status.pose.position.x - initial_pose_.position.x,
status.pose.position.y - initial_pose_.position.y,
status.pose.position.z - initial_pose_.position.z);

if (npc_logic_started) {
const auto yaw = [&]() {
const auto q = Eigen::Quaterniond(
getRotationMatrix(initial_pose_.orientation).transpose() *
Expand Down Expand Up @@ -259,8 +262,8 @@ void EgoEntitySimulation::overwrite(
[[fallthrough]];

case VehicleModelType::IDEAL_STEER_VEL:
state(0) = world_relative_position(0);
state(1) = world_relative_position(1);
state(0) = world_relative_position_.x();
state(1) = world_relative_position_.y();
state(2) = yaw;
vehicle_model_ptr_->setState(state);
break;
Expand All @@ -277,8 +280,21 @@ void EgoEntitySimulation::overwrite(
void EgoEntitySimulation::update(
double current_scenario_time, double step_time, bool npc_logic_started)
{
using quaternion_operation::getRotationMatrix;

autoware->rethrow();

/*
SimModelInterface only supports 2D, therefore the position in Oz is
considered unchangeable and stored in an additional variable
world_relative_position_ that is used in calculations.
*/
world_relative_position_ = getRotationMatrix(initial_pose_.orientation).transpose() *
Eigen::Vector3d(
status_.pose.position.x - initial_pose_.position.x,
status_.pose.position.y - initial_pose_.position.y,
status_.pose.position.z - initial_pose_.position.z);

if (npc_logic_started) {
auto input = Eigen::VectorXd(vehicle_model_ptr_->getDimU());

Expand Down Expand Up @@ -319,6 +335,9 @@ void EgoEntitySimulation::update(
vehicle_model_ptr_->setInput(input);
vehicle_model_ptr_->update(step_time);
}
// only the position in the Oz axis is left unchanged, the rest is taken from SimModelInterface
world_relative_position_.x() = vehicle_model_ptr_->getX();
world_relative_position_.y() = vehicle_model_ptr_->getY();
updateStatus(current_scenario_time, step_time);
updatePreviousValues();
}
Expand All @@ -331,19 +350,23 @@ auto EgoEntitySimulation::getMatchedLaneletPoseFromEntityStatus(
/// EgoEntity::setMapPose
const auto unique_route_lanelets =
traffic_simulator::helper::getUniqueValues(autoware->getRouteLanelets());
const auto matching_length = [entity_width] { return entity_width * 0.5 + 1.0; }();
const auto matching_distance = std::max(
vehicle_parameters.axles.front_axle.track_width,
vehicle_parameters.axles.rear_axle.track_width) *
0.5 +
1.0;

std::optional<traffic_simulator_msgs::msg::LaneletPose> lanelet_pose;

if (unique_route_lanelets.empty()) {
lanelet_pose =
hdmap_utils_ptr_->toLaneletPose(status.pose, status.bounding_box, false, matching_length);
hdmap_utils_ptr_->toLaneletPose(status.pose, status.bounding_box, false, matching_distance);
} else {
lanelet_pose =
hdmap_utils_ptr_->toLaneletPose(status.pose, unique_route_lanelets, matching_length);
hdmap_utils_ptr_->toLaneletPose(status.pose, unique_route_lanelets, matching_distance);
if (!lanelet_pose) {
lanelet_pose =
hdmap_utils_ptr_->toLaneletPose(status.pose, status.bounding_box, false, matching_length);
hdmap_utils_ptr_->toLaneletPose(status.pose, status.bounding_box, false, matching_distance);
}
}
return lanelet_pose;
Expand All @@ -363,33 +386,31 @@ auto EgoEntitySimulation::calculateEgoPitch() const -> double
auto centerline_points = hdmap_utils_ptr_->getCenterPoints(ego_lanelet.value().lanelet_id);

/// @note Copied from motion_util::findNearestSegmentIndex
auto find_nearest_segment_index = [](
const std::vector<geometry_msgs::msg::Point> & points,
const geometry_msgs::msg::Point & point) {
assert(not points.empty());

double min_dist = std::numeric_limits<double>::max();
size_t min_idx = 0;

for (size_t i = 0; i < points.size(); ++i) {
const auto dist = [](const auto point1, const auto point2) {
const auto dx = point1.x - point2.x;
const auto dy = point1.y - point2.y;
return dx * dx + dy * dy;
}(points.at(i), point);

if (dist < min_dist) {
min_dist = dist;
min_idx = i;
auto find_nearest_segment_index =
[](const std::vector<geometry_msgs::msg::Point> & points, const Eigen::Vector3d & point) {
assert(not points.empty());

double min_dist = std::numeric_limits<double>::max();
size_t min_idx = 0;

for (size_t i = 0; i < points.size(); ++i) {
const auto dist =
[](const geometry_msgs::msg::Point & point1, const Eigen::Vector3d & point2) {
const auto dx = point1.x - point2.x();
const auto dy = point1.y - point2.y();
return dx * dx + dy * dy;
}(points.at(i), point);

if (dist < min_dist) {
min_dist = dist;
min_idx = i;
}
}
}
return min_idx;
};
return min_idx;
};

geometry_msgs::msg::Point ego_point;
ego_point.x = vehicle_model_ptr_->getX();
ego_point.y = vehicle_model_ptr_->getY();
const size_t ego_seg_idx = find_nearest_segment_index(centerline_points, ego_point);
const size_t ego_seg_idx =
find_nearest_segment_index(centerline_points, world_relative_position_);

const auto & prev_point = centerline_points.at(ego_seg_idx);
const auto & next_point = centerline_points.at(ego_seg_idx + 1);
Expand Down Expand Up @@ -419,26 +440,20 @@ auto EgoEntitySimulation::getCurrentTwist() const -> geometry_msgs::msg::Twist
auto EgoEntitySimulation::getCurrentPose(const double pitch_angle = 0.) const
-> geometry_msgs::msg::Pose
{
Eigen::VectorXd relative_position(3);
relative_position(0) = vehicle_model_ptr_->getX();
relative_position(1) = vehicle_model_ptr_->getY();
relative_position(2) = 0.0;
relative_position =
quaternion_operation::getRotationMatrix(initial_pose_.orientation) * relative_position;

geometry_msgs::msg::Pose current_pose;
current_pose.position.x = initial_pose_.position.x + relative_position(0);
current_pose.position.y = initial_pose_.position.y + relative_position(1);
current_pose.position.z = initial_pose_.position.z + relative_position(2);
current_pose.orientation = [&]() {
geometry_msgs::msg::Vector3 rpy;
rpy.x = 0;
rpy.y = pitch_angle;
rpy.z = vehicle_model_ptr_->getYaw();
return initial_pose_.orientation * quaternion_operation::convertEulerAngleToQuaternion(rpy);
}();

return current_pose;
const auto relative_position =
quaternion_operation::getRotationMatrix(initial_pose_.orientation) * world_relative_position_;
Comment on lines +443 to +444
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://eigen.tuxfamily.org/dox/TopicPitfalls.html

In short: do not use the auto keywords with Eigen's expressions, unless you are 100% sure about what you are doing. In particular, do not use the auto keyword as a replacement for a Matrix<> type.

const Eigen::Vector3d relative_position =

This should fix it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding problem!
I also think it should be fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hakuturu583, it was my pleasure.

const auto relative_orientation = quaternion_operation::convertEulerAngleToQuaternion(
geometry_msgs::build<geometry_msgs::msg::Vector3>()
.x(0)
.y(pitch_angle)
.z(vehicle_model_ptr_->getYaw()));

return geometry_msgs::build<geometry_msgs::msg::Pose>()
.position(geometry_msgs::build<geometry_msgs::msg::Point>()
.x(initial_pose_.position.x + relative_position(0))
.y(initial_pose_.position.y + relative_position(1))
.z(initial_pose_.position.z + relative_position(2)))
.orientation(initial_pose_.orientation * relative_orientation);
}

auto EgoEntitySimulation::getCurrentAccel(const double step_time) const -> geometry_msgs::msg::Accel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto makeUpdatedStatus(
const traffic_simulator_msgs::msg::EntityStatus &,
traffic_simulator_msgs::msg::PolylineTrajectory &,
const traffic_simulator_msgs::msg::BehaviorParameter &,
const std::shared_ptr<hdmap_utils::HdMapUtils> &, double,
const std::shared_ptr<hdmap_utils::HdMapUtils> &, double, double,
std::optional<double> target_speed = std::nullopt)
-> std::optional<traffic_simulator_msgs::msg::EntityStatus>;
} // namespace follow_trajectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class FollowWaypointController
There is no technical basis for this value, it was determined based on
Dawid Moszynski experiments.
*/
static constexpr double finish_distance_tolerance = 1e-4;
static constexpr double finish_distance_tolerance = 1e-2;

/*
Accuracy of the predicted arrival distance at the waypoint with the
Expand All @@ -129,7 +129,7 @@ class FollowWaypointController
There is no technical basis for this value, it was determined based on
Dawid Moszynski experiments.
*/
static constexpr std::size_t number_of_acceleration_candidates = 20;
static constexpr std::size_t number_of_acceleration_candidates = 30;

/*
This is a debugging method, it is not worth giving it much attention.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class EntityBase

/* */ auto setLinearJerk(const double liner_jerk) -> void;

virtual void startNpcLogic();
virtual void startNpcLogic(const double current_time);

/* */ void stopAtCurrentPosition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class EntityManager
// FIXME: this ignores V2I traffic lights
iter->second->setTrafficLightManager(conventional_traffic_light_manager_ptr_);
if (npc_logic_started_ && not is<EgoEntity>(name)) {
iter->second->startNpcLogic();
iter->second->startNpcLogic(getCurrentTime());
}
return success;
} else {
Expand All @@ -555,7 +555,7 @@ class EntityManager

void updateHdmapMarker();

void startNpcLogic();
void startNpcLogic(const double current_time);

auto isNpcLogicStarted() const { return npc_logic_started_; }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ class HdMapUtils
const double matching_distance = 1.0) const
-> std::optional<traffic_simulator_msgs::msg::LaneletPose>;

auto toLaneletPose(
const geometry_msgs::msg::Point &, const traffic_simulator_msgs::msg::BoundingBox &,
const bool include_crosswalk, const double matching_distance = 1.0) const
-> std::optional<traffic_simulator_msgs::msg::LaneletPose>;

auto toLaneletPose(
const geometry_msgs::msg::Pose &, const traffic_simulator_msgs::msg::BoundingBox &,
const bool include_crosswalk, const double matching_distance = 1.0) const
Expand Down
2 changes: 1 addition & 1 deletion simulation/traffic_simulator/src/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ void API::startNpcLogic()
if (isNpcLogicStarted()) {
THROW_SIMULATION_ERROR("NPC logics are already started.");
}
entity_manager_ptr_->startNpcLogic();
clock_.start();
entity_manager_ptr_->startNpcLogic(getCurrentTime());
}

void API::requestLaneChange(const std::string & name, const lanelet::Id & lanelet_id)
Expand Down
Loading
Loading