EasyNav Plugins
Loading...
Searching...
No Matches
MPPIOptimizer.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// This file is part of the project Easy Navigation (EasyNav in short)
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16// #pragma once
17#ifndef EASYNAV_MPPI_CONTROLLER__MPPIOPTIMIZER_HPP_
18#define EASYNAV_MPPI_CONTROLLER__MPPIOPTIMIZER_HPP_
19
20#include <utility>
21#include <vector>
22#include <random>
23
24#include "geometry_msgs/msg/pose.hpp"
25#include "nav_msgs/msg/path.hpp"
26#include "pcl/point_cloud.h"
27#include "pcl/point_types.h"
28
29namespace easynav
30{
31
34{
35 double v;
36 double w;
37 std::vector<std::vector<std::pair<double, double>>> all_trajectories;
38 std::vector<std::pair<double, double>> best_trajectory;
39};
40
42{
43 double v;
44 double w;
45 double cost;
46};
47
49{
50public:
63 double num_samples, double horizon_steps, double dt, double lambda,
64 double max_lin_vel = 1.0, double max_ang_vel = 1.0, double max_lin_acc = 1.0,
65 double max_ang_acc = 1.0, double fov = M_PI / 2.0, double safety_radius = 0.6);
66
73 const geometry_msgs::msg::Pose & current_pose,
74 const nav_msgs::msg::Path & path,
75 const pcl::PointCloud<pcl::PointXYZ> & points);
76
77private:
78 double num_samples_;
79 double horizon_steps_;
80 double dt_;
81 double lambda_;
82 double max_lin_vel_;
83 double max_ang_vel_;
84 double max_lin_acc_;
85 double max_ang_acc_;
86 double fov_;
87 double safety_radius_;
88 double last_v_ = 0.0;
89 double last_w_ = 0.0;
90
91 std::default_random_engine rng_;
92 std::normal_distribution<double> normal_ = std::normal_distribution<double>(0.0, 0.5);
93 std::normal_distribution<double> v_noise_ = std::normal_distribution<double>(0.0, 0.05);
94 std::normal_distribution<double> w_noise_ = std::normal_distribution<double>(0.0, 0.02);
95
104 double compute_cost(
105 const std::vector<std::pair<double, double>> & trajectory,
106 const nav_msgs::msg::Path & path,
107 double v, double w, double initial_yaw,
108 const pcl::PointCloud<pcl::PointXYZ> & points);
109
119 std::vector<std::pair<double, double>> simulate_trajectory(
120 double x, double y, double yaw,
121 double v, double w, const nav_msgs::msg::Path & path, int steps);
122
130 double heading_error(
131 double robot_yaw,
132 double target_x, double target_y,
133 double robot_x, double robot_y);
134
139 double shortest_angular_distance(double from, double to);
140
141};
142
143} // namespace easynav
144
145#endif // EASYNAV_MPPI_CONTROLLER__MPPIOPTIMIZER_HPP_
MPPIResult compute_control(const geometry_msgs::msg::Pose &current_pose, const nav_msgs::msg::Path &path, const pcl::PointCloud< pcl::PointXYZ > &points)
Computes the control commands using MPPI optimization.
Definition MPPIOptimizer.cpp:175
MPPIOptimizer(double num_samples, double horizon_steps, double dt, double lambda, double max_lin_vel=1.0, double max_ang_vel=1.0, double max_lin_acc=1.0, double max_ang_acc=1.0, double fov=M_PI/2.0, double safety_radius=0.6)
Constructor for MPPIOptimizer.
Definition MPPIOptimizer.cpp:12
Provides a mapping for often used cost values.
Definition cost_values.hpp:41
Result structure for MPPI optimization containing control commands and trajectories.
Definition MPPIOptimizer.hpp:34
std::vector< std::pair< double, double > > best_trajectory
Best trajectory found during optimization.
Definition MPPIOptimizer.hpp:38
double v
Linear velocity command.
Definition MPPIOptimizer.hpp:35
std::vector< std::vector< std::pair< double, double > > > all_trajectories
All sampled trajectories.
Definition MPPIOptimizer.hpp:37
double w
Angular velocity command.
Definition MPPIOptimizer.hpp:36
Definition MPPIOptimizer.hpp:42
double v
Linear velocity for this sample.
Definition MPPIOptimizer.hpp:43
double cost
Cost associated with this trajectory sample.
Definition MPPIOptimizer.hpp:45
double w
Angular velocity for this sample.
Definition MPPIOptimizer.hpp:44