Giter VIP home page Giter VIP logo

mpc_local_planner's Introduction

MPC local planner

A nonlinear MPC used to control an autonomous car.

📖 Table of Contents

📔 Description

This repository contains an implementation of a control system used for an autonomous car. The control system is utilizes nonlinear MPCs (NMPC) for controlling the car. The control system was originally made for the Norwegian student organization at NTNU, Fuel Fighter. Acados is used to get access to fast solvers tailored for NMPC. Acados python interface is then used to generate C code that we use in our C++ program. The control system is designed to follow a reference path/trajectory. The path is given as a nav_msgs::Path message. This contains a vector with points defining the path. To make the car follow the path we firstly interpolate a third order polynomial to fit a small section of the track in front of the car. Then we input this into the solver. The mpc is designed so that the car wants to stay on the track and keep a constant speed. There are several parameters that can be tuned so that the mpc works optimally. See parameter section


Demo of MPC using gazebo simulator and audibot car

ROS interface

The mpc is made for ROS2 Humble. All of the inputs to the mpc and outputs are therefore sent using topics and transforms. The MPC needs to know the state of the car and where the track or goal is. Transforms are used to figure out where the car is. The code looks up the latest transform from a map frame to a car frame. How fast we are going is sent to us as a Twist message on a given topic. It can also take in a topic where the actual steering angle of the car is published. However, it is also possible to assume that the steering angle is equal to the previous steering command. This can be done by setting use_actual_steering_topic=False in the param file. Lastly the MPC needs to know where we want the car to drive. This is sent over the path topic as a path message.

The output of the MPC is a steering angle and throttle value. These values are published on two separate topics: /steering_cmd and /throttle_cmd. In addition to the commands sent to the car several path messages are also published. /global_path is the reference track. This is where we want the car to drive. This is the green line seen in the gif. /local_path is where the mpc is planning to drive. This is shown in red. Lastly we have /interpolated_path. This is a interpolation of the /global_path using a third order polynomial. The names of most of the frames and topics can be found and changed in the file /params/mpc.yaml


ROS interface for MPC

🛠️ Install

The MPC requires several things to work. Mainly it is the library Acados and of course ROS.

  1. ROS ROS is used to send and receive data. It can be installed by following this tutorial. If you already have ROS installed you can skip this. ROS noetic is used, however other versions may also work.

  2. Clone

Clone this repository into the src folder in a workspace. Example:

cd ~/ros2_ws/src
git clone https://gitlab.stud.idi.ntnu.no/fuelfighter/autonomous/planning-control/mpc_local_planner.git
  1. Acados

The recommended way to instal acados is to use the install script install_acados.sh. First we need to install some dependencies. Run the following:

sudo apt install python3-virtualenv python3-pip

Then we can use the script. It requires the path to where you want to install acados. It can be used as follows:

bash install_acados.sh /path/to/install/location

The installation was successful if a graph pops up showing the solution by an example mpc.

You can also install it manually by doing the following steps. Firstly follow this guide to download and build the acados library. Choose the Cmake alternative. Once that is done we need to set it up with the python interface. I recommend using a virtual environment for this (as do they). To make compiling this code easier make sure to create the virtual environment in <acados_root>/build/. If you do not do this the code will not compile. You will have to change CmakeLists.txt. Follow the steps in this guide. Remember to add the lines from step four into .bashrc

  1. MPC

Now we are ready to build the mpc.

colcon build

You can also build only the mpc by adding mpc_local_planner to the command:

colcon build --packages-select mpc_local_planner

🚀 Usage

Parameters

Once everything is installed and built we are ready to define the parameters for the mpc. This is done using rosparam. The parameters are defined in a .yaml file in the folder config. These parameters need to be correct for your vehicle so that the mpc will work optimally. If some critical parameters are not defined the code will not run. It will throw an error telling you what parameter it is missing. Other noncritical parameters cause warnings and some do not even do that. Therefore make sure your parameters are correct. The way the build system works makes it so that you need to recompile every time you update any of the parameters. Otherwise the changes will have no effect.

Run

Finally we are ready to run the code. This is done by using launch files. The main launch file is mpc.launch.py. You can run this file in the following way.

source install/setup.bash
ros2 launch mpc_local_planner mpc.launch.py

It is also possible to only start rviz be using rviz.launch. The syntax is the same as for mpc.launch.

ros2 launch mpc_local_planner rviz.launch.py

🔗 References

mpc_local_planner's People

Contributors

torborve avatar erikfagerli avatar andreas-utkilen avatar

Stargazers

HUANG ANDONG avatar maky avatar xzh avatar BinHong Liu avatar gh_shen avatar  avatar Khoa Nguyen avatar Liangjun XING avatar Zheyu avatar  avatar  avatar Hamza Abdinassir Hassan avatar  avatar  avatar  avatar  avatar Zhu Xiaolong avatar LucianZhong avatar NeXT avatar westsky avatar  avatar Muhammad avatar Anastasia avatar Weiming Liao avatar BRNKR avatar  avatar Manasvi Saxena avatar  avatar Jianwei peng avatar bigFlight avatar coffee avatar  avatar DeepDuke avatar zhouzuhong avatar

Watchers

zhouzuhong avatar coffee avatar  avatar

mpc_local_planner's Issues

Compile failed :(

Hello and thanks of this great work! Actually I am working with Acados and ROS so I can learn a lot from your project. Unfortauntly I couldn't build the project. It gives me the following error.

[ 11%] �[34m�[1mGenerating /home/muhammad/mpc_ws/src/mpc_local_planner/build/point_stab/c_generated_code/main_point_stab.c�[0m
[ 11%] �[34m�[1mGenerating /home/muhammad/mpc_ws/src/mpc_local_planner/build/path_tracking/c_generated_code/main_path_tracking.c�[0m
/bin/sh: 1: /build/env/bin/python3: not found
/bin/sh: 1: /build/env/bin/python3: not found
CMakeFiles/point_stab_lib.dir/build.make:75: recipe for target '/home/muhammad/mpc_ws/src/mpc_local_planner/build/point_stab/c_generated_code/main_point_stab.c' failed
make[2]: *** [/home/muhammad/mpc_ws/src/mpc_local_planner/build/point_stab/c_generated_code/main_point_stab.c] Error 127
make[2]: *** [/home/muhammad/mpc_ws/src/mpc_local_planner/build/path_tracking/c_generated_code/main_path_tracking.c] Error 127
CMakeFiles/path_tracking_lib.dir/build.make:75: recipe for target '/home/muhammad/mpc_ws/src/mpc_local_planner/build/path_tracking/c_generated_code/main_path_tracking.c' failed
CMakeFiles/Makefile2:1402: recipe for target 'CMakeFiles/point_stab_lib.dir/all' failed
CMakeFiles/Makefile2:1376: recipe for target 'CMakeFiles/path_tracking_lib.dir/all' failed
make[1]: *** [CMakeFiles/point_stab_lib.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/path_tracking_lib.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2 

Could you tell me what is the wrong please? thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.