forked from ai-winter/ros_motion_planning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
680 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project(mpc_planner) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
angles | ||
costmap_2d | ||
geometry_msgs | ||
nav_core | ||
nav_msgs | ||
navfn | ||
pluginlib | ||
roscpp | ||
tf2_geometry_msgs | ||
tf2_ros | ||
base_local_planner | ||
local_planner | ||
) | ||
|
||
find_package(OsqpEigen REQUIRED) | ||
find_package(Eigen3 REQUIRED) | ||
|
||
catkin_package( | ||
INCLUDE_DIRS include | ||
CATKIN_DEPENDS local_planner | ||
) | ||
|
||
include_directories( | ||
include | ||
${catkin_INCLUDE_DIRS} | ||
) | ||
|
||
add_library(${PROJECT_NAME} | ||
src/mpc_planner.cpp | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
${catkin_LIBRARIES} | ||
OsqpEigen | ||
) |
112 changes: 112 additions & 0 deletions
112
src/core/local_planner/mpc_planner/include/mpc_planner.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* ********************************************************* | ||
* | ||
* @file: mpc_planner.h | ||
* @brief: Contains the model predicted control (MPC) local planner class | ||
* @author: Yang Haodong | ||
* @date: 2024-01-31 | ||
* @version: 1.0 | ||
* | ||
* Copyright (c) 2024, Yang Haodong. | ||
* All rights reserved. | ||
* | ||
* -------------------------------------------------------- | ||
* | ||
* ******************************************************** | ||
*/ | ||
#ifndef MPC_PLANNER_H | ||
#define MPC_PLANNER_H | ||
|
||
#include <geometry_msgs/PointStamped.h> | ||
#include <tf2/utils.h> | ||
|
||
#include "local_planner.h" | ||
|
||
namespace mpc_planner | ||
{ | ||
/** | ||
* @brief A class implementing a local planner using the MPC | ||
*/ | ||
class MPCPlanner : public nav_core::BaseLocalPlanner, local_planner::LocalPlanner | ||
{ | ||
public: | ||
/** | ||
* @brief Construct a new MPC planner object | ||
*/ | ||
MPCPlanner(); | ||
|
||
/** | ||
* @brief Construct a new MPC planner object | ||
*/ | ||
MPCPlanner(std::string name, tf2_ros::Buffer* tf, costmap_2d::Costmap2DROS* costmap_ros); | ||
|
||
/** | ||
* @brief Destroy the MPC planner object | ||
*/ | ||
~MPCPlanner(); | ||
|
||
/** | ||
* @brief Initialization of the local planner | ||
* @param name the name to give this instance of the trajectory planner | ||
* @param tf a pointer to a transform listener | ||
* @param costmap_ros the cost map to use for assigning costs to trajectories | ||
*/ | ||
void initialize(std::string name, tf2_ros::Buffer* tf, costmap_2d::Costmap2DROS* costmap_ros); | ||
|
||
/** | ||
* @brief Set the plan that the controller is following | ||
* @param orig_global_plan the plan to pass to the controller | ||
* @return true if the plan was updated successfully, else false | ||
*/ | ||
bool setPlan(const std::vector<geometry_msgs::PoseStamped>& orig_global_plan); | ||
|
||
/** | ||
* @brief Check if the goal pose has been achieved | ||
* @return true if achieved, false otherwise | ||
*/ | ||
bool isGoalReached(); | ||
|
||
/** | ||
* @brief Given the current position, orientation, and velocity of the robot, compute the velocity commands | ||
* @param cmd_vel will be filled with the velocity command to be passed to the robot base | ||
* @return true if a valid trajectory was found, else false | ||
*/ | ||
bool computeVelocityCommands(geometry_msgs::Twist& cmd_vel); | ||
|
||
private: | ||
/** | ||
* @brief Execute MPC control process | ||
* @param s current state | ||
* @param s_d desired state | ||
* @param u_r refered control | ||
* @param du_p previous control error | ||
* @return u control vector | ||
*/ | ||
Eigen::Vector2d _mpcControl(Eigen::Vector3d s, Eigen::Vector3d s_d, Eigen::Vector2d u_r, Eigen::Vector2d du_p); | ||
/** | ||
* @brief convert matrix A to its sparse view | ||
* @param A dense matrix | ||
* @return A_s sparse matrix | ||
*/ | ||
Eigen::SparseMatrix<double> _convertToSparseMatrix(Eigen::MatrixXd A); | ||
|
||
private: | ||
bool initialized_; // initialized flag | ||
bool goal_reached_; // goal reached flag | ||
tf2_ros::Buffer* tf_; // transform buffer | ||
|
||
double d_t_; // control time interval | ||
Eigen::Matrix3d Q_; // state error matrix | ||
Eigen::Matrix2d R_; // control error matrix | ||
int p_; // predicting time domain | ||
int m_; // control time domain | ||
Eigen::Vector2d du_p_; // previous control error | ||
|
||
ros::Publisher target_pt_pub_, current_pose_pub_; | ||
|
||
// goal parameters | ||
double goal_x_, goal_y_; | ||
Eigen::Vector3d goal_rpy_; | ||
}; | ||
} // namespace mpc_planner | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<library path="lib/libmpc_planner"> | ||
<class name="mpc_planner/MPCPlanner" type="mpc_planner::MPCPlanner" | ||
base_class_type="nav_core::BaseLocalPlanner"> | ||
<description> | ||
A implementation of a local model predicted control (MPC) planner. | ||
</description> | ||
</class> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>mpc_planner</name> | ||
<version>0.0.0</version> | ||
<description>The mpc_planner package</description> | ||
<maintainer email="[email protected]">winter</maintainer> | ||
<license>GPL3</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<depend>angles</depend> | ||
<depend>costmap_2d</depend> | ||
<depend>geometry_msgs</depend> | ||
<depend>nav_core</depend> | ||
<depend>nav_msgs</depend> | ||
<depend>navfn</depend> | ||
<depend>pluginlib</depend> | ||
<depend>roscpp</depend> | ||
<depend>tf2_geometry_msgs</depend> | ||
<depend>tf2_ros</depend> | ||
<depend>local_planner</depend> | ||
|
||
|
||
<export> | ||
<nav_core plugin="${prefix}/mpc_planner_plugin.xml" /> | ||
|
||
</export> | ||
</package> |
Oops, something went wrong.