Skip to content

Commit

Permalink
fix: define function in header
Browse files Browse the repository at this point in the history
Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
  • Loading branch information
satoshi-ota committed Dec 18, 2024
1 parent c0c9903 commit c570803
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef AUTOWARE__MOTION_UTILS__FACTOR__PLANNING_FACTOR_INTERFACE_HPP_
#define AUTOWARE__MOTION_UTILS__FACTOR__PLANNING_FACTOR_INTERFACE_HPP_

#include <autoware/motion_utils/trajectory/trajectory.hpp>
#include <rclcpp/rclcpp.hpp>

#include <autoware_planning_msgs/msg/path_point.hpp>
Expand All @@ -41,7 +42,13 @@ using tier4_planning_msgs::msg::SafetyFactorArray;
class PlanningFactorInterface
{
public:
PlanningFactorInterface(rclcpp::Node * node, const std::string & name);
PlanningFactorInterface(rclcpp::Node * node, const std::string & name)
: name_{name},
pub_factors_{
node->create_publisher<PlanningFactorArray>("/planning/planning_factors/" + name, 1)},
clock_{node->get_clock()}
{
}

/**
* @brief factor setter for single control point.
Expand All @@ -61,7 +68,14 @@ class PlanningFactorInterface
const std::vector<PointType> & points, const Pose & ego_pose, const Pose & control_point_pose,
const uint16_t behavior, const SafetyFactorArray & safety_factors,
const bool is_driving_forward = true, const double velocity = 0.0,
const double shift_length = 0.0, const std::string & detail = "");
const double shift_length = 0.0, const std::string & detail = "")
{
const auto distance = static_cast<float>(autoware::motion_utils::calcSignedArcLength(
points, ego_pose.position, control_point_pose.position));
add(

Check warning on line 75 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L73-L75

Added lines #L73 - L75 were not covered by tests
distance, control_point_pose, behavior, safety_factors, is_driving_forward, velocity,
shift_length, detail);
}

Check warning on line 78 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L78

Added line #L78 was not covered by tests

/**
* @brief factor setter for two control points (section).
Expand All @@ -82,7 +96,16 @@ class PlanningFactorInterface
const std::vector<PointType> & points, const Pose & ego_pose, const Pose & start_pose,
const Pose & end_pose, const uint16_t behavior, const SafetyFactorArray & safety_factors,
const bool is_driving_forward = true, const double velocity = 0.0,
const double shift_length = 0.0, const std::string & detail = "");
const double shift_length = 0.0, const std::string & detail = "")
{
const auto start_distance = static_cast<float>(
autoware::motion_utils::calcSignedArcLength(points, ego_pose.position, start_pose.position));
const auto end_distance = static_cast<float>(
autoware::motion_utils::calcSignedArcLength(points, ego_pose.position, end_pose.position));
add(

Check warning on line 105 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L101-L105

Added lines #L101 - L105 were not covered by tests
start_distance, end_distance, start_pose, end_pose, behavior, safety_factors,
is_driving_forward, velocity, shift_length, detail);
}

Check warning on line 108 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L108

Added line #L108 was not covered by tests

/**
* @brief factor setter for single control point.
Expand All @@ -99,7 +122,24 @@ class PlanningFactorInterface
void add(

Check warning on line 122 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L122

Added line #L122 was not covered by tests
const double distance, const Pose & control_point_pose, const uint16_t behavior,
const SafetyFactorArray & safety_factors, const bool is_driving_forward = true,
const double velocity = 0.0, const double shift_length = 0.0, const std::string & detail = "");
const double velocity = 0.0, const double shift_length = 0.0, const std::string & detail = "")
{
const auto control_point = tier4_planning_msgs::build<ControlPoint>()
.pose(control_point_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(distance);

Check warning on line 131 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L127-L131

Added lines #L127 - L131 were not covered by tests

const auto factor = tier4_planning_msgs::build<PlanningFactor>()

Check warning on line 133 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L133

Added line #L133 was not covered by tests
.module(name_)
.is_driving_forward(is_driving_forward)

Check warning on line 135 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L135

Added line #L135 was not covered by tests
.control_points({control_point})
.behavior(behavior)

Check warning on line 137 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L137

Added line #L137 was not covered by tests
.detail(detail)
.safety_factors(safety_factors);

factors_.push_back(factor);
}

Check warning on line 142 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L142

Added line #L142 was not covered by tests

/**
* @brief factor setter for two control points (section).
Expand All @@ -119,12 +159,45 @@ class PlanningFactorInterface
const double start_distance, const double end_distance, const Pose & start_pose,
const Pose & end_pose, const uint16_t behavior, const SafetyFactorArray & safety_factors,
const bool is_driving_forward = true, const double velocity = 0.0,
const double shift_length = 0.0, const std::string & detail = "");
const double shift_length = 0.0, const std::string & detail = "")
{
const auto control_start_point = tier4_planning_msgs::build<ControlPoint>()
.pose(start_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(start_distance);

Check warning on line 168 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L164-L168

Added lines #L164 - L168 were not covered by tests

const auto control_end_point = tier4_planning_msgs::build<ControlPoint>()
.pose(end_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(end_distance);

Check warning on line 174 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L170-L174

Added lines #L170 - L174 were not covered by tests

const auto factor = tier4_planning_msgs::build<PlanningFactor>()

Check warning on line 176 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L176

Added line #L176 was not covered by tests
.module(name_)
.is_driving_forward(is_driving_forward)

Check warning on line 178 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L178

Added line #L178 was not covered by tests
.control_points({control_start_point, control_end_point})
.behavior(behavior)

Check warning on line 180 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L180

Added line #L180 was not covered by tests
.detail(detail)
.safety_factors(safety_factors);

factors_.push_back(factor);
}

Check warning on line 185 in common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_motion_utils/include/autoware/motion_utils/factor/planning_factor_interface.hpp#L185

Added line #L185 was not covered by tests

/**
* @brief publish planning factors.
*/
void publish();
void publish()
{
PlanningFactorArray msg;
msg.header.frame_id = "map";
msg.header.stamp = clock_->now();
msg.factors = factors_;

pub_factors_->publish(msg);

factors_.clear();
}

private:
std::string name_;
Expand Down
103 changes: 0 additions & 103 deletions common/autoware_motion_utils/src/factor/planing_factor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,12 @@
// limitations under the License.

#include <autoware/motion_utils/factor/planning_factor_interface.hpp>
#include <autoware/motion_utils/trajectory/trajectory.hpp>

#include <string>
#include <vector>

namespace autoware::motion_utils
{

PlanningFactorInterface::PlanningFactorInterface(rclcpp::Node * node, const std::string & name)
: name_{name},
pub_factors_{
node->create_publisher<PlanningFactorArray>("/planning/planning_factors/" + name, 1)},
clock_{node->get_clock()}
{
}

template <class PointType>
void PlanningFactorInterface::add(
const std::vector<PointType> & points, const Pose & ego_pose, const Pose & control_point_pose,
const uint16_t behavior, const SafetyFactorArray & safety_factors, const bool is_driving_forward,
const double velocity, const double shift_length, const std::string & detail)
{
const auto distance = static_cast<float>(autoware::motion_utils::calcSignedArcLength(
points, ego_pose.position, control_point_pose.position));
add(
distance, control_point_pose, behavior, safety_factors, is_driving_forward, velocity,
shift_length, detail);
}

template void PlanningFactorInterface::add<tier4_planning_msgs::msg::PathPointWithLaneId>(
const std::vector<tier4_planning_msgs::msg::PathPointWithLaneId> &, const Pose &, const Pose &,
const uint16_t behavior, const SafetyFactorArray &, const bool, const double, const double,
Expand All @@ -55,22 +32,6 @@ template void PlanningFactorInterface::add<autoware_planning_msgs::msg::Trajecto
const uint16_t behavior, const SafetyFactorArray &, const bool, const double, const double,
const std::string &);

template <class PointType>
void PlanningFactorInterface::add(
const std::vector<PointType> & points, const Pose & ego_pose, const Pose & start_pose,
const Pose & end_pose, const uint16_t behavior, const SafetyFactorArray & safety_factors,
const bool is_driving_forward, const double velocity, const double shift_length,
const std::string & detail)
{
const auto start_distance = static_cast<float>(
autoware::motion_utils::calcSignedArcLength(points, ego_pose.position, start_pose.position));
const auto end_distance = static_cast<float>(
autoware::motion_utils::calcSignedArcLength(points, ego_pose.position, end_pose.position));
add(
start_distance, end_distance, start_pose, end_pose, behavior, safety_factors,
is_driving_forward, velocity, shift_length, detail);
}

template void PlanningFactorInterface::add<tier4_planning_msgs::msg::PathPointWithLaneId>(
const std::vector<tier4_planning_msgs::msg::PathPointWithLaneId> &, const Pose &, const Pose &,
const Pose &, const uint16_t behavior, const SafetyFactorArray &, const bool, const double,
Expand All @@ -83,68 +44,4 @@ template void PlanningFactorInterface::add<autoware_planning_msgs::msg::Trajecto
const std::vector<autoware_planning_msgs::msg::TrajectoryPoint> &, const Pose &, const Pose &,
const Pose &, const uint16_t behavior, const SafetyFactorArray &, const bool, const double,
const double, const std::string &);

void PlanningFactorInterface::add(
const double distance, const Pose & control_point_pose, const uint16_t behavior,
const SafetyFactorArray & safety_factors, const bool is_driving_forward, const double velocity,
const double shift_length, const std::string & detail)
{
const auto control_point = tier4_planning_msgs::build<ControlPoint>()
.pose(control_point_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(distance);

const auto factor = tier4_planning_msgs::build<PlanningFactor>()
.module(name_)
.is_driving_forward(is_driving_forward)
.control_points({control_point})
.behavior(behavior)
.detail(detail)
.safety_factors(safety_factors);

factors_.push_back(factor);
}

void PlanningFactorInterface::add(
const double start_distance, const double end_distance, const Pose & start_pose,
const Pose & end_pose, const uint16_t behavior, const SafetyFactorArray & safety_factors,
const bool is_driving_forward, const double velocity, const double shift_length,
const std::string & detail)
{
const auto control_start_point = tier4_planning_msgs::build<ControlPoint>()
.pose(start_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(start_distance);

const auto control_end_point = tier4_planning_msgs::build<ControlPoint>()
.pose(end_pose)
.velocity(velocity)
.shift_length(shift_length)
.distance(end_distance);

const auto factor = tier4_planning_msgs::build<PlanningFactor>()
.module(name_)
.is_driving_forward(is_driving_forward)
.control_points({control_start_point, control_end_point})
.behavior(behavior)
.detail(detail)
.safety_factors(safety_factors);

factors_.push_back(factor);
}

void PlanningFactorInterface::publish()
{
PlanningFactorArray msg;
msg.header.frame_id = "map";
msg.header.stamp = clock_->now();
msg.factors = factors_;

pub_factors_->publish(msg);

factors_.clear();
}

} // namespace autoware::motion_utils

0 comments on commit c570803

Please sign in to comment.