Compare commits
16 Commits
a9c56261ea
...
3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 33d6537947 | |||
| 62a2fed488 | |||
| 1a19e38b2d | |||
| 0d10ec2208 | |||
| 270bbcc0c4 | |||
| dbbda958a2 | |||
| 875db4ba1e | |||
| 9c14054d3f | |||
| 498a85a199 | |||
| d681201698 | |||
| 5812542eaf | |||
| 0c65a5b6ba | |||
| 1616ac8d7b | |||
| 5d4d77155b | |||
| 274d3dd858 | |||
| 251c741dd9 |
@@ -20,7 +20,11 @@ The specified base path contains a CMakeLists.txt but "catkin_make" must be invo
|
|||||||
|
|
||||||
# Build trong workspace mới
|
# Build trong workspace mới
|
||||||
cd ../pnkx_nav_catkin_ws
|
cd ../pnkx_nav_catkin_ws
|
||||||
catkin_make
|
rm -rf build devel
|
||||||
|
catkin_make -DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \
|
||||||
|
-DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
|
||||||
source devel/setup.bash
|
source devel/setup.bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -356,8 +356,7 @@ export PNKX_NAV_CORE_CONFIG_DIR=/path/to/config
|
|||||||
|
|
||||||
# Chỉ định workspace directory
|
# Chỉ định workspace directory
|
||||||
export PNKX_NAV_CORE_DIR=/path/to/pnkx_nav_core
|
export PNKX_NAV_CORE_DIR=/path/to/pnkx_nav_core
|
||||||
|
] không install)
|
||||||
# LD_LIBRARY_PATH (nếu không install)
|
|
||||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/pnkx_nav_core/build/lib
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/pnkx_nav_core/build/lib
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ base_global_planner: CustomPlanner
|
|||||||
|
|
||||||
PNKXLocalPlanner:
|
PNKXLocalPlanner:
|
||||||
base_local_planner: LocalPlannerAdapter
|
base_local_planner: LocalPlannerAdapter
|
||||||
base_global_planner: CustomPlanner
|
base_global_planner: CustomPlanner
|
||||||
|
|
||||||
PNKXDockingLocalPlanner:
|
PNKXDockingLocalPlanner:
|
||||||
base_local_planner: LocalPlannerAdapter
|
base_local_planner: LocalPlannerAdapter
|
||||||
@@ -30,7 +30,7 @@ max_planning_retries: 0 # ... or after 10 attempts (whichever happens first)
|
|||||||
oscillation_timeout: -1 # abort controller and trigger recovery behaviors after 30.0 s
|
oscillation_timeout: -1 # abort controller and trigger recovery behaviors after 30.0 s
|
||||||
oscillation_distance: 0.5
|
oscillation_distance: 0.5
|
||||||
### recovery behaviors
|
### recovery behaviors
|
||||||
recovery_behavior_enabled: true
|
recovery_behavior_enabled: false
|
||||||
recovery_behaviors: [
|
recovery_behaviors: [
|
||||||
{name: aggressive_reset, type: ClearCostmapRecovery},
|
{name: aggressive_reset, type: ClearCostmapRecovery},
|
||||||
{name: conservative_reset, type: ClearCostmapRecovery},
|
{name: conservative_reset, type: ClearCostmapRecovery},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
yaw_goal_tolerance: 0.03
|
yaw_goal_tolerance: 0.02
|
||||||
xy_goal_tolerance: 0.02
|
xy_goal_tolerance: 0.03
|
||||||
min_approach_linear_velocity: 0.05
|
min_approach_linear_velocity: 0.05
|
||||||
|
|
||||||
LocalPlannerAdapter:
|
LocalPlannerAdapter:
|
||||||
@@ -53,12 +53,12 @@ LimitedAccelGenerator:
|
|||||||
max_vel_theta: 0.4 # max_rot_vel: 1.0 # choose slightly less than the base's capability
|
max_vel_theta: 0.4 # max_rot_vel: 1.0 # choose slightly less than the base's capability
|
||||||
min_vel_theta: 0.05 # min_rot_vel: 0.1 default: 0.4 # this is the min angular velocity when there is negligible translational velocity
|
min_vel_theta: 0.05 # min_rot_vel: 0.1 default: 0.4 # this is the min angular velocity when there is negligible translational velocity
|
||||||
|
|
||||||
acc_lim_x: 1.5
|
acc_lim_x: 3.0
|
||||||
acc_lim_y: 0.0 # diff drive robot
|
acc_lim_y: 0.0 # diff drive robot
|
||||||
acc_lim_theta: 1.5
|
acc_lim_theta: 1.5
|
||||||
decel_lim_x: -1.5
|
decel_lim_x: -3.0
|
||||||
decel_lim_y: -0.0
|
decel_lim_y: -0.0
|
||||||
decel_lim_theta: -1.5
|
decel_lim_theta: -2.0
|
||||||
|
|
||||||
# Whether to split the path into segments or not
|
# Whether to split the path into segments or not
|
||||||
split_path: true
|
split_path: true
|
||||||
@@ -74,8 +74,8 @@ LimitedAccelGenerator:
|
|||||||
|
|
||||||
MKTAlgorithmDiffPredictiveTrajectory:
|
MKTAlgorithmDiffPredictiveTrajectory:
|
||||||
library_path: libmkt_algorithm_diff
|
library_path: libmkt_algorithm_diff
|
||||||
xy_local_goal_tolerance: 0.02
|
xy_local_goal_tolerance: 0.05
|
||||||
angle_threshold: 0.47
|
angle_threshold: 0.6
|
||||||
index_samples: 60
|
index_samples: 60
|
||||||
follow_step_path: true
|
follow_step_path: true
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ MKTAlgorithmDiffPredictiveTrajectory:
|
|||||||
|
|
||||||
MKTAlgorithmDiffGoStraight:
|
MKTAlgorithmDiffGoStraight:
|
||||||
library_path: libmkt_algorithm_diff
|
library_path: libmkt_algorithm_diff
|
||||||
xy_local_goal_tolerance: 0.02
|
xy_local_goal_tolerance: 0.05
|
||||||
angle_threshold: 0.8
|
angle_threshold: 0.8
|
||||||
index_samples: 60
|
index_samples: 60
|
||||||
follow_step_path: true
|
follow_step_path: true
|
||||||
@@ -156,7 +156,7 @@ MKTAlgorithmDiffGoStraight:
|
|||||||
|
|
||||||
MKTAlgorithmDiffRotateToGoal:
|
MKTAlgorithmDiffRotateToGoal:
|
||||||
library_path: libmkt_algorithm_diff
|
library_path: libmkt_algorithm_diff
|
||||||
xy_local_goal_tolerance: 0.02
|
xy_local_goal_tolerance: 0.05
|
||||||
angle_threshold: 0.47
|
angle_threshold: 0.47
|
||||||
index_samples: 60
|
index_samples: 60
|
||||||
follow_step_path: true
|
follow_step_path: true
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
// Process index_s with multiple elements
|
// Process index_s with multiple elements
|
||||||
if (index_s.size() > 1)
|
if (index_s.size() > 1)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < index_s.size(); ++i)
|
for (size_t i = 1; i < index_s.size(); ++i)
|
||||||
{
|
{
|
||||||
if (index_s[i - 1] >= (unsigned int)global_plan.poses.size() || index_s[i] >= (unsigned int)global_plan.poses.size())
|
if (index_s[i - 1] >= (unsigned int)global_plan.poses.size() || index_s[i] >= (unsigned int)global_plan.poses.size())
|
||||||
{
|
{
|
||||||
@@ -219,11 +219,12 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
double x = cos(global_plan.poses[index_s[i - 1]].pose.theta) * dx + sin(global_plan.poses[index_s[i - 1]].pose.theta) * dy;
|
double x = cos(global_plan.poses[index_s[i - 1]].pose.theta) * dx + sin(global_plan.poses[index_s[i - 1]].pose.theta) * dy;
|
||||||
double y = -sin(global_plan.poses[index_s[i - 1]].pose.theta) * dx + cos(global_plan.poses[index_s[i - 1]].pose.theta) * dy;
|
double y = -sin(global_plan.poses[index_s[i - 1]].pose.theta) * dx + cos(global_plan.poses[index_s[i - 1]].pose.theta) * dy;
|
||||||
|
|
||||||
if (std::abs(std::sqrt(dx * dx + dy * dy)) <= xy_local_goal_tolerance_ + 0.1)
|
if (std::abs(std::sqrt(dx * dx + dy * dy)) <= xy_local_goal_tolerance_ + 0.2)
|
||||||
{
|
{
|
||||||
double tolerance = fabs(cos(theta)) >= fabs(sin(theta)) ? x : y;
|
double tolerance = fabs(cos(theta)) >= fabs(sin(theta)) ? x : y;
|
||||||
if (fabs(tolerance) <= xy_local_goal_tolerance_)
|
if (fabs(tolerance) <= xy_local_goal_tolerance_)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (index_s[i] > sub_goal_index_saved_)
|
if (index_s[i] > sub_goal_index_saved_)
|
||||||
{
|
{
|
||||||
sub_goal_index = (i < index_s.size() - 1) ? index_s[i] : (unsigned int)global_plan.poses.size() - 1;
|
sub_goal_index = (i < index_s.size() - 1) ? index_s[i] : (unsigned int)global_plan.poses.size() - 1;
|
||||||
@@ -257,7 +258,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
double theta = angles::normalize_angle(robot_pose.pose.theta - global_plan.poses[sub_goal_index].pose.theta);
|
double theta = angles::normalize_angle(robot_pose.pose.theta - global_plan.poses[sub_goal_index].pose.theta);
|
||||||
double x = cos(global_plan.poses[sub_goal_index].pose.theta) * dx + sin(global_plan.poses[sub_goal_index].pose.theta) * dy;
|
double x = cos(global_plan.poses[sub_goal_index].pose.theta) * dx + sin(global_plan.poses[sub_goal_index].pose.theta) * dy;
|
||||||
double y = -sin(global_plan.poses[sub_goal_index].pose.theta) * dx + cos(global_plan.poses[sub_goal_index].pose.theta) * dy;
|
double y = -sin(global_plan.poses[sub_goal_index].pose.theta) * dx + cos(global_plan.poses[sub_goal_index].pose.theta) * dy;
|
||||||
if (std::abs(std::sqrt(dx * dx + dy * dy)) <= xy_local_goal_tolerance_ + 0.1)
|
if (std::abs(std::sqrt(dx * dx + dy * dy)) <= xy_local_goal_tolerance_ + 0.2)
|
||||||
{
|
{
|
||||||
double tolerance = fabs(cos(theta)) >= fabs(sin(theta)) ? x : y;
|
double tolerance = fabs(cos(theta)) >= fabs(sin(theta)) ? x : y;
|
||||||
if (fabs(tolerance) <= xy_local_goal_tolerance_)
|
if (fabs(tolerance) <= xy_local_goal_tolerance_)
|
||||||
@@ -415,7 +416,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
robot_nav_2d_msgs::Pose2DStamped sub_pose;
|
robot_nav_2d_msgs::Pose2DStamped sub_pose;
|
||||||
sub_pose = global_plan.poses[closet_index];
|
sub_pose = global_plan.poses[closet_index];
|
||||||
|
|
||||||
#ifdef SCORE_ALGORITHM_WITH_ROS
|
#ifdef BUILD_WITH_ROS
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::PoseStamped sub_pose_stamped = robot_nav_2d_utils::pose2DToPoseStamped(sub_pose);
|
robot_geometry_msgs::PoseStamped sub_pose_stamped = robot_nav_2d_utils::pose2DToPoseStamped(sub_pose);
|
||||||
geometry_msgs::PoseStamped sub_pose_stamped_ros;
|
geometry_msgs::PoseStamped sub_pose_stamped_ros;
|
||||||
@@ -423,7 +424,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
sub_pose_stamped_ros.header.frame_id = sub_pose_stamped.header.frame_id;
|
sub_pose_stamped_ros.header.frame_id = sub_pose_stamped.header.frame_id;
|
||||||
sub_pose_stamped_ros.pose.position.x = sub_pose_stamped.pose.position.x;
|
sub_pose_stamped_ros.pose.position.x = sub_pose_stamped.pose.position.x;
|
||||||
sub_pose_stamped_ros.pose.position.y = sub_pose_stamped.pose.position.y;
|
sub_pose_stamped_ros.pose.position.y = sub_pose_stamped.pose.position.y;
|
||||||
sub_pose_stamped_ros.pose.position.z = sub_pose_stamped.pose.position.z;
|
sub_pose_stamped_ros.pose.position.z = 0.9;
|
||||||
sub_pose_stamped_ros.pose.orientation.x = sub_pose_stamped.pose.orientation.x;
|
sub_pose_stamped_ros.pose.orientation.x = sub_pose_stamped.pose.orientation.x;
|
||||||
sub_pose_stamped_ros.pose.orientation.y = sub_pose_stamped.pose.orientation.y;
|
sub_pose_stamped_ros.pose.orientation.y = sub_pose_stamped.pose.orientation.y;
|
||||||
sub_pose_stamped_ros.pose.orientation.z = sub_pose_stamped.pose.orientation.z;
|
sub_pose_stamped_ros.pose.orientation.z = sub_pose_stamped.pose.orientation.z;
|
||||||
@@ -434,7 +435,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
|
|
||||||
robot_nav_2d_msgs::Pose2DStamped sub_goal;
|
robot_nav_2d_msgs::Pose2DStamped sub_goal;
|
||||||
sub_goal = global_plan.poses[goal_index];
|
sub_goal = global_plan.poses[goal_index];
|
||||||
#ifdef SCORE_ALGORITHM_WITH_ROS
|
#ifdef BUILD_WITH_ROS
|
||||||
{
|
{
|
||||||
robot_geometry_msgs::PoseStamped sub_goal_stamped = robot_nav_2d_utils::pose2DToPoseStamped(sub_goal);
|
robot_geometry_msgs::PoseStamped sub_goal_stamped = robot_nav_2d_utils::pose2DToPoseStamped(sub_goal);
|
||||||
geometry_msgs::PoseStamped sub_goal_stamped_ros;
|
geometry_msgs::PoseStamped sub_goal_stamped_ros;
|
||||||
@@ -442,7 +443,7 @@ bool score_algorithm::ScoreAlgorithm::computePlanCommand(const robot_nav_2d_msgs
|
|||||||
sub_goal_stamped_ros.header.frame_id = sub_goal_stamped.header.frame_id;
|
sub_goal_stamped_ros.header.frame_id = sub_goal_stamped.header.frame_id;
|
||||||
sub_goal_stamped_ros.pose.position.x = sub_goal_stamped.pose.position.x;
|
sub_goal_stamped_ros.pose.position.x = sub_goal_stamped.pose.position.x;
|
||||||
sub_goal_stamped_ros.pose.position.y = sub_goal_stamped.pose.position.y;
|
sub_goal_stamped_ros.pose.position.y = sub_goal_stamped.pose.position.y;
|
||||||
sub_goal_stamped_ros.pose.position.z = sub_goal_stamped.pose.position.z;
|
sub_goal_stamped_ros.pose.position.z = 0.9;
|
||||||
sub_goal_stamped_ros.pose.orientation.x = sub_goal_stamped.pose.orientation.x;
|
sub_goal_stamped_ros.pose.orientation.x = sub_goal_stamped.pose.orientation.x;
|
||||||
sub_goal_stamped_ros.pose.orientation.y = sub_goal_stamped.pose.orientation.y;
|
sub_goal_stamped_ros.pose.orientation.y = sub_goal_stamped.pose.orientation.y;
|
||||||
sub_goal_stamped_ros.pose.orientation.z = sub_goal_stamped.pose.orientation.z;
|
sub_goal_stamped_ros.pose.orientation.z = sub_goal_stamped.pose.orientation.z;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ namespace mkt_algorithm
|
|||||||
*/
|
*/
|
||||||
robot_nav_2d_msgs::Path2D generateTrajectory(
|
robot_nav_2d_msgs::Path2D generateTrajectory(
|
||||||
const robot_nav_2d_msgs::Path2D &path, const robot_nav_2d_msgs::Twist2D &drive_target,
|
const robot_nav_2d_msgs::Path2D &path, const robot_nav_2d_msgs::Twist2D &drive_target,
|
||||||
const robot_nav_2d_msgs::Twist2D &velocity, const double &sign_x, robot_nav_2d_msgs::Twist2D &drive_cmd);
|
const robot_nav_2d_msgs::Twist2D &velocity, const double &sign_x, robot_nav_2d_msgs::Twist2D &drive_cmd, const double &dt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generate trajectory
|
* @brief Generate trajectory
|
||||||
|
|||||||
@@ -131,19 +131,19 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::GoStraight::calculator(
|
|||||||
auto carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
auto carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
||||||
robot_geometry_msgs::PoseStamped carrot_pose_stamped = robot_nav_2d_utils::pose2DToPoseStamped(carrot_pose);
|
robot_geometry_msgs::PoseStamped carrot_pose_stamped = robot_nav_2d_utils::pose2DToPoseStamped(carrot_pose);
|
||||||
|
|
||||||
// === Final Heading Alignment Check ===
|
// // === Final Heading Alignment Check ===
|
||||||
double xy_error = 0.0, heading_error = 0.0;
|
// double xy_error = 0.0, heading_error = 0.0;
|
||||||
if (shouldAlignToFinalHeading(transformed_plan, carrot_pose, velocity, xy_error, heading_error, sign_x))
|
// if (shouldAlignToFinalHeading(transformed_plan, carrot_pose, velocity, xy_error, heading_error, sign_x))
|
||||||
{
|
// {
|
||||||
// Use Arc Motion controller for final heading alignment
|
// // Use Arc Motion controller for final heading alignment
|
||||||
alignToFinalHeading(xy_error, heading_error, velocity, sign_x, dt, drive_cmd);
|
// alignToFinalHeading(xy_error, heading_error, velocity, sign_x, dt, drive_cmd);
|
||||||
#ifdef BUILD_WITH_ROS
|
// #ifdef BUILD_WITH_ROS
|
||||||
ROS_INFO("xy_err=%.3f, heading_err=%.3f deg, v=%.3f, w_current=%.3f, w_target=%.3f",
|
// ROS_INFO("xy_err=%.3f, heading_err=%.3f deg, v=%.3f, w_current=%.3f, w_target=%.3f",
|
||||||
xy_error, heading_error * 180.0 / M_PI, drive_cmd.x, velocity.theta, drive_cmd.theta);
|
// xy_error, heading_error * 180.0 / M_PI, drive_cmd.x, velocity.theta, drive_cmd.theta);
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// robot::log_info_at(__FILE__, __LINE__, "journey : %f lookahead_dist : %f",
|
// robot::log_info_at(__FILE__, __LINE__, "journey : %f lookahead_dist : %f",
|
||||||
// journey(transformed_plan.poses, 0, transformed_plan.poses.size() - 1), lookahead_dist);
|
// journey(transformed_plan.poses, 0, transformed_plan.poses.size() - 1), lookahead_dist);
|
||||||
if(fabs(carrot_pose.pose.y) > 0.2)
|
if(fabs(carrot_pose.pose.y) > 0.2)
|
||||||
@@ -151,7 +151,7 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::GoStraight::calculator(
|
|||||||
lookahead_dist = sqrt(carrot_pose.pose.y *carrot_pose.pose.y + lookahead_dist * lookahead_dist);
|
lookahead_dist = sqrt(carrot_pose.pose.y *carrot_pose.pose.y + lookahead_dist * lookahead_dist);
|
||||||
}
|
}
|
||||||
robot_nav_2d_msgs::Twist2D drive_target;
|
robot_nav_2d_msgs::Twist2D drive_target;
|
||||||
transformed_plan = this->generateTrajectory(transformed_plan, drive_cmd, velocity, sign_x, drive_target);
|
transformed_plan = this->generateTrajectory(transformed_plan, drive_cmd, velocity, sign_x, drive_target, dt);
|
||||||
carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
||||||
|
|
||||||
// Normal Pure Pursuit
|
// Normal Pure Pursuit
|
||||||
@@ -164,7 +164,7 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::GoStraight::calculator(
|
|||||||
sign_x,
|
sign_x,
|
||||||
dt,
|
dt,
|
||||||
drive_cmd);
|
drive_cmd);
|
||||||
}
|
// }
|
||||||
applyDistanceSpeedScaling(compute_plan_, velocity, drive_cmd, sign_x, dt);
|
applyDistanceSpeedScaling(compute_plan_, velocity, drive_cmd, sign_x, dt);
|
||||||
|
|
||||||
if (this->nav_stop_)
|
if (this->nav_stop_)
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ bool mkt_algorithm::diff::PredictiveTrajectory::prepare(const robot_nav_2d_msgs:
|
|||||||
robot::log_warning("[%s:%d]\n Could not transform the global plan to the frame of the controller", __FILE__, __LINE__);
|
robot::log_warning("[%s:%d]\n Could not transform the global plan to the frame of the controller", __FILE__, __LINE__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transform_plan_);
|
const auto carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transform_plan_);
|
||||||
if(fabs(carrot_pose.pose.y) > 0.2)
|
if(fabs(carrot_pose.pose.y) > 0.2)
|
||||||
{
|
{
|
||||||
@@ -443,8 +444,8 @@ bool mkt_algorithm::diff::PredictiveTrajectory::prepare(const robot_nav_2d_msgs:
|
|||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
robot::log_error("[%s:%d]\n getLookAheadPoint throw an exception: %s", __FILE__, __LINE__, e.what());
|
robot::log_warning_throttle(0.2, "[%s:%d]\n getLookAheadPoint throw an exception: %s", __FILE__, __LINE__, e.what());
|
||||||
return false;
|
x_direction = x_direction_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,8 +520,12 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::PredictiveTrajectory::calculator(
|
|||||||
const double distance_allow_rotate = min_journey_squared_;
|
const double distance_allow_rotate = min_journey_squared_;
|
||||||
const double path_distance_to_rotate = journey(transformed_plan.poses, 0, transformed_plan.poses.size() - 1);
|
const double path_distance_to_rotate = journey(transformed_plan.poses, 0, transformed_plan.poses.size() - 1);
|
||||||
allow_rotate |= path_distance_to_rotate >= distance_allow_rotate;
|
allow_rotate |= path_distance_to_rotate >= distance_allow_rotate;
|
||||||
allow_rotate &= std::hypot(compute_plan_.poses.front().pose.x - pose.pose.x, compute_plan_.poses.front().pose.y - pose.pose.y) <= 0.1;
|
// robot_geometry_msgs::Pose2D back_pose = transformed_plan.poses.back().pose;
|
||||||
double angle_to_heading;
|
// allow_rotate |= fabs(atan2(back_pose.y, back_pose.x) - back_pose.theta) > M_PI / 3.0;
|
||||||
|
|
||||||
|
allow_rotate &= (fabs(transformed_plan.poses.front().pose.y) <= 0.5);
|
||||||
|
|
||||||
|
double angle_to_heading;
|
||||||
if (allow_rotate && shouldRotateToPath(transformed_plan, carrot_pose, velocity, angle_to_heading, sign_x))
|
if (allow_rotate && shouldRotateToPath(transformed_plan, carrot_pose, velocity, angle_to_heading, sign_x))
|
||||||
{
|
{
|
||||||
if (!stopped(velocity, max_vel_theta_ + rot_stopped_velocity_, trans_stopped_velocity_))
|
if (!stopped(velocity, max_vel_theta_ + rot_stopped_velocity_, trans_stopped_velocity_))
|
||||||
@@ -549,7 +554,7 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::PredictiveTrajectory::calculator(
|
|||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
robot_nav_2d_msgs::Twist2D drive_target = drive_cmd;
|
robot_nav_2d_msgs::Twist2D drive_target = drive_cmd;
|
||||||
transformed_plan = this->generateTrajectory(transformed_plan, drive_cmd, velocity, sign_x, drive_target);
|
transformed_plan = this->generateTrajectory(transformed_plan, drive_cmd, velocity, sign_x, drive_target, dt);
|
||||||
carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
carrot_pose = *getLookAheadPoint(velocity, lookahead_dist, transformed_plan);
|
||||||
|
|
||||||
// Normal Pure Pursuit
|
// Normal Pure Pursuit
|
||||||
@@ -576,6 +581,7 @@ mkt_msgs::Trajectory2D mkt_algorithm::diff::PredictiveTrajectory::calculator(
|
|||||||
result.velocity = drive_cmd;
|
result.velocity = drive_cmd;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
result.poses.clear();
|
result.poses.clear();
|
||||||
result.poses.reserve(transformed_plan.poses.size());
|
result.poses.reserve(transformed_plan.poses.size());
|
||||||
@@ -619,15 +625,15 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
|
|
||||||
// 3) Adjust speed using Hermite trajectory curvature + remaining distance
|
// 3) Adjust speed using Hermite trajectory curvature + remaining distance
|
||||||
double v_target = adjustSpeedWithHermiteTrajectory(velocity, trajectory, drive_target.x, sign_x);
|
double v_target = adjustSpeedWithHermiteTrajectory(velocity, trajectory, drive_target.x, sign_x);
|
||||||
const double L_min = 0.1; // m, chỉnh theo nhu cầu
|
// const double L_min = 0.1; // m, chỉnh theo nhu cầu
|
||||||
double scale_close = std::clamp(L / L_min, 0.0, 1.0);
|
// double scale_close = std::clamp(L / L_min, 0.0, 1.0);
|
||||||
v_target *= scale_close;
|
// v_target *= scale_close;
|
||||||
const double y_abs = std::fabs(carrot_pose.pose.y);
|
const double y_abs = std::fabs(carrot_pose.pose.y);
|
||||||
const double y_soft = 0.1;
|
const double y_soft = 0.1;
|
||||||
if (y_abs > y_soft)
|
if (y_abs > y_soft)
|
||||||
{
|
{
|
||||||
double scale = y_soft / y_abs; // y càng lớn => scale càng nhỏ
|
double scale = y_soft / y_abs; // y càng lớn => scale càng nhỏ
|
||||||
scale = std::clamp(scale, 0.2, 1.0); // không giảm quá sâu
|
scale = std::clamp(scale, 0.6, 1.0); // không giảm quá sâu
|
||||||
v_target *= scale;
|
v_target *= scale;
|
||||||
robot_nav_2d_msgs::Twist2D cmd, result;
|
robot_nav_2d_msgs::Twist2D cmd, result;
|
||||||
cmd.x = v_target;
|
cmd.x = v_target;
|
||||||
@@ -638,9 +644,6 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
// 4) Maintain minimum approach speed
|
// 4) Maintain minimum approach speed
|
||||||
if (std::fabs(v_target) < min_approach_linear_velocity)
|
if (std::fabs(v_target) < min_approach_linear_velocity)
|
||||||
v_target = std::copysign(min_approach_linear_velocity, sign_x);
|
v_target = std::copysign(min_approach_linear_velocity, sign_x);
|
||||||
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
// 5) Angular speed from curvature
|
// 5) Angular speed from curvature
|
||||||
double w_target = v_target * kappa;
|
double w_target = v_target * kappa;
|
||||||
if(journey(trajectory.poses, 0, trajectory.poses.size() - 1) <= min_journey_squared_)
|
if(journey(trajectory.poses, 0, trajectory.poses.size() - 1) <= min_journey_squared_)
|
||||||
@@ -658,7 +661,6 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
if(fabs(dx) < 1e-6 && fabs(dy) < 1e-6)
|
if(fabs(dx) < 1e-6 && fabs(dy) < 1e-6)
|
||||||
continue;
|
continue;
|
||||||
heading_ref = std::atan2(dy, dx);
|
heading_ref = std::atan2(dy, dx);
|
||||||
ss << "error " << heading_ref << " ";
|
|
||||||
if(sign_x < 0.0)
|
if(sign_x < 0.0)
|
||||||
heading_ref += std::copysign(M_PI, heading_ref) * (-1.0);
|
heading_ref += std::copysign(M_PI, heading_ref) * (-1.0);
|
||||||
break;
|
break;
|
||||||
@@ -666,7 +668,6 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const double error = heading_ref;
|
const double error = heading_ref;
|
||||||
ss << error << " ";
|
|
||||||
double w_heading = 0.0;
|
double w_heading = 0.0;
|
||||||
pid(error,
|
pid(error,
|
||||||
near_goal_heading_integral_,
|
near_goal_heading_integral_,
|
||||||
@@ -678,9 +679,8 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
w_heading);
|
w_heading);
|
||||||
// Apply acceleration limits
|
// Apply acceleration limits
|
||||||
double dw_heading = std::clamp(w_heading - velocity.theta, -acc_lim_theta_ * dt, acc_lim_theta_ * dt);
|
double dw_heading = std::clamp(w_heading - velocity.theta, -acc_lim_theta_ * dt, acc_lim_theta_ * dt);
|
||||||
ss << "dw_heading " << dw_heading << " ";
|
|
||||||
w_target = velocity.theta + dw_heading;
|
w_target = velocity.theta + dw_heading;
|
||||||
// w_target = std::clamp(w_target, -0.03, 0.03);
|
w_target = std::clamp(w_target, -fabs(drive_target.theta), fabs(drive_target.theta));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -692,7 +692,6 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
{
|
{
|
||||||
near_goal_heading_was_active_ = false;
|
near_goal_heading_was_active_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
w_target = std::clamp(w_target, -fabs(drive_target.theta), fabs(drive_target.theta));
|
w_target = std::clamp(w_target, -fabs(drive_target.theta), fabs(drive_target.theta));
|
||||||
|
|
||||||
// 6) Apply acceleration limits (linear + angular)
|
// 6) Apply acceleration limits (linear + angular)
|
||||||
@@ -701,7 +700,7 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
|
|
||||||
drive_cmd.x = velocity.x + dv;
|
drive_cmd.x = velocity.x + dv;
|
||||||
drive_cmd.theta = velocity.theta + dw;
|
drive_cmd.theta = velocity.theta + dw;
|
||||||
|
|
||||||
Eigen::VectorXd y(2);
|
Eigen::VectorXd y(2);
|
||||||
y << drive_cmd.x, drive_cmd.theta;
|
y << drive_cmd.x, drive_cmd.theta;
|
||||||
|
|
||||||
@@ -720,8 +719,8 @@ void mkt_algorithm::diff::PredictiveTrajectory::computePurePursuit(
|
|||||||
drive_cmd.x = std::clamp(kf_->state()[0], -fabs(v_target), fabs(v_target));
|
drive_cmd.x = std::clamp(kf_->state()[0], -fabs(v_target), fabs(v_target));
|
||||||
drive_cmd.x = fabs(drive_cmd.x) >= v_min ? drive_cmd.x : std::copysign(v_min, sign_x);
|
drive_cmd.x = fabs(drive_cmd.x) >= v_min ? drive_cmd.x : std::copysign(v_min, sign_x);
|
||||||
if (kf_filter_angular_)
|
if (kf_filter_angular_)
|
||||||
drive_cmd.theta = std::clamp(kf_->state()[3], -max_vel_theta_, max_vel_theta_);
|
drive_cmd.theta = std::clamp(kf_->state()[3], -fabs(drive_target.theta), fabs(drive_target.theta));
|
||||||
// robot::log_info("%s", ss.str().c_str());
|
// robot::log_info("drive_cmd.theta: %f, drive_target.theta: %f", drive_cmd.theta, drive_target.theta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mkt_algorithm::diff::PredictiveTrajectory::applyDistanceSpeedScaling(
|
void mkt_algorithm::diff::PredictiveTrajectory::applyDistanceSpeedScaling(
|
||||||
@@ -745,8 +744,9 @@ void mkt_algorithm::diff::PredictiveTrajectory::applyDistanceSpeedScaling(
|
|||||||
double cosine_factor = 0.5 * (1.0 + std::cos(M_PI * (1.0 - r)));
|
double cosine_factor = 0.5 * (1.0 + std::cos(M_PI * (1.0 - r)));
|
||||||
target_speed = max_speed * cosine_factor;
|
target_speed = max_speed * cosine_factor;
|
||||||
}
|
}
|
||||||
|
const double v_limited = sign_x > 0 ? traj_->getTwistLinear(true).x : traj_->getTwistLinear(false).x;
|
||||||
double reduce_speed = std::min(max_speed, min_speed_xy_);
|
const double v_min = std::min(fabs(v_limited), min_speed_xy_);
|
||||||
|
double reduce_speed = std::min(max_speed, v_min);
|
||||||
if (s < S_final)
|
if (s < S_final)
|
||||||
{
|
{
|
||||||
double r = std::clamp(s / S_final, 0.0, 1.0);
|
double r = std::clamp(s / S_final, 0.0, 1.0);
|
||||||
@@ -818,12 +818,6 @@ bool mkt_algorithm::diff::PredictiveTrajectory::shouldRotateToPath(
|
|||||||
#ifdef BUILD_WITH_ROS
|
#ifdef BUILD_WITH_ROS
|
||||||
if (result)
|
if (result)
|
||||||
ROS_WARN_THROTTLE(0.1, "angle_to_path: %f, heading_rotate: %f, is_stopped: %x %x, sign_x: %f", angle_to_path, heading_rotate, is_stopped, sign(angle_to_path) * sign_x < 0, sign_x);
|
ROS_WARN_THROTTLE(0.1, "angle_to_path: %f, heading_rotate: %f, is_stopped: %x %x, sign_x: %f", angle_to_path, heading_rotate, is_stopped, sign(angle_to_path) * sign_x < 0, sign_x);
|
||||||
|
|
||||||
// else if(fabs(velocity.x) < min_speed_xy_)
|
|
||||||
// {
|
|
||||||
// ROS_INFO_THROTTLE(0.1, "velocity.x: %f, velocity.theta: %f, ", velocity.x, velocity.theta);
|
|
||||||
// ROS_INFO_THROTTLE(0.1, "angle_to_path: %f, heading_rotate: %f, is_stopped: %x %x, sign_x: %f", angle_to_path, heading_rotate, is_stopped, sign(angle_to_path) * sign_x < 0, sign_x);
|
|
||||||
// }
|
|
||||||
#else
|
#else
|
||||||
if (result)
|
if (result)
|
||||||
robot::log_info_throttle(0.1, "angle_to_path: %f, heading_rotate: %f, is_stopped: %x %x, sign_x: %f", angle_to_path, heading_rotate, is_stopped, sign(angle_to_path) * sign_x < 0, sign_x);
|
robot::log_info_throttle(0.1, "angle_to_path: %f, heading_rotate: %f, is_stopped: %x %x, sign_x: %f", angle_to_path, heading_rotate, is_stopped, sign(angle_to_path) * sign_x < 0, sign_x);
|
||||||
@@ -963,8 +957,10 @@ void mkt_algorithm::diff::PredictiveTrajectory::alignToFinalHeading(
|
|||||||
// --- Linear velocity calculation ---
|
// --- Linear velocity calculation ---
|
||||||
// Base velocity proportional to distance, with minimum for smooth motion
|
// Base velocity proportional to distance, with minimum for smooth motion
|
||||||
double v_base = std::sqrt(2.0 * std::fabs(decel_lim_x_) * xy_error);
|
double v_base = std::sqrt(2.0 * std::fabs(decel_lim_x_) * xy_error);
|
||||||
|
const double v_limited = sign_x > 0 ? traj_->getTwistLinear(true).x : traj_->getTwistLinear(false).x;
|
||||||
|
const double v_min = std::min(fabs(v_limited), min_speed_xy_);
|
||||||
v_base = std::max(v_base, final_heading_min_velocity_);
|
v_base = std::max(v_base, final_heading_min_velocity_);
|
||||||
v_base = std::min(v_base, min_speed_xy_);
|
v_base = std::min(v_base, v_min);
|
||||||
|
|
||||||
// Scale down when heading error is large (prioritize rotation)
|
// Scale down when heading error is large (prioritize rotation)
|
||||||
double heading_scale = 1.0;
|
double heading_scale = 1.0;
|
||||||
@@ -1036,7 +1032,7 @@ void mkt_algorithm::diff::PredictiveTrajectory::alignToFinalHeading(
|
|||||||
cmd_vel.theta = omega_current + domega;
|
cmd_vel.theta = omega_current + domega;
|
||||||
|
|
||||||
// --- Apply velocity limits ---
|
// --- Apply velocity limits ---
|
||||||
cmd_vel.x = std::clamp(cmd_vel.x, -min_speed_xy_, min_speed_xy_);
|
cmd_vel.x = std::clamp(cmd_vel.x, -v_min, v_min);
|
||||||
cmd_vel.theta = std::clamp(cmd_vel.theta, -max_vel_theta_, max_vel_theta_);
|
cmd_vel.theta = std::clamp(cmd_vel.theta, -max_vel_theta_, max_vel_theta_);
|
||||||
|
|
||||||
// --- Safety: ensure we can stop ---
|
// --- Safety: ensure we can stop ---
|
||||||
@@ -1218,9 +1214,11 @@ double mkt_algorithm::diff::PredictiveTrajectory::adjustSpeedWithHermiteTrajecto
|
|||||||
double v_limit = std::fabs(v_target);
|
double v_limit = std::fabs(v_target);
|
||||||
double journey_distance = journey(trajectory.poses, 0, trajectory.poses.size() - 1);
|
double journey_distance = journey(trajectory.poses, 0, trajectory.poses.size() - 1);
|
||||||
|
|
||||||
|
const double v_limited = sign_x > 0 ? traj_->getTwistLinear(true).x : traj_->getTwistLinear(false).x;
|
||||||
|
const double v_min = std::min(fabs(v_limited), min_speed_xy_);
|
||||||
if (journey_distance < min_journey_squared_)
|
if (journey_distance < min_journey_squared_)
|
||||||
{
|
{
|
||||||
v_limit = std::clamp(sqrt(2.0 * fabs(decel_lim_x_) * journey_distance), min_approach_linear_velocity_, min_speed_xy_) * sign_x;
|
v_limit = std::clamp(sqrt(2.0 * fabs(decel_lim_x_) * journey_distance), min_approach_linear_velocity_, v_min) * sign_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_kappa > 1e-6 && max_lateral_accel_ > 1e-6)
|
if (max_kappa > 1e-6 && max_lateral_accel_ > 1e-6)
|
||||||
@@ -1230,7 +1228,7 @@ double mkt_algorithm::diff::PredictiveTrajectory::adjustSpeedWithHermiteTrajecto
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(trajectory.poses.size() > 2 && fabs(trajectory.poses.front().pose.theta) >= angle_threshold_)
|
if(trajectory.poses.size() > 2 && fabs(trajectory.poses.front().pose.theta) >= angle_threshold_)
|
||||||
v_limit = min_speed_xy_ * sign_x;
|
v_limit = v_min * sign_x;
|
||||||
|
|
||||||
if (fabs(decel_lim_x_) > 1e-6)
|
if (fabs(decel_lim_x_) > 1e-6)
|
||||||
{
|
{
|
||||||
@@ -1248,7 +1246,8 @@ robot_nav_2d_msgs::Path2D mkt_algorithm::diff::PredictiveTrajectory::generateTra
|
|||||||
const robot_nav_2d_msgs::Twist2D &drive_target,
|
const robot_nav_2d_msgs::Twist2D &drive_target,
|
||||||
const robot_nav_2d_msgs::Twist2D &velocity,
|
const robot_nav_2d_msgs::Twist2D &velocity,
|
||||||
const double &sign_x,
|
const double &sign_x,
|
||||||
robot_nav_2d_msgs::Twist2D &drive_cmd)
|
robot_nav_2d_msgs::Twist2D &drive_cmd,
|
||||||
|
const double &dt)
|
||||||
{
|
{
|
||||||
if (path.poses.empty())
|
if (path.poses.empty())
|
||||||
{
|
{
|
||||||
@@ -1256,23 +1255,30 @@ robot_nav_2d_msgs::Path2D mkt_algorithm::diff::PredictiveTrajectory::generateTra
|
|||||||
drive_cmd.theta = 0.0;
|
drive_cmd.theta = 0.0;
|
||||||
return robot_nav_2d_msgs::Path2D();
|
return robot_nav_2d_msgs::Path2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drive_cmd.x = drive_target.x;
|
||||||
|
drive_cmd.theta = max_vel_theta_;
|
||||||
double max_kappa = calculateMaxKappa(path);
|
double max_kappa = calculateMaxKappa(path);
|
||||||
const double straight_threshold = std::max(0.05, 2.0 * (costmap_robot_ ? costmap_robot_->getCostmap()->getResolution() : 0.05));
|
const double straight_threshold = std::max(0.05, 2.0 * (costmap_robot_ ? costmap_robot_->getCostmap()->getResolution() : 0.05));
|
||||||
drive_cmd.x = this->adjustSpeedWithHermiteTrajectory(velocity, path, drive_target.x, sign_x);
|
// nếu đường thẳng
|
||||||
drive_cmd.theta = max_vel_theta_;
|
if (max_kappa <= straight_threshold)
|
||||||
|
|
||||||
if (max_kappa <= straight_threshold && fabs(path.poses.back().pose.x) < min_lookahead_dist_) // nếu đường thẳng
|
|
||||||
{
|
{
|
||||||
if(fabs(path.poses.front().pose.y) <= 0.03 && fabs(path.poses.back().pose.x) < min_lookahead_dist_ )
|
if(fabs(path.poses.back().pose.x) < min_lookahead_dist_ * 0.8)
|
||||||
{
|
{
|
||||||
|
if(fabs(path.poses.back().pose.x) < min_journey_squared_)
|
||||||
|
drive_cmd.theta = 0.01;
|
||||||
return generateParallelPath(path, sign_x);
|
return generateParallelPath(path, sign_x);
|
||||||
}
|
}
|
||||||
return generateHermiteTrajectory(path, sign_x);
|
return generateHermiteTrajectory(path, sign_x);
|
||||||
}
|
}
|
||||||
else // nếu đường cong
|
else // nếu đường cong
|
||||||
{
|
{
|
||||||
if(fabs(drive_cmd.x) < min_speed_xy_)
|
const double v_limited = sign_x > 0 ? traj_->getTwistLinear(true).x : traj_->getTwistLinear(false).x;
|
||||||
drive_cmd.x = std::copysign(min_speed_xy_, sign_x);
|
const double v_min = std::min(fabs(v_limited), min_speed_xy_);
|
||||||
|
if(fabs(drive_cmd.x) < v_min)
|
||||||
|
{
|
||||||
|
drive_cmd.x = std::copysign(v_min, sign_x);
|
||||||
|
}
|
||||||
return generateHermiteQuadraticTrajectory(path, sign_x);
|
return generateHermiteQuadraticTrajectory(path, sign_x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1317,8 +1323,6 @@ robot_nav_2d_msgs::Path2D mkt_algorithm::diff::PredictiveTrajectory::generatePar
|
|||||||
return parallel_path;
|
return parallel_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
robot_nav_2d_msgs::Path2D mkt_algorithm::diff::PredictiveTrajectory::generateHermiteTrajectory(
|
robot_nav_2d_msgs::Path2D mkt_algorithm::diff::PredictiveTrajectory::generateHermiteTrajectory(
|
||||||
const robot_nav_2d_msgs::Path2D &path, const double &sign_x)
|
const robot_nav_2d_msgs::Path2D &path, const double &sign_x)
|
||||||
{
|
{
|
||||||
|
|||||||
Submodule src/Algorithms/Packages/global_planners/custom_planner updated: 62a493a892...49ea9fe7f5
Submodule src/Libraries/robot_time updated: 0c007fdab3...75075a3498
Reference in New Issue
Block a user