15 #include "nav2_mppi_controller/tools/noise_generator.hpp"
28 is_holonomic_ = is_holonomic;
31 ndistribution_vx_ = std::normal_distribution(0.0f, settings_.sampling_std.vx);
32 ndistribution_vy_ = std::normal_distribution(0.0f, settings_.sampling_std.vy);
33 ndistribution_wz_ = std::normal_distribution(0.0f, settings_.sampling_std.wz);
36 getParam(regenerate_noises_,
"regenerate_noises",
false);
38 if (regenerate_noises_) {
49 noise_cond_.notify_all();
50 if (noise_thread_.joinable()) {
60 std::unique_lock<std::mutex> guard(noise_lock_);
63 noise_cond_.notify_all();
70 std::unique_lock<std::mutex> guard(noise_lock_);
72 state.cvx = noises_vx_.rowwise() + control_sequence.vx.transpose();
73 state.cvy = noises_vy_.rowwise() + control_sequence.vy.transpose();
74 state.cwz = noises_wz_.rowwise() + control_sequence.wz.transpose();
80 is_holonomic_ = is_holonomic;
84 std::unique_lock<std::mutex> guard(noise_lock_);
85 noises_vx_.setZero(settings_.batch_size, settings_.time_steps);
86 noises_vy_.setZero(settings_.batch_size, settings_.time_steps);
87 noises_wz_.setZero(settings_.batch_size, settings_.time_steps);
91 if (regenerate_noises_) {
92 noise_cond_.notify_all();
101 std::unique_lock<std::mutex> guard(noise_lock_);
102 noise_cond_.wait(guard, [
this]() {
return ready_;});
110 auto & s = settings_;
111 noises_vx_ = Eigen::ArrayXXf::NullaryExpr(
112 s.batch_size, s.time_steps, [&] () {return ndistribution_vx_(generator_);});
113 noises_wz_ = Eigen::ArrayXXf::NullaryExpr(
114 s.batch_size, s.time_steps, [&] () {return ndistribution_wz_(generator_);});
116 noises_vy_ = Eigen::ArrayXXf::NullaryExpr(
117 s.batch_size, s.time_steps, [&] () {return ndistribution_vy_(generator_);});
void reset(mppi::models::OptimizerSettings &settings, bool is_holonomic)
Reset noise generator with settings and model types.
void initialize(mppi::models::OptimizerSettings &settings, bool is_holonomic, const std::string &name, ParametersHandler *param_handler)
Initialize noise generator with settings and model types.
void generateNoisedControls()
Generate random controls by gaussian noise with mean in control_sequence_.
void noiseThread()
Thread to execute noise generation process.
void setNoisedControls(models::State &state, const models::ControlSequence &control_sequence)
set noised control_sequence to state controls
void shutdown()
Shutdown noise generator thread.
void generateNextNoises()
Signal to the noise thread the controller is ready to generate a new noised control for the next iter...
Handles getting parameters and dynamic parameter changes.
auto getParamGetter(const std::string &ns)
Get an object to retrieve parameters.
A control sequence over time (e.g. trajectory)
Settings for the optimizer to use.
State information: velocities, controls, poses, speed.