Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
noise_generator.hpp
1 // Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_MPPI_CONTROLLER__TOOLS__NOISE_GENERATOR_HPP_
16 #define NAV2_MPPI_CONTROLLER__TOOLS__NOISE_GENERATOR_HPP_
17 
18 #include <string>
19 #include <memory>
20 #include <thread>
21 #include <mutex>
22 #include <condition_variable>
23 
24 // xtensor creates warnings that needs to be ignored as we are building with -Werror
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Warray-bounds"
27 #pragma GCC diagnostic ignored "-Wstringop-overflow"
28 #include <xtensor/xtensor.hpp>
29 #include <xtensor/xview.hpp>
30 #pragma GCC diagnostic pop
31 
32 #include "nav2_mppi_controller/models/optimizer_settings.hpp"
33 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
34 #include "nav2_mppi_controller/models/control_sequence.hpp"
35 #include "nav2_mppi_controller/models/state.hpp"
36 
37 namespace mppi
38 {
39 
45 {
46 public:
50  NoiseGenerator() = default;
51 
59  void initialize(
61  bool is_holonomic, const std::string & name, ParametersHandler * param_handler);
62 
66  void shutdown();
67 
72  void generateNextNoises();
73 
78  void setNoisedControls(models::State & state, const models::ControlSequence & control_sequence);
79 
85  void reset(mppi::models::OptimizerSettings & settings, bool is_holonomic);
86 
87 protected:
91  void noiseThread();
92 
100  void generateNoisedControls();
101 
102  xt::xtensor<float, 2> noises_vx_;
103  xt::xtensor<float, 2> noises_vy_;
104  xt::xtensor<float, 2> noises_wz_;
105 
107  bool is_holonomic_;
108 
109  std::thread noise_thread_;
110  std::condition_variable noise_cond_;
111  std::mutex noise_lock_;
112  bool active_{false}, ready_{false}, regenerate_noises_{false};
113 };
114 
115 } // namespace mppi
116 
117 #endif // NAV2_MPPI_CONTROLLER__TOOLS__NOISE_GENERATOR_HPP_
Generates noise trajectories from optimal trajectory.
NoiseGenerator()=default
Constructor for mppi::NoiseGenerator.
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.
A control sequence over time (e.g. trajectory)
Settings for the optimizer to use.
State information: velocities, controls, poses, speed.
Definition: state.hpp:36