Nav2 Navigation Stack - humble  humble
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 #include <xtensor/xtensor.hpp>
25 #include <xtensor/xview.hpp>
26 
27 #include "nav2_mppi_controller/models/optimizer_settings.hpp"
28 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
29 #include "nav2_mppi_controller/models/control_sequence.hpp"
30 #include "nav2_mppi_controller/models/state.hpp"
31 
32 namespace mppi
33 {
34 
40 {
41 public:
45  NoiseGenerator() = default;
46 
54  void initialize(
56  bool is_holonomic, const std::string & name, ParametersHandler * param_handler);
57 
61  void shutdown();
62 
67  void generateNextNoises();
68 
73  void setNoisedControls(models::State & state, const models::ControlSequence & control_sequence);
74 
80  void reset(mppi::models::OptimizerSettings & settings, bool is_holonomic);
81 
82 protected:
86  void noiseThread();
87 
96 
97  xt::xtensor<float, 2> noises_vx_;
98  xt::xtensor<float, 2> noises_vy_;
99  xt::xtensor<float, 2> noises_wz_;
100 
102  bool is_holonomic_;
103 
104  std::thread noise_thread_;
105  std::condition_variable noise_cond_;
106  std::mutex noise_lock_;
107  bool active_{false}, ready_{false}, regenerate_noises_{false};
108 };
109 
110 } // namespace mppi
111 
112 #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:31