15 #ifndef NAV2_MPPI_CONTROLLER__OPTIMIZER_HPP_
16 #define NAV2_MPPI_CONTROLLER__OPTIMIZER_HPP_
18 #include <Eigen/Dense>
23 #include "rclcpp_lifecycle/lifecycle_node.hpp"
25 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
26 #include "nav2_core/goal_checker.hpp"
27 #include "nav2_core/controller_exceptions.hpp"
29 #include "geometry_msgs/msg/twist.hpp"
30 #include "geometry_msgs/msg/pose_stamped.hpp"
31 #include "geometry_msgs/msg/twist_stamped.hpp"
32 #include "nav_msgs/msg/path.hpp"
34 #include "nav2_mppi_controller/models/optimizer_settings.hpp"
35 #include "nav2_mppi_controller/motion_models.hpp"
36 #include "nav2_mppi_controller/critic_manager.hpp"
37 #include "nav2_mppi_controller/models/state.hpp"
38 #include "nav2_mppi_controller/models/trajectories.hpp"
39 #include "nav2_mppi_controller/models/path.hpp"
40 #include "nav2_mppi_controller/tools/noise_generator.hpp"
41 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
42 #include "nav2_mppi_controller/tools/utils.hpp"
73 rclcpp_lifecycle::LifecycleNode::WeakPtr parent,
const std::string & name,
74 std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros,
92 const geometry_msgs::msg::PoseStamped & robot_pose,
93 const geometry_msgs::msg::Twist & robot_speed,
const nav_msgs::msg::Path & plan,
125 void reset(
bool reset_dynamic_speed_limits =
true);
150 const geometry_msgs::msg::PoseStamped & robot_pose,
151 const geometry_msgs::msg::Twist & robot_speed,
152 const nav_msgs::msg::Path & plan,
217 Eigen::Array<float, Eigen::Dynamic, 3> & trajectories,
218 const Eigen::ArrayXXf & state)
const;
231 geometry_msgs::msg::TwistStamped
244 void setOffset(
double controller_frequency);
253 rclcpp_lifecycle::LifecycleNode::WeakPtr parent_;
254 std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
258 std::shared_ptr<MotionModel> motion_model_;
268 std::array<mppi::models::Control, 4> control_history_;
271 geometry_msgs::msg::Pose goal_;
272 Eigen::ArrayXf costs_;
275 state_, generated_trajectories_, path_, goal_,
276 costs_, settings_.model_dt,
false,
nullptr,
nullptr,
277 std::nullopt, std::nullopt};
279 rclcpp::Logger
logger_{rclcpp::get_logger(
"MPPIController")};
Manager of objective function plugins for scoring trajectories.
Generates noise trajectories from optimal trajectory.
Main algorithm optimizer of the MPPI Controller.
geometry_msgs::msg::TwistStamped evalControl(const geometry_msgs::msg::PoseStamped &robot_pose, const geometry_msgs::msg::Twist &robot_speed, const nav_msgs::msg::Path &plan, const geometry_msgs::msg::Pose &goal, nav2_core::GoalChecker *goal_checker)
Compute control using MPPI algorithm.
void updateStateVelocities(models::State &state) const
Update velocities in state.
const models::ControlSequence & getOptimalControlSequence()
Get the optimal control sequence for a cycle for visualization.
void setMotionModel(const std::string &model)
Set the motion model of the vehicle platform.
void setOffset(double controller_frequency)
Using control frequencies and time step size, determine if trajectory offset should be used to popula...
Eigen::ArrayXXf getOptimizedTrajectory()
Get the optimal trajectory for a cycle for visualization.
void reset(bool reset_dynamic_speed_limits=true)
Reset the optimization problem to initial conditions.
rclcpp::Logger logger_
Caution, keep references.
void prepare(const geometry_msgs::msg::PoseStamped &robot_pose, const geometry_msgs::msg::Twist &robot_speed, const nav_msgs::msg::Path &plan, const geometry_msgs::msg::Pose &goal, nav2_core::GoalChecker *goal_checker)
Prepare state information on new request for trajectory rollouts.
void integrateStateVelocities(models::Trajectories &trajectories, const models::State &state) const
Rollout velocities in state to poses.
const models::OptimizerSettings & getSettings() const
Get the motion model time step.
~Optimizer()
Destructor for mppi::Optimizer.
void updateControlSequence()
Update control sequence with state controls weighted by costs using softmax function.
void generateNoisedTrajectories()
updates generated trajectories with noised trajectories from the last cycle's optimal control
bool fallback(bool fail)
Perform fallback behavior to try to recover from a set of trajectories in collision.
bool isHolonomic() const
Whether the motion model is holonomic.
models::Trajectories & getGeneratedTrajectories()
Get the trajectories generated in a cycle for visualization.
void updateInitialStateVelocities(models::State &state) const
Update initial velocity in state.
void shutdown()
Shutdown for optimizer at process end.
void optimize()
Main function to generate, score, and return trajectories.
Optimizer()=default
Constructor for mppi::Optimizer.
void setSpeedLimit(double speed_limit, bool percentage)
Set the maximum speed based on the speed limits callback.
void shiftControlSequence()
Shift the optimal control sequence after processing for next iterations initial conditions after exec...
void applyControlSequenceConstraints()
Apply hard vehicle constraints on control sequence.
void getParams()
Obtain the main controller's parameters.
void propagateStateVelocitiesFromInitials(models::State &state) const
predict velocities in state using model for time horizon equal to timesteps
void initialize(rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string &name, std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros, ParametersHandler *dynamic_parameters_handler)
Initializes optimizer on startup.
geometry_msgs::msg::TwistStamped getControlFromSequenceAsTwist(const builtin_interfaces::msg::Time &stamp)
Convert control sequence to a twist command.
Handles getting parameters and dynamic parameter changes.
Function-object for checking whether a goal has been reached.
A 2D costmap provides a mapping between points in the world and their associated "costs".
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...
A control sequence over time (e.g. trajectory)
Settings for the optimizer to use.
Path represented as a tensor.
State information: velocities, controls, poses, speed.