From 561b09929ec439f2d713c2f9408c76411c3b067a Mon Sep 17 00:00:00 2001 From: Masahiro Kubota <42679530+masahiro-kubota@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:05:45 +0900 Subject: [PATCH] refactor: fix comment (#52) * refactor: fix comments Signed-off-by: Masahiro Kubota * refactor: fix comments Signed-off-by: Masahiro Kubota * refactor: fix comment Signed-off-by: Masahiro Kubota --------- Signed-off-by: Masahiro Kubota --- .../src/velocity_planning/longitudinal_controller.cpp | 7 ++++--- .../src/velocity_planning/p_controller.cpp | 2 ++ .../src/velocity_planning/trajectory_follower.cpp | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/autoware_practice_course/src/velocity_planning/longitudinal_controller.cpp b/src/autoware_practice_course/src/velocity_planning/longitudinal_controller.cpp index 72a378d..b791996 100644 --- a/src/autoware_practice_course/src/velocity_planning/longitudinal_controller.cpp +++ b/src/autoware_practice_course/src/velocity_planning/longitudinal_controller.cpp @@ -61,7 +61,7 @@ void LongitudinalControllerNode::update_target_velocity(const Trajectory & msg) void LongitudinalControllerNode::update_current_state(const Odometry & msg) { current_velocity_ = msg.twist.twist.linear.x; - current_pose_ = msg.pose.pose.position; // 現在の車両の位置を更新する + current_pose_ = msg.pose.pose.position; }; void LongitudinalControllerNode::on_timer() @@ -71,10 +71,11 @@ void LongitudinalControllerNode::on_timer() AckermannControlCommand command; command.stamp = stamp; + // The AckermannControlCommand can contain both longitudinal acceleration and velocity commands, but the vehicle + // interface only accepts longitudinal acceleration. double velocity_error = target_velocity_ - current_velocity_; command.longitudinal.acceleration = kp_ * velocity_error; - command.longitudinal.speed = target_velocity_; // メッセージ型としてはspeedがあるが、vehiclle - // interface側では加速度しか受け取っていない。 + command.longitudinal.speed = target_velocity_; command.lateral.steering_tire_angle = 0.0; diff --git a/src/autoware_practice_course/src/velocity_planning/p_controller.cpp b/src/autoware_practice_course/src/velocity_planning/p_controller.cpp index e736eb9..871e1f3 100644 --- a/src/autoware_practice_course/src/velocity_planning/p_controller.cpp +++ b/src/autoware_practice_course/src/velocity_planning/p_controller.cpp @@ -44,6 +44,8 @@ void PControllerNode::on_timer() AckermannControlCommand command; command.stamp = stamp; + // The AckermannControlCommand can contain both longitudinal acceleration and velocity commands, but the vehicle + // interface only accepts longitudinal acceleration. double velocity_error = target_velocity_ - current_velocity_; command.longitudinal.acceleration = kp_ * velocity_error; command.longitudinal.speed = target_velocity_; diff --git a/src/autoware_practice_course/src/velocity_planning/trajectory_follower.cpp b/src/autoware_practice_course/src/velocity_planning/trajectory_follower.cpp index 8bfee71..8415ebb 100644 --- a/src/autoware_practice_course/src/velocity_planning/trajectory_follower.cpp +++ b/src/autoware_practice_course/src/velocity_planning/trajectory_follower.cpp @@ -64,6 +64,7 @@ void TrajectoryFollowerNode::update_target_velocity(const Trajectory & msg) target_velocity_ = msg.points[closest_point_index_].longitudinal_velocity_mps; }; +// Retrieves the value of the specified parameter from the YAML file double TrajectoryFollowerNode::load_parameters(const std::string & param_file, const std::string & param_tag) { std::ifstream file(param_file); @@ -120,6 +121,7 @@ double TrajectoryFollowerNode::lateral_controller() double min_distance = std::numeric_limits::max(); size_t lookahead_point_index = closest_point_index_; min_distance = std::numeric_limits::max(); + // Find the lookahead point for (size_t i = closest_point_index_; i < trajectory_.points.size(); ++i) { double dx = trajectory_.points[i].pose.position.x - current_position_.x; @@ -145,7 +147,6 @@ double TrajectoryFollowerNode::lateral_controller() double TrajectoryFollowerNode::calculate_yaw_from_quaternion(const geometry_msgs::msg::Quaternion & q) { - // Convert quaternion to Euler angles double siny_cosp = 2 * (q.w * q.z + q.x * q.y); double cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z); double yaw = std::atan2(siny_cosp, cosy_cosp);