-
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
Aldokan
committed
Apr 28, 2024
1 parent
bf53c89
commit bf669a6
Showing
16 changed files
with
315 additions
and
29 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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**: | ||
ros__parameters: | ||
lqr_controller: | ||
Q: [20.0, 20.0, 1.0, 1.0, 1.0, 1.0] # State costs for [x, y, heading, surge, sway, yaw] | ||
Q: [20.0, 20.0, 1.0, 1.0, 1.0, 1.0] # State costs for [x, y, heading, x_dot, y_dot, heading_dot] | ||
R: [1.0, 1.0, 1.0] # Control cost weight |
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,27 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(pid_controller) | ||
|
||
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_python REQUIRED) | ||
find_package(rclpy REQUIRED) | ||
find_package(vortex_msgs REQUIRED) | ||
find_package(geometry_msgs REQUIRED) | ||
|
||
ament_python_install_package(${PROJECT_NAME}) | ||
|
||
install(DIRECTORY | ||
launch | ||
config | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
install(PROGRAMS | ||
pid_controller/pid_controller_node.py | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
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,6 @@ | ||
/**: | ||
ros__parameters: | ||
pid_controller: | ||
Kp: [23.04, 34.56, 4.032] # Proportional costs for [x, y, heading] | ||
Ki: [2.76, 4.1, 0.48] # Integral costs for [x, y, heading] | ||
Kd: [28.7648, 43.1472, 5.048384] # Derivative costs for [x, y, heading] |
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,19 @@ | ||
import os | ||
from ament_index_python.packages import get_package_share_directory | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
|
||
def generate_launch_description(): | ||
pid_controller_node = Node( | ||
package='pid_controller', | ||
executable='pid_controller_node.py', | ||
name='pid_controller_node', | ||
parameters=[ | ||
os.path.join(get_package_share_directory('pid_controller'),'config','pid_config.yaml'), | ||
os.path.join(get_package_share_directory('asv_setup'), 'config', 'robots', 'freya.yaml') | ||
], | ||
output='screen', | ||
) | ||
return LaunchDescription([ | ||
pid_controller_node | ||
]) |
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"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>pid_controller</name> | ||
<version>0.0.0</version> | ||
<description>This is an implementation of the PID DP controller for the ASV</description> | ||
<maintainer email="[email protected]">vortex</maintainer> | ||
<license>MIT</license> | ||
|
||
<buildtool_depend>ament_cmake_python</buildtool_depend> | ||
|
||
<depend>rclpy</depend> | ||
<depend>python-transforms3d-pip</depend> | ||
<depend>nav_msgs</depend> | ||
<depend>geometry_msgs</depend> | ||
<depend>vortex_msgs</depend> | ||
<depend>std_msgs</depend> | ||
<depend>numpy</depend> | ||
<depend>matplotlib</depend> | ||
<depend>scipy</depend> | ||
|
||
<test_depend>python3-pytest</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
Empty file.
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,59 @@ | ||
import numpy as np | ||
|
||
from transforms3d.euler import euler2quat, quat2euler | ||
from nav_msgs.msg import Odometry | ||
from geometry_msgs.msg import PoseStamped | ||
|
||
|
||
def odometrymsg_to_state(msg): | ||
x = msg.pose.pose.position.x | ||
y = msg.pose.pose.position.y | ||
orientation_q = msg.pose.pose.orientation | ||
orientation_list = [ | ||
orientation_q.w, orientation_q.x, orientation_q.y, orientation_q.z | ||
] | ||
|
||
# Convert quaternion to Euler angles, extract yaw | ||
yaw = quat2euler(orientation_list)[2] | ||
|
||
vx = msg.twist.twist.linear.x | ||
vy = msg.twist.twist.linear.y | ||
vyaw = msg.twist.twist.angular.z | ||
|
||
state = np.array([x, y, yaw, vx, vy, vyaw]) | ||
return state | ||
|
||
def state_to_odometrymsg(state): | ||
orientation_list_next = euler2quat(0, 0, state[2]) | ||
|
||
odometry_msg = Odometry() | ||
odometry_msg.pose.pose.position.x = state[0] | ||
odometry_msg.pose.pose.position.y = state[1] | ||
odometry_msg.pose.pose.position.z = 0.0 | ||
odometry_msg.pose.pose.orientation.w = orientation_list_next[0] | ||
odometry_msg.pose.pose.orientation.x = orientation_list_next[1] | ||
odometry_msg.pose.pose.orientation.y = orientation_list_next[2] | ||
odometry_msg.pose.pose.orientation.z = orientation_list_next[3] | ||
|
||
return odometry_msg | ||
|
||
def state_to_posestamped(state, frame_id, stamp): | ||
orientation_list_next = euler2quat(0, 0, state[2]) | ||
|
||
posestamped_msg = PoseStamped() | ||
|
||
posestamped_msg.header.frame_id = frame_id | ||
posestamped_msg.header.stamp = stamp | ||
|
||
posestamped_msg.pose.position.x = state[0] | ||
posestamped_msg.pose.position.y = state[1] | ||
posestamped_msg.pose.position.z = 0.0 | ||
posestamped_msg.pose.orientation.w = orientation_list_next[0] | ||
posestamped_msg.pose.orientation.x = orientation_list_next[1] | ||
posestamped_msg.pose.orientation.y = orientation_list_next[2] | ||
posestamped_msg.pose.orientation.z = orientation_list_next[3] | ||
|
||
return posestamped_msg | ||
|
||
def ssa(angle): | ||
return (angle + np.pi) % (2 * np.pi) - np.pi |
Oops, something went wrong.