Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implementation of a pid dp controller #499

Open
wants to merge 79 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
3260506
feat: adding in the setup for dp controller, dosent build, need to fix
Talhanc Sep 27, 2024
a3da7f6
feat: adding in pid parts
Talhanc Oct 11, 2024
0705602
Develop (#481)
kluge7 Oct 11, 2024
b218088
self.reference_mode erstattes med States.REFERENCE_MODE
malenef Oct 13, 2024
3180183
Some formatting
Andeshog Oct 13, 2024
821c846
feat: add pid gains
Talhanc Oct 13, 2024
cb24307
refactor: move controller to control
Andeshog Oct 13, 2024
6c93dfe
refactor: change function name from J to create_J to avoid conflict w…
Andeshog Oct 13, 2024
2e66778
Vinklene restarter seg ikke til null når du slipper opp kontrolleren
malenef Oct 18, 2024
76249d7
feat: added a new main.cpp file with ros2 node class
Talhanc Oct 18, 2024
5de507d
feat: add pid controller for dp
Andeshog Oct 18, 2024
5ca0457
feat: add possiblity to tune the PID during runtime by publishing Flo…
Andeshog Oct 18, 2024
7f16b07
feat: add config file for parameters
Andeshog Oct 19, 2024
f21369f
remove unnecessary typedef
Andeshog Oct 19, 2024
ff279e0
refactor: move eta, eta_d and nu over to ros node
Andeshog Oct 19, 2024
ee91ca5
feat: add launch file
Andeshog Oct 19, 2024
59b362c
feat: add eta_dot_d as reference state
Andeshog Oct 19, 2024
7a71543
build fix
Andeshog Oct 19, 2024
23c313e
feat: add reference filter
Andeshog Oct 19, 2024
4dcf9f6
added zeta and omega as ros params
jorgenfj Oct 19, 2024
3c56eea
feat: initialized action server
Andeshog Oct 20, 2024
d13fca8
feat: action server for reference filter
Andeshog Oct 20, 2024
18ded87
feat: add odom subscriber for reference filter
Andeshog Oct 20, 2024
0063806
Add parameter file
malenef Oct 20, 2024
c486401
Add ssa
malenef Oct 20, 2024
bbbe77e
Add better formating and cleaner code
malenef Oct 20, 2024
30c3bd8
Add documentation
malenef Oct 20, 2024
5327a63
feat: adding joystick input
Talhanc Oct 20, 2024
c5dea38
Add documentation and remove spamming in terminal
malenef Oct 20, 2024
c46ba1e
fix: some issues with pid_controller_ros.hpp file
Talhanc Oct 20, 2024
5ffb4a2
Merge branch '434-task-dp-controller' into 432-task-expand-joystick-i…
Talhanc Oct 20, 2024
487830d
Merge pull request #490 from vortexntnu/432-task-expand-joystick-inte…
Talhanc Oct 20, 2024
79fc2aa
feat: add multithreaded executor
Andeshog Oct 20, 2024
af96056
Merge branch '434-task-dp-controller' of github.com:vortexntnu/vortex…
Andeshog Oct 20, 2024
7406b3a
feat: make new goals overwrite the old goal
Andeshog Oct 22, 2024
06662e1
feat: add rotation of velocity from body to NED
Andeshog Oct 22, 2024
a442e88
feat: tuning reference filter
Andeshog Oct 22, 2024
28e4e71
fix: fix conversions between quat and euler using tf2
Andeshog Oct 22, 2024
cfa688b
refactor: use tf2 for conversion between euler and quat
Andeshog Oct 22, 2024
8d0d38b
feat: init tuning process
Andeshog Oct 22, 2024
121c638
feat: added anti windup
Talhanc Oct 23, 2024
c1df6f9
fix: variable issue in controller input
Talhanc Oct 23, 2024
3a2076f
refactor: Update include order in pid_controller_utils.hpp
Talhanc Oct 23, 2024
5f46ee1
feat: added in quaternions instead of euler
Talhanc Oct 24, 2024
9a69032
feat: added quaternion normalization to fix error
Talhanc Oct 31, 2024
188efa2
fix: changed pid params
Talhanc Nov 1, 2024
ed2115e
refactor(dp_controller): removed previous version
Talhanc Nov 8, 2024
ad55492
docs: added documentation
Talhanc Nov 8, 2024
614bc3e
docs: added documentation
Talhanc Nov 8, 2024
b280119
Merge remote-tracking branch 'origin/develop' into 434-task-dp-contro…
Talhanc Nov 8, 2024
8ced2af
hey
Talhanc Nov 8, 2024
00a2424
hey
Talhanc Nov 8, 2024
d159315
refactor: applied formatting changes
Talhanc Nov 8, 2024
9ca02ca
refactor: did some changes asked by anders
Talhanc Nov 8, 2024
ddfd003
fix(pid_controller_utils): forgot ; in one line
Talhanc Nov 8, 2024
ca73be3
feat: add methods for filling vectors
Andeshog Nov 10, 2024
1c65a96
refactor: remove redundant code
Andeshog Nov 10, 2024
4a2d2e8
feat: add tf2_geometry_msgs dependency
Andeshog Nov 10, 2024
b2d8df1
fix: fix methods
Andeshog Nov 10, 2024
b6d17b8
refactor: make precommit hook happy
Andeshog Nov 10, 2024
99e859a
make pre-commit hook happy
Andeshog Nov 10, 2024
fbf26e8
fix: fix parameter names
Andeshog Nov 10, 2024
2a75ea4
feat: added struct elements for the quaternions and position
Talhanc Nov 10, 2024
cc0b3b6
Merge branch 'feat/dp_controller_euler' into 434-task-dp-controller
Andeshog Nov 18, 2024
69b4c3a
feat: add correct qos profile for odom sug
Andeshog Nov 18, 2024
0ac8b2e
fix: structure fix
Andeshog Nov 18, 2024
7717907
fix: make pre-commit guy habby
Andeshog Nov 18, 2024
ba23237
fix:something wrong
Talhanc Jan 7, 2025
87d0a4a
fix:something wrong
Talhanc Jan 7, 2025
ab7fd8b
fix: fixing the control input computation
Talhanc Jan 7, 2025
2e07a59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 7, 2025
222302b
fix: variabel error in guidance callback
Talhanc Jan 8, 2025
2868b8a
fix: some merge errors
Talhanc Jan 8, 2025
fde5507
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2025
6683733
feat: added topics into config file for the euler pid controller
Talhanc Jan 9, 2025
2031df1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2025
25c245a
fix: Adeed kill switch and remove the msgs error
Talhanc Jan 9, 2025
3499682
fix: change in reference filter parameter
Talhanc Jan 9, 2025
0cf0c30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: added documentation
  • Loading branch information
Talhanc committed Nov 8, 2024
commit 614bc3e13196afe320e918a802aa5e0cbae2d4ac
10 changes: 4 additions & 6 deletions control/pid_controller_dp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.8)
project(pid_controller_dp)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
Expand All @@ -10,7 +9,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(nav_msgs REQUIRED)
Expand All @@ -21,15 +19,15 @@ find_package(vortex_msgs REQUIRED)

include_directories(include)

add_executable(pid_controller_node
add_executable(pid_controller_node
src/pid_controller_node.cpp
src/pid_controller_ros.cpp
src/pid_controller.cpp
src/pid_controller_utils.cpp
)

ament_target_dependencies(pid_controller_node
rclcpp
ament_target_dependencies(pid_controller_node
rclcpp
geometry_msgs
nav_msgs
Eigen3
Expand All @@ -52,4 +50,4 @@ install(DIRECTORY
DESTINATION share/${PROJECT_NAME}/
)

ament_package()
ament_package()
4 changes: 0 additions & 4 deletions control/pid_controller_dp/config/pid_params.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
pid_controller_node:
ros__parameters:
# Kp: [100.0, 100.0, 100.0, 40.0, 40.0, 40.0]
# Ki: [5.0, 5.0, 5.0, 1.0, 1.0, 1.0]
# Kd: [28.0, 22.0, 28.0, 3.0, 3.0, 3.0]

Kp: [110.0, 110.0, 110.0, 15.0, 15.0, 15.0]
Ki: [2.0, 2.0, 2.0, 0.12, 0.12, 0.12]
Kd: [15.0, 15.0, 15.0, 6.0, 7.0, 6.0]
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include <eigen3/Eigen/Dense>

namespace Eigen {
typedef Eigen::Matrix<double, 6, 6> Matrix6d;
typedef Eigen::Matrix<double, 3, 3> Matrix3d;
typedef Eigen::Matrix<double, 6, 1> Vector6d;
typedef Eigen::Matrix<double, 7, 1> Vector7d;
typedef Eigen::Matrix<double, 4, 1> Vector4d;
typedef Eigen::Matrix<double, 6, 6> Matrix6d;
typedef Eigen::Matrix<double, 3, 3> Matrix3d;
typedef Eigen::Matrix<double, 4, 3> Matrix4x3d;
typedef Eigen::Matrix<double, 7, 6> Matrix7x6d;
typedef Eigen::Matrix<double, 6, 7> Matrix6x7d;
typedef Eigen::Matrix<double, 7,7> Matrix7d;
typedef Eigen::Matrix<double, 7, 7> Matrix7d;
} // namespace Eigen

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@ class PIDController {
public:
explicit PIDController();

// @brief Calculate the control input tau
// @param eta: 7D vector containing the vehicle pose [x, y, z, w, x, y, z]
// @param eta_d: 7D vector containing the desired vehicle pose [x, y, z, w, x, y, z]
// @param nu: 6D vector containing the vehicle velocity [u, v, w, p, q, r]
// @param eta_dot_d: 7D vector containing the desired vehicle velocity [u, v, w, p, q, r]
// @return 6D vector containing the control input tau [u, v, w, p, q, r]
Eigen::Vector6d calculate_tau(const Eigen::Vector7d &eta, const Eigen::Vector7d &eta_d, const Eigen::Vector6d &nu, const Eigen::Vector7d &eta_dot_d);

// @brief Set the proportional gain matrix
// @param Kp: 6x6 matrix containing the proportional gain matrix
void setKp(const Eigen::Matrix6d &Kp);

// @brief Set the integral gain matrix
// @param Ki: 6x6 matrix containing the integral gain matrix
void setKi(const Eigen::Matrix6d &Ki);

// @brief Set the derivative gain matrix
// @param Kd: 6x6 matrix containing the derivative gain matrix
void setKd(const Eigen::Matrix6d &Kd);

// @brief Set the time step
// @param dt: Time step
void setTimeStep(double dt);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,37 @@
#include <std_msgs/msg/float64_multi_array.hpp>
#include <vortex_msgs/msg/reference_filter.hpp>

// @brief Class for the PID controller node
class PIDControllerNode : public rclcpp::Node {
public:
explicit PIDControllerNode();

private:
// @brief Callback function for the odometry topic
// @param msg: Odometry message containing the vehicle pose and velocity
void odometry_callback(const nav_msgs::msg::Odometry::SharedPtr msg);

void guidance_callback(const vortex_msgs::msg::ReferenceFilter::SharedPtr msg);

// @brief Callback function for the proportional gain matrix
void publish_tau();

// @brief Set the PID controller parameters
void set_pid_params();

// @brief Callback function for the proportional gain matrix
// @param msg: Float64MultiArray message containing the proportional gain matrix
void kp_callback(const std_msgs::msg::Float64MultiArray::SharedPtr msg);

// @brief Callback function for the integral gain matrix
// @param msg: Float64MultiArray message containing the integral gain matrix
void ki_callback(const std_msgs::msg::Float64MultiArray::SharedPtr msg);

// @brief Callback function for the derivative gain matrix
// @param msg: Float64MultiArray message containing the derivative gain matrix
void kd_callback(const std_msgs::msg::Float64MultiArray::SharedPtr msg);

void set_pid_params();
// @brief Callback function for the guidance topic
// @param msg: ReferenceFilter message containing the desired vehicle pose and velocity
void guidance_callback(const vortex_msgs::msg::ReferenceFilter::SharedPtr msg);

PIDController pid_controller_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,52 @@
#include <tf2/LinearMath/Matrix3x3.h>
#include <tf2/LinearMath/Quaternion.h>

Eigen::Matrix6d float64multiarray_to_diagonal_matrix6d(const std_msgs::msg::Float64MultiArray &msg);

// @brief Calculate the sine of an angle in degrees
// @param angle: Angle in degrees
// @return Smallest sine angle of the input
double ssa(double angle);

// Eigen::Vector6d apply_ssa(const Eigen::Vector7d &eta);
// @brief Convert a Float64MultiArray message to a 6x6 diagonal matrix
// @param msg: Float64MultiArray message containing 6 elements
// @return 6x6 diagonal matrix with the elements of the message on the diagonal
Eigen::Matrix6d float64multiarray_to_diagonal_matrix6d(const std_msgs::msg::Float64MultiArray &msg);

// @brief Calculate the rotation matrix from a quaternion
// @param q: Quaternion represented as a 4D vector [w, x, y, z]
// @return 3x3 rotation matrix
Eigen::Matrix3d calculate_R_quat(const Eigen::Vector4d &q);

// Eigen::Matrix3d calculate_T(const Eigen::Vector7d &eta);

// @brief Calculate the transformation matrix from a quaternion
// @param q: Quaternion represented as a 4D vector [w, x, y, z]
// @return 4x3 transformation matrix
Eigen::Matrix4x3d calculate_T_quat(const Eigen::Vector4d &q);

// @brief Calculate the Jacobian matrix
// @param eta: 7D vector containing the vehicle pose [x, y, z, w, x, y, z]
// @return 7x6 Jacobian matrix
Eigen::Matrix7x6d calculate_J(const Eigen::Vector7d &eta);

// @brief Calculate the pseudo-inverse of the Jacobian matrix
// @param eta: 7D vector containing the vehicle pose [x, y, z, w, x, y, z]
// @return 6x7 pseudo-inverse Jacobian matrix
Eigen::Matrix6x7d calculate_J_sudo_inv(const Eigen::Vector7d &eta);

// @brief Calculate the error between the desired and actual vehicle pose
// @param eta: 7D vector containing the actual vehicle pose [x, y, z, w, x, y, z]
// @param eta_d: 7D vector containing the desired vehicle pose [x, y, z, w, x, y, z]
// @return 7D vector containing the error between the desired and actual vehicle pose
Eigen::Vector7d error_eta(const Eigen::Vector7d &eta, const Eigen::Vector7d &eta_d);

Eigen::Matrix7x6d calculate_J(const Eigen::Vector7d &eta);

// @brief Calculate the anti-windup term
// @param dt: Time step
// @param error: 7D vector containing the error between the desired and actual vehicle pose [x, y, z, w, x, y, z]
// @param integral: 7D vector containing the integral term of the PID controller [x, y, z, w, x, y, z]
// @return 7D vector containing the anti-windup term
Eigen::Vector7d anti_windup(const double dt, const Eigen::Vector7d &error, const Eigen::Vector7d &integral);

// @brief Limit the input to the PID controller
// @param input: 6D vector containing the input to the PID controller [u, v, w, p, q, r]
// @return 6D vector containing the limited input to the PID controller [u, v, w, p, q, r]
Eigen::Vector6d limit_input(const Eigen::Vector6d &input);

#endif
17 changes: 2 additions & 15 deletions control/pid_controller_dp/src/pid_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ PIDController::PIDController()
dt(0.01) {}

Eigen::Vector6d PIDController::calculate_tau(const Eigen::Vector7d &eta, const Eigen::Vector7d &eta_d, const Eigen::Vector6d &nu, const Eigen::Vector7d &eta_dot_d) {
// Eigen::Vector6d error = apply_ssa(eta - eta_d);

// Eigen::Matrix6d J = calculate_J(eta);

// Eigen::Matrix6d J_inv = J.inverse();

Eigen::Vector7d error = error_eta(eta, eta_d);

Expand All @@ -26,13 +21,11 @@ Eigen::Vector6d PIDController::calculate_tau(const Eigen::Vector7d &eta, const E

Eigen::Vector6d P = Kp_ * J_inv * error;

Eigen::Vector6d I = Ki_ * J_inv * integral_ ;
Eigen::Vector6d I = Ki_ * J_inv * integral_;

Eigen::Vector6d D = Kd_ * error_nu;

Eigen::Vector6d tau = -(P + I + D);

tau = limit_input(tau);
Eigen::Vector6d tau = -limit_input((P + I + D));

integral_ = anti_windup(dt, error, integral_);

Expand All @@ -41,20 +34,14 @@ Eigen::Vector6d PIDController::calculate_tau(const Eigen::Vector7d &eta, const E

void PIDController::setKp(const Eigen::Matrix6d &Kp) {
this->Kp_ = Kp;
std::cout << "Kp: " << std::endl
<< Kp_ << std::endl;
}

void PIDController::setKi(const Eigen::Matrix6d &Ki) {
this->Ki_ = Ki;
std::cout << "Ki: " << std::endl
<< Ki_ << std::endl;
}

void PIDController::setKd(const Eigen::Matrix6d &Kd) {
this->Kd_ = Kd;
std::cout << "Kd: " << std::endl
<< Kd_ << std::endl;
}

void PIDController::setTimeStep(double dt) {
Expand Down
10 changes: 0 additions & 10 deletions control/pid_controller_dp/src/pid_controller_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ void PIDControllerNode::odometry_callback(const nav_msgs::msg::Odometry::SharedP
double y_ori = msg->pose.pose.orientation.y;
double z_ori = msg->pose.pose.orientation.z;

// tf2::Quaternion quat;
// quat.setX(msg->pose.pose.orientation.x);
// quat.setY(msg->pose.pose.orientation.y);
// quat.setZ(msg->pose.pose.orientation.z);
// quat.setW(msg->pose.pose.orientation.w);

// tf2::Matrix3x3 m(quat);
// double roll, pitch, yaw;
// m.getRPY(roll, pitch, yaw);

eta_ << x, y, z, w_ori, x_ori, y_ori, z_ori;

double u = msg->twist.twist.linear.x;
Expand Down
Loading