15 #include "nav2_mppi_controller/tools/noise_generator.hpp"
19 #include <xtensor/xmath.hpp>
20 #include <xtensor/xrandom.hpp>
21 #include <xtensor/xnoalias.hpp>
31 is_holonomic_ = is_holonomic;
35 getParam(regenerate_noises_,
"regenerate_noises",
false);
37 if (regenerate_noises_) {
48 noise_cond_.notify_all();
49 if (noise_thread_.joinable()) {
59 std::unique_lock<std::mutex> guard(noise_lock_);
62 noise_cond_.notify_all();
69 std::unique_lock<std::mutex> guard(noise_lock_);
71 xt::noalias(state.cvx) = control_sequence.vx + noises_vx_;
72 xt::noalias(state.cvy) = control_sequence.vy + noises_vy_;
73 xt::noalias(state.cwz) = control_sequence.wz + noises_wz_;
79 is_holonomic_ = is_holonomic;
83 std::unique_lock<std::mutex> guard(noise_lock_);
84 xt::noalias(noises_vx_) = xt::zeros<float>({settings_.batch_size, settings_.time_steps});
85 xt::noalias(noises_vy_) = xt::zeros<float>({settings_.batch_size, settings_.time_steps});
86 xt::noalias(noises_wz_) = xt::zeros<float>({settings_.batch_size, settings_.time_steps});
90 if (regenerate_noises_) {
91 noise_cond_.notify_all();
100 std::unique_lock<std::mutex> guard(noise_lock_);
101 noise_cond_.wait(guard, [
this]() {
return ready_;});
109 auto & s = settings_;
111 xt::noalias(noises_vx_) = xt::random::randn<float>(
112 {s.batch_size, s.time_steps}, 0.0f,
114 xt::noalias(noises_wz_) = xt::random::randn<float>(
115 {s.batch_size, s.time_steps}, 0.0f,
118 xt::noalias(noises_vy_) = xt::random::randn<float>(
119 {s.batch_size, s.time_steps}, 0.0f,
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 parmaeter changes.
auto getParamGetter(const std::string &ns)
Get an object to retreive parameters.
A control sequence over time (e.g. trajectory)
Settings for the optimizer to use.
State information: velocities, controls, poses, speed.