Skip to content

Commit 548bc69

Browse files
feat(autoware_diffusion_planner): gradual drift and deviation on turns and reducing jitter (#3239)
* feat(mppi): fix for gradual drift Co-authored-by: Cursor <cursoragent@cursor.com> * using coloured noise; changed reference to be time-based tracking; param updates Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * param update; removed unecessary projections Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * new tunings after test Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * fix to plots Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * fixes Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * updates to debug Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * changes for adding lateral error to cost structure Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * fixes Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> * fix Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> --------- Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ce47baf commit 548bc69

18 files changed

Lines changed: 1448 additions & 517 deletions

planning/autoware_diffusion_planner/include/autoware/diffusion_planner/diffusion_planner_node.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <autoware_planning_msgs/msg/trajectory.hpp>
4545
#include <autoware_vehicle_msgs/msg/steering_report.hpp>
4646
#include <autoware_vehicle_msgs/msg/turn_indicators_command.hpp>
47+
#include <std_msgs/msg/bool.hpp>
4748
#include <std_msgs/msg/float32_multi_array.hpp>
4849
#include <std_msgs/msg/float64.hpp>
4950
#include <std_srvs/srv/set_bool.hpp>
@@ -180,6 +181,9 @@ class DiffusionPlanner : public rclcpp::Node
180181
const autoware::mppi_optimizer::FirstOrderDubinsMppiDebug & debug, const std::string & frame_id,
181182
const rclcpp::Time & stamp);
182183

184+
/** Publish whether MPPI is currently applied to the output trajectory. */
185+
void publish_mppi_enabled(bool enabled);
186+
183187
/**
184188
* @brief Publish guidance triggered status as a debug message.
185189
* @param guidance_triggered Map of guidance name to triggered flags per batch.
@@ -232,6 +236,7 @@ class DiffusionPlanner : public rclcpp::Node
232236
rclcpp::Publisher<Trajectory>::SharedPtr pub_mppi_reference_trajectory_{nullptr};
233237
rclcpp::Publisher<Trajectory>::SharedPtr pub_mppi_optimized_trajectory_{nullptr};
234238
rclcpp::Publisher<MarkerArray>::SharedPtr pub_mppi_markers_{nullptr};
239+
rclcpp::Publisher<std_msgs::msg::Bool>::SharedPtr pub_mppi_enabled_{nullptr};
235240
rclcpp::Publisher<CandidateTrajectories>::SharedPtr pub_trajectories_{nullptr};
236241
rclcpp::Publisher<PredictedObjects>::SharedPtr pub_objects_{nullptr};
237242
rclcpp::Publisher<MarkerArray>::SharedPtr pub_lane_marker_{nullptr};

planning/autoware_diffusion_planner/src/diffusion_planner_node.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ DiffusionPlanner::DiffusionPlanner(const rclcpp::NodeOptions & options)
9292
pub_mppi_optimized_trajectory_ =
9393
this->create_publisher<Trajectory>("~/debug/mppi/optimized_trajectory", 1);
9494
pub_mppi_markers_ = this->create_publisher<MarkerArray>("~/debug/mppi/markers", 1);
95+
// Latched so late-joining debug tools see the current enable state immediately.
96+
pub_mppi_enabled_ = this->create_publisher<std_msgs::msg::Bool>(
97+
"~/debug/mppi/enabled", rclcpp::QoS{1}.transient_local());
9598
pub_trajectories_ = this->create_publisher<CandidateTrajectories>("~/output/trajectories", 1);
9699
pub_objects_ =
97100
this->create_publisher<PredictedObjects>("~/output/predicted_objects", rclcpp::QoS(1));
@@ -116,6 +119,7 @@ DiffusionPlanner::DiffusionPlanner(const rclcpp::NodeOptions & options)
116119
"~/debug/guidance_status", 1);
117120

118121
set_up_params();
122+
publish_mppi_enabled(params_.use_mppi_optimizer && !params_.shadow_mode);
119123
vehicle_info_ = autoware::vehicle_info_utils::VehicleInfoUtils(*this).getVehicleInfo();
120124

121125
// Create core instance
@@ -394,6 +398,7 @@ SetParametersResult DiffusionPlanner::on_parameter(
394398
temp_params.line_string_max_step_m != previous_line_string_max_step_m;
395399
params_ = temp_params;
396400
core_->update_params(params_);
401+
publish_mppi_enabled(params_.use_mppi_optimizer && !params_.shadow_mode);
397402

398403
if (
399404
args_path_changed || model_paths_changed || batch_size_changed || dpm_solver_steps_changed ||
@@ -683,9 +688,11 @@ void DiffusionPlanner::on_timer()
683688
driving_along_targets, frame_context->ego_kinematic_state.pose.pose.position.z));
684689
record_section_time(
685690
*stop_watch_ptr_, "mppi_optimizer/optimize_trajectory", *diagnostics_inference_);
686-
if (!params_.shadow_mode) {
691+
const bool apply_mppi = !params_.shadow_mode;
692+
if (apply_mppi) {
687693
planner_output.trajectory = mppi_result.trajectory;
688694
}
695+
publish_mppi_enabled(apply_mppi);
689696

690697
autoware_utils_debug::ScopedTimeTrack publish_debug_st(
691698
"mppi_optimizer/publish_debug", *time_keeper_);
@@ -698,12 +705,15 @@ void DiffusionPlanner::on_timer()
698705
record_section_time(
699706
*stop_watch_ptr_, "mppi_optimizer/publish_debug", *diagnostics_inference_);
700707
} catch (const std::runtime_error & e) {
708+
publish_mppi_enabled(false);
701709
RCLCPP_ERROR_STREAM(get_logger(), "MPPI optimization failed: " << e.what());
702710
diagnostics_inference_->update_level_and_message(DiagnosticStatus::ERROR, e.what());
703711
diagnostics_inference_->publish(frame_time);
704712
return;
705713
}
706714
record_section_time(*stop_watch_ptr_, "mppi_optimizer", *diagnostics_inference_);
715+
} else {
716+
publish_mppi_enabled(false);
707717
}
708718

709719
publish_guidance_status(planner_output.guidance_triggered, frame_time);
@@ -765,6 +775,13 @@ void DiffusionPlanner::publish_guidance_status(
765775
pub_guidance_status_->publish(msg);
766776
}
767777

778+
void DiffusionPlanner::publish_mppi_enabled(bool enabled)
779+
{
780+
std_msgs::msg::Bool msg;
781+
msg.data = enabled;
782+
pub_mppi_enabled_->publish(msg);
783+
}
784+
768785
void DiffusionPlanner::publish_mppi_debug(
769786
const autoware::mppi_optimizer::FirstOrderDubinsMppiDebug & debug, const std::string & frame_id,
770787
const rclcpp::Time & stamp)

planning/autoware_mppi_optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ if(CUDA_AVAIL AND TRT_AVAIL)
8585
autoware_vehicle_msgs::autoware_vehicle_msgs__rosidl_generator_cpp
8686
geometry_msgs::geometry_msgs__rosidl_generator_cpp
8787
nav_msgs::nav_msgs__rosidl_generator_cpp
88+
${CUDA_cufft_LIBRARY}
8889
)
8990
set_target_properties(first_order_dubins_mppi PROPERTIES
9091
POSITION_INDEPENDENT_CODE ON

planning/autoware_mppi_optimizer/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Various features can be disabled by changing the following parameters set in `mp
6969
ignore_obstacles: true
7070
ignore_drivable_area: true
7171
force_cold_start_each_step: true
72+
use_last_control_as_nominal: true
7273
```
7374
7475
Then rebuild / restart the diffusion planner and compare live MPPI to offline retune.
@@ -79,7 +80,9 @@ Notes:
7980
- `ignore_drivable_area` is retained as an ablation flag; on this stack boundary crash is already
8081
disabled in the cost (`isEgoOutsideDrivableArea` always false).
8182
- `force_cold_start_each_step` only resets tracking counters / arc-length (control is already
82-
re-seeded from the reference via `updateImportanceSampler(u_nom)` each cycle).
83+
re-seeded via `updateImportanceSampler(u_nom)` each cycle).
84+
- `use_last_control_as_nominal` warm-starts `u_nom` from the shifted previous optimized control
85+
sequence when available; otherwise (and on cold start) reseeds from the diffusion reference.
8386

8487
### Replay only
8588

planning/autoware_mppi_optimizer/config/mppi_optimizer.param.yaml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
ros__parameters:
33
# Vehicle actuation dynamics are loaded from $(vehicle_model)_description/config/simulator_model.param.yaml
44

5-
# MPPI controller / FirstOrderDubinsBicycleCostParams
6-
# (see first_order_dubins_mppi_interface.cu, first_order_dubins_bicycle_cost.cuh)
7-
lambda: 3000.0
5+
# FirstOrderDubinsBicycleCostParams (see first_order_dubins_bicycle_cost.cuh)
6+
lambda: 100.0
87
desired_speed: 2.5
9-
speed_coeff: 500.0
8+
speed_coeff: 0.0
109
track_coeff: 1000.0
11-
heading_coeff: 500.0
12-
crash_coeff: 100000.0
10+
track_terminal_scale: 10.0
11+
heading_coeff: 100.0
12+
# Spatial (closest-segment) costs restored from pre time-indexed tracking; 0 = off.
13+
lateral_distance_coeff: 0.0
14+
lateral_yaw_error_coeff: 0.0
15+
crash_coeff: 10000.0
1316
boundary_threshold: 0.8
1417
boundary_threshold_left: -1.0
1518
boundary_threshold_right: -1.0
16-
lateral_acceleration_coeff: 500.0
17-
lateral_jerk_coeff: 3000.0
18-
longitudinal_jerk_coeff: 1000.0
19-
accel_cmd_coeff: 200.0
20-
steer_cmd_coeff: 1000.0
21-
steer_rate_coeff: 5000.0
22-
goal_pos_coeff: 1000.0
23-
goal_speed_coeff: 200.0
24-
goal_yaw_coeff: 500.0
25-
goal_terminal_scale: 10.0
19+
lateral_acceleration_coeff: 0.0
20+
lateral_jerk_coeff: 150.0
21+
longitudinal_jerk_coeff: 150.0
22+
accel_cmd_coeff: 50.0
23+
steer_cmd_coeff: 0.0
24+
steer_rate_coeff: 0.0
2625
obstacle_collision_margin: 0.2
2726
road_border_collision_margin: 0.2
2827
drivable_area_crossing_coeff: 500.0
@@ -37,3 +36,5 @@
3736
ignore_drivable_area: true
3837
force_cold_start_each_step: false
3938
skip_if_invalid: true # if the MPPI output is invalid (i.e., collides with obstacles or road borders), the input reference is returned
39+
# Warm-start u_nom from shifted previous optimized controls (else reseed from DP each cycle).
40+
use_last_control_as_nominal: true

planning/autoware_mppi_optimizer/include/autoware/mppi_optimizer/first_order_dubins_mppi_cost_params.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ struct FirstOrderDubinsMppiCostParams
2727
float desired_speed{3.0F};
2828
float speed_coeff{500.0F};
2929
float track_coeff{1000.0F};
30+
float track_terminal_scale{10.0F};
3031
float heading_coeff{500.0F};
32+
float lateral_distance_coeff{0.0F};
33+
float lateral_yaw_error_coeff{0.0F};
3134
float crash_coeff{100000.0F};
3235
float boundary_threshold{1.5F};
3336
float boundary_threshold_left{-1.0F};
3437
float boundary_threshold_right{-1.0F};
3538
float accel_cmd_coeff{0.0F};
3639
float steer_cmd_coeff{0.0F};
40+
3741
float steer_rate_coeff{0.0F};
3842
float lateral_acceleration_coeff{300.0F};
3943
float lateral_jerk_coeff{300.0F};
4044
float longitudinal_jerk_coeff{10.0F};
4145
float obstacle_collision_margin{0.5F};
4246
float road_border_collision_margin{0.2F};
4347
float drivable_area_crossing_coeff{10000.0F};
44-
float goal_pos_coeff{1000.0F};
45-
float goal_speed_coeff{0.0F};
46-
float goal_yaw_coeff{500.0F};
47-
float goal_terminal_scale{10.0F};
4848
};
4949

5050
} // namespace autoware::mppi_optimizer

planning/autoware_mppi_optimizer/include/autoware/mppi_optimizer/first_order_dubins_mppi_interface.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ class FirstOrderDubinsMppiInterface
121121

122122
/**
123123
* @brief Ablation options to mirror mppi_offline_retune conditions in online sim.
124+
* @param use_last_control_as_nominal When true and a previous optimized control sequence
125+
* exists, seed u_nom by shifting that sequence (warm start) instead of reseeding
126+
* from the diffusion reference every cycle.
124127
*/
125128
void setAblationOptions(
126129
const bool ignore_obstacles, const bool ignore_drivable_area,
127-
const bool force_cold_start_each_step, const bool skip_if_invalid);
130+
const bool force_cold_start_each_step, const bool skip_if_invalid,
131+
bool use_last_control_as_nominal = false);
128132

129133
/**
130134
* @brief Copy per-rollout raw costs and normalized importance weights from the last
@@ -134,20 +138,26 @@ class FirstOrderDubinsMppiInterface
134138
bool copySampleCostDistribution(
135139
std::vector<float> & raw_costs, std::vector<float> & normalized_weights, int stride = 1) const;
136140

141+
/**
142+
* @brief When true, optimizeTrajectory fills debug.rollouts with top-K weighted samples
143+
* (CPU replay; ~tens of ms). Enable only for offline retune — leave false for online
144+
* planning and debug trajectory logging.
145+
*/
146+
void setRolloutVisualizationEnabled(bool enable);
147+
137148
/**
138149
* @brief Run one MPPI control step and propagate the vehicle state forward.
139150
* @param state Current ego state (updated in place).
140-
* @param arc_length Current arc length along the reference path (updated in place).
141151
* @param sim_time Current simulation time [s].
142152
*/
143-
FirstOrderDubinsMppiControl computeStep(
144-
FirstOrderDubinsMppiState & state, float & arc_length, float sim_time);
153+
FirstOrderDubinsMppiControl computeStep(FirstOrderDubinsMppiState & state, float sim_time);
145154

146155
/**
147156
* @brief Track a diffusion-planner reference (poses + velocities) with one MPPI step.
148157
*
149158
* Uses the diffusion trajectory directly as the MPPI reference horizon (x, y, yaw, v),
150-
* seeds u_nom from the reference trajectory controls each cycle, and returns the MPPI-predicted
159+
* seeds u_nom from the previous optimized controls when use_last_control_as_nominal is set
160+
* (otherwise from the reference trajectory), and returns the MPPI-predicted
151161
* feasible state rollout that best tracks that reference.
152162
*
153163
* @param input Reference trajectory from the diffusion planner (map frame).

planning/autoware_mppi_optimizer/include/autoware/mppi_optimizer/first_order_dubins_mppi_runtime_options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct FirstOrderDubinsMppiRuntimeOptions
3030
bool ignore_drivable_area{false};
3131
bool force_cold_start_each_step{false};
3232
bool skip_if_invalid{false};
33+
/** Warm-start u_nom from shifted previous optimized controls (else reseed from DP each cycle). */
34+
bool use_last_control_as_nominal{false};
3335
};
3436

3537
} // namespace autoware::mppi_optimizer

planning/autoware_mppi_optimizer/include/autoware/mppi_optimizer/mppi_debug_trajectory_io.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef AUTOWARE__MPPI_OPTIMIZER__MPPI_DEBUG_TRAJECTORY_IO_HPP_
1616
#define AUTOWARE__MPPI_OPTIMIZER__MPPI_DEBUG_TRAJECTORY_IO_HPP_
1717

18+
#include "autoware/mppi_optimizer/first_order_dubins_mppi_interface.hpp"
1819
#include "autoware/mppi_optimizer/mppi_debug_trajectory_logger.hpp"
1920

2021
#include <autoware_planning_msgs/msg/trajectory.hpp>
@@ -90,6 +91,25 @@ inline bool writeMppiDebugCostsCsv(
9091
return true;
9192
}
9293

94+
inline bool writeMppiDebugRolloutsCsv(
95+
const std::string & path, const std::vector<FirstOrderDubinsMppiRollout> & rollouts)
96+
{
97+
std::ofstream out(path);
98+
if (!out) {
99+
return false;
100+
}
101+
out << "rollout_index,cost,step,x,y\n";
102+
out << std::setprecision(9) << std::fixed;
103+
for (size_t r = 0; r < rollouts.size(); ++r) {
104+
const auto & rollout = rollouts[r];
105+
for (size_t s = 0; s < rollout.points.size(); ++s) {
106+
out << r << "," << rollout.cost << "," << s << "," << rollout.points[s].first << ","
107+
<< rollout.points[s].second << "\n";
108+
}
109+
}
110+
return true;
111+
}
112+
93113
inline bool loadMppiDebugTrajectoryCsv(
94114
const std::string & path, autoware_planning_msgs::msg::Trajectory & trajectory)
95115
{

planning/autoware_mppi_optimizer/include/autoware/mppi_optimizer/mppi_debug_trajectory_logger.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ class MppiDebugTrajectoryLogger
131131
out << "desired_speed," << cost.desired_speed << "\n";
132132
out << "speed_coeff," << cost.speed_coeff << "\n";
133133
out << "track_coeff," << cost.track_coeff << "\n";
134+
out << "track_terminal_scale," << cost.track_terminal_scale << "\n";
134135
out << "heading_coeff," << cost.heading_coeff << "\n";
136+
out << "lateral_distance_coeff," << cost.lateral_distance_coeff << "\n";
137+
out << "lateral_yaw_error_coeff," << cost.lateral_yaw_error_coeff << "\n";
135138
out << "crash_coeff," << cost.crash_coeff << "\n";
136139
out << "boundary_threshold," << cost.boundary_threshold << "\n";
137140
out << "boundary_threshold_left," << cost.boundary_threshold_left << "\n";
@@ -143,10 +146,6 @@ class MppiDebugTrajectoryLogger
143146
out << "lateral_jerk_coeff," << cost.lateral_jerk_coeff << "\n";
144147
out << "longitudinal_jerk_coeff," << cost.longitudinal_jerk_coeff << "\n";
145148
out << "obstacle_collision_margin," << cost.obstacle_collision_margin << "\n";
146-
out << "goal_pos_coeff," << cost.goal_pos_coeff << "\n";
147-
out << "goal_speed_coeff," << cost.goal_speed_coeff << "\n";
148-
out << "goal_yaw_coeff," << cost.goal_yaw_coeff << "\n";
149-
out << "goal_terminal_scale," << cost.goal_terminal_scale << "\n";
150149
}
151150
}
152151
{

0 commit comments

Comments
 (0)