Skip to content

girimugundankumar/pole-placement-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pole Placement C++ Wrapper

BSD License

📚 Overview

This package is a C++ wrapper that provides an interface for performing pole placement using the scipy.place function from Python's SciPy library. The main purpose is to leverage the Python-based control system functionality from C++ code, as there aren't any open-source, easily available libraries for pole placement written natively in C++.

Pole placement is widely used for designing controllers, and this code was written for integration into the flightstack architecture at the Advanced Control Systems Lab (ACSL) for testing on UAVs:

🛠️ Dependencies

To successfully build and use this package, ensure the following dependencies are installed:

1. Python

Make sure Python is installed. Even if it's installed, run the following commands to ensure the required packages are available:

# Install Python3 development headers
sudo apt install python3-dev

# Install numpy and scipy
sudo pip3 install numpy scipy

# Upgrade them to the latest version
sudo pip3 install --upgrade scipy numpy

2. Boost.Python

Boost.Python (Boost) is required to provide a Python API from C++.

Installing Boost.Python from Source

Run the following commands (Linux instructions):

# Go to home directory
cd ~

# Clone Boost version 1.86
git clone https://github.com/boostorg/boost/tree/boost-1.86.0

# cd into boost root folder
cd ~/boost

# Compile Boost with Python
./bootstrap.sh --with-python

# Install Boost
sudo ./b2 --with-python
sudo ./b2 install

# Link Boost
sudo ldconfig

# Verify if Boost.Python is installed
ldconfig -p | grep boost_python

💻 How to Use the Repository

1. Clone the repository

# Clone wherever you need -- the recursive clones Eigen 3.40 too.
# If you already have Eigen in your codebase you can remove the tag to clone recursively 
# and modify the CMakeLists.txt to add the correct location of Eigen
git clone --recursive https://github.com/girimugundankumar/pole-placement-wrapper.git

# cd into the package
cd pole-placement-wrapper

# Create build directory and cd into it
mkdir build && cd build

# Run cmake
cmake ..

# Compile
make

2. Run the example file

# Run the example executable from the build directory
./pole_placement_example

Example Output

When you run the example file, the output should be:

===== For Complex Poles ===== 
Gain Matrix: 
15.6   -0   -0
  -0 17.8   -1
  -0    1 23.8
Placed Poles: 
 (-24,0)
(-25,-1)
 (-25,1)

===== For Real Poles =====

Gain Matrix: 
 0.200714 -0.966658  0.240661 -0.102798
 0.505873  0.577791  0.517958 -0.419914
Placed Poles: 
(-8.6659,0)
(-5.0566,0)
   (-0.5,0)
   (-0.2,0)

If you see this output, the code works correctly.

📄 CMake Integration

The CMakeLists.txt file includes all the necessary library dependencies, so you can easily integrate this package into your project.

🔗 Integration

If you plan on integrating the code into your existing codebase, in your C++ code, you will need to append the directory containing the Python module to sys.path. Modify the following code snippet in pole_placement.hpp to ensure the correct path to your Python module:

// Append the directory containing the Python module to sys.path
p::object sys = p::import("sys");
sys.attr("path").attr("append")("../include/pole_placement/");

Important: You may need to change the "../include/pole_placement/" path to reflect the correct location of the Python module based on your project's directory structure. The path provided must be the relative path from the directory where the executable is located. For this example, the path is given relative to the build directory where the executable is located.

📝 License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

🤝 Contributing

Contributions are welcome! If you’d like to improve this package, feel free to submit a pull request or open an issue.

About

C++ wrapper for scipy place function for pole placement

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors