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

Asv simulation #187

Open
wants to merge 91 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
573263b
Added plotting method choice
Mokaz Apr 7, 2024
cb30acf
Added hybridpath plotting (old, doesn't work with new hp)
Mokaz Apr 7, 2024
b0aac02
Added realtime simulator files
Mokaz Apr 7, 2024
9eaf96b
Set up python package, launch, lqr_config.yaml
vortexuser Jan 8, 2024
08f1d2c
Getting params from config file working
vortexuser Jan 8, 2024
00e8f56
Added dampening D
vortexuser Jan 8, 2024
a40004d
WIP not working
vortexuser Jan 8, 2024
63b1dc1
Ivan stuff working in ROS2
vortexuser Jan 9, 2024
63beabe
Implemented Ivan LOS LQR in ROS2
vortexuser Jan 9, 2024
3a52888
Added los_guidance package
vortexuser Jan 9, 2024
1a2446f
Added x_ref LOS calculation and Odometry
vortexuser Jan 9, 2024
9e15d0d
Added Odometry
vortexuser Jan 9, 2024
0af90b6
WIP need to fix lqr
vortexuser Jan 10, 2024
4ed491e
Fixed x_ref dimensions
vortexuser Jan 11, 2024
f050c64
Made package
vortexuser Jan 11, 2024
15a8416
WIP stuff
vortexuser Jan 12, 2024
e7c428b
Vessel Simulator working, added giraffe
Mokaz Jan 21, 2024
ecb6487
Updated giraffe message, added write np.array to file
Mokaz Jan 21, 2024
934a13a
Changed magic number to be like Ivan sim (still not work)
Mokaz Jan 24, 2024
be8c70f
Edited points
Mokaz Jan 25, 2024
1a29a28
Updated switching logic with line in front of endpoint, point subscri…
Jan 28, 2024
26c085f
Fixed plotting points, removed ivansim
Mokaz Feb 4, 2024
1d772d0
Add hybridpath_controller package files
Mokaz Feb 14, 2024
e1df116
Added adaptive backstepping controller and plotting
Mokaz Feb 18, 2024
be786be
Added simulation function
Mokaz Feb 18, 2024
4348843
Added hybridpath_guidance, updated hybridpath controller node
Mokaz Feb 25, 2024
5c8543c
Seemingly working hybridpath_controller
Mokaz Feb 28, 2024
b93be23
Finished hybridpath simulator
Mokaz Mar 5, 2024
1d3b6ae
Plotting works almost perfectly
Mokaz Mar 8, 2024
93b8ddc
Removed duplicate launch file, added READMEs, added docs and typehint…
Mokaz Mar 10, 2024
a0d930c
Added default kappa value to AdaptiveBackstep
Mokaz Mar 10, 2024
95c847d
Added s_ reset when updating path in guidance
Mokaz Mar 10, 2024
ab3d76c
Added WIP unit test for hybridpath_controller control_law
Mokaz Mar 10, 2024
ee3b9ee
Added working unit test for control law
Mokaz Mar 10, 2024
cba7dd2
Removed testing stuff and comments
Mokaz Mar 10, 2024
4388c52
Cleanup and made ready for testing.
Andeshog Mar 21, 2024
e695dc5
Removed plotting function and example usage
Andeshog Mar 21, 2024
f0505b5
Cleanup
Andeshog Mar 21, 2024
decf3d7
Added return type for every function
Andeshog Mar 21, 2024
fa9bcb9
Added type annotations
Andeshog Mar 21, 2024
d415572
Added theory to README, and fixes to hybridpath
Andeshog Mar 22, 2024
85a0497
Updated README
Andeshog Mar 22, 2024
48a526d
Update README
Andeshog Mar 22, 2024
c49dd05
Fixed README
Andeshog Mar 22, 2024
747a383
Fix README
Andeshog Mar 22, 2024
7710d81
Fix README
Andeshog Mar 22, 2024
ff47eec
Minor fixes
Andeshog Mar 23, 2024
d943b2e
Minor name changes
Andeshog Mar 23, 2024
3c22764
Added theory in README
Andeshog Mar 23, 2024
cb3e04d
Fix link
Andeshog Mar 23, 2024
4d79388
Fix link
Andeshog Mar 23, 2024
227631b
typo
Andeshog Mar 23, 2024
194edce
Fix hybridpath guidance callback and readme
Andeshog Mar 27, 2024
8fddd14
Removed plotting
Andeshog Mar 28, 2024
4dee062
Moved K1 and K2 to yaml
Andeshog Mar 28, 2024
ae0f8e7
Merge branch 'hybridpath_to_CMakeLists'
Mokaz Mar 28, 2024
38c3980
Removed both simulators (to be readded at a later time)
Mokaz Mar 28, 2024
836def7
Removed launch file for old LQR LOS simulator
Mokaz Mar 28, 2024
0c63b7b
Fixed asv_setup hybridpath nitpick
Mokaz Apr 3, 2024
31e3383
Fixed hp controller import parameters
Mokaz Apr 3, 2024
2304101
Removed los_guidance
Mokaz Apr 3, 2024
46d376e
Removed old lqr_controller
Mokaz Apr 7, 2024
476762e
Added otter inertia and damping matrices
Andeshog Apr 7, 2024
d47b221
Added coriolis matrix
Andeshog Apr 7, 2024
6346324
Added source
Andeshog Apr 11, 2024
4ab359d
Rewrite hybridpath
Andeshog Apr 11, 2024
f3267b5
Fix node
Andeshog Apr 11, 2024
e26a289
Added update method for s
Andeshog Apr 11, 2024
2ff38ee
Fixes to hybridpath node
Andeshog Apr 11, 2024
0f5cf9d
Initial test file
Andeshog Apr 11, 2024
3f324b9
Fix node to publish vs and vss
Andeshog Apr 11, 2024
8a7c254
Docstring for update_s method
Andeshog Apr 11, 2024
2ac9cf9
Deleted lqr_controller package
Mokaz Apr 14, 2024
e7fbf97
Fixed import params from freya.yaml
Mokaz Apr 14, 2024
d2306ef
Typo
Andeshog Apr 11, 2024
3a8b234
Added source
Andeshog Apr 14, 2024
a620171
Fixes to hybridpath
Andeshog Apr 14, 2024
9f8658d
Added staticmethod odom_to_state
Andeshog Apr 14, 2024
3d9b350
Fix odom_to_eta
Andeshog Apr 14, 2024
a6e0299
Moved odom_to_eta to node
Andeshog Apr 14, 2024
25bab02
Added fixes to node
Andeshog Apr 14, 2024
c4b0475
Fix update_s
Andeshog Apr 14, 2024
c1cd708
Added mu tuning parameter to hp guidance
Mokaz Apr 14, 2024
377a20e
Added simulator support for foxglove realtime sim
Mokaz Apr 14, 2024
580fa42
Added matplotlib plotting, progress bar, giraffe
Mokaz Apr 15, 2024
8ae411f
Added setting of waypoints in yaml file, removed giraffe
Mokaz Apr 21, 2024
385b96c
Added LQR_DP
Mokaz Apr 22, 2024
26d26be
Removed xref test, added email to package.xml
Mokaz Apr 26, 2024
4df1d84
Added guidance callback for updating x_ref
Mokaz Apr 26, 2024
0026c06
Fixed guidance callback
Mokaz Apr 27, 2024
1056e4f
Fixed guidance callback for DP
Mokaz Apr 28, 2024
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
2 changes: 2 additions & 0 deletions asv_setup/config/robots/freya.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
buoyancy: 0 # kg
center_of_mass: [0, 0, 0] # mm (x,y,z)
center_of_buoyancy: [0, 0, 0] # mm (x,y,z)
inertia_matrix: [90.5, 0.0, 0.0, 0.0, 167.5, 12.25, 0.0, 12.25, 42.65] # from otter
damping_matrix_diag: [77.55, 162.5, 42.65] # from otter


propulsion:
Expand Down
25 changes: 25 additions & 0 deletions asv_setup/launch/hybridpath.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.actions import SetEnvironmentVariable, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
hybridpath_controller_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory('hybridpath_controller'), 'launch', 'hybridpath_controller.launch.py')
)
)

hybridpath_guidance_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory('hybridpath_guidance'), 'launch', 'hybridpath_guidance.launch.py')
)
)

# Return launch description
return LaunchDescription([
hybridpath_controller_launch,
hybridpath_guidance_launch
])
35 changes: 35 additions & 0 deletions guidance/hybridpath_guidance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.8)
project(hybridpath_guidance)

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
hybridpath_guidance/hybridpath_guidance_node.py
DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
ament_add_pytest_test(python_tests tests)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
endif()

ament_package()
131 changes: 131 additions & 0 deletions guidance/hybridpath_guidance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Hybrid Path Guidance

This package provides the implementation of hybrid path guidance for the Vortex ASV.

## Usage

To use the hybrid path guidance launch it using: `ros2 launch hybridpath_guidance hybridpath_guidance.launch`
Or alternatively, run it together with the hybridpath controller using the launch file `hybridpath.launch.py` in asv_setup

To run with custom waypoints (replace example waypoints with actual waypoints, and add as many prefered):

`ros2 service call waypoint_list vortex_msgs/srv/Waypoint "waypoint: [{x: 0.0, y: 0.0, z: 0.0}, {x: 5.0, y: 5.0, z: 0.0}]"`

## Configuration

You can configure the behavior of the hybrid path guidance by modifying the parameters in the `config` directory.

## Theory
### Path generation
Given a set of $n + 1$ waypoints, the hybridpath generator will generate a $C^r$ path that goes through the waypoints. That is, the path is continuous in $r$ derivatives. Towards constructing the overall desired path $p_d(s)$, it is first divided into $n$ subpaths $p_{d,i}(s)$ for $i = 1, ... , n$ between the waypoints. Each of these is expressed as a polynomial in $s$ of a certain order. Then the expressions for the subpaths are concatenated at the waypoints to assemble the full path. The order of the polynomials must be chosen sufficiently high to ensure the overall path is sufficiently differentiable at the waypoints. Increasing the order of the polynomial increases the number of coefficients giving more degrees-of-freedom to satisfy these continuity constraints.

The variable $s \in [0,n)$ is called the path variable, and it tells us exactly where we are on the path. For example, $s$ will be $0$ at the first waypoint, $1$ at the second, and so on. However, using the path parameter to take values $s \in [0,n)$ is unnecessary and can be numerically problematic. Instead, we can identify each path segment $p_i$ and parametrize it by $\theta \in [0,1)$. We define
```math
i := \lfloor s \rfloor + 1
```
```math
\theta = s - \lfloor s \rfloor \in [0,1)
```

to get the continuous map
```math
s \mapsto p_d(s)
```

Consider polynomials of order $k$,
```math
x_{d,i}(\theta) = a_{k,i} \theta^k + ... + a_{1,i} \theta + a_{0,i}
```
```math
y_{d,i}(\theta) = b_{k,i} \theta^k + ... + b_{1,i} \theta + b_{0,i}
```
where the coefficients {$`a_{j,i}`$, $`b_{j,i}`$} must be determined. For each subpath there are $(k + 1)$ $\cdot$ $2$ unknowns so that there are $(k + 1)$ $\cdot$ $2n$ unknown coefficients in total to be determined for the full path. This is done by setting up and solving the linear system
```math
A\phi = b \; \; \; \; \; \; \phi^T = [a^T, b^T]
```
for each path segment and solve them in a single operation as $` \phi = A^{-1}b`$.

Assuming that the subpaths is to be connected at the waypoints, we use the following procedure to calculate the coefficients of each subpath:

$C^0$ : Continuity at the waypoints gives for i:
```math
x_{d,i}(0) = x_{i-1} \; \; \; \; \; \; y_{d,i}(0) = y_{i-1}
```
```math
x_{d,i}(1) = x_i \; \; \; \; \; \; y_{d,i}(1) = y_i
```

$C^1$ : The slopes at the first and last waypoints are chosen as:
```math
x^\theta_{d,i}(0) = x_1 - x_0 \; \; \; \; \; \; y^\theta_{d,1}(0) = y_1 - y_0
```
```math
x^\theta_{d,n}(1) = x_n - x_{n-1} \; \; \; \; \; \; y^\theta_{d,n}(1) = y_n - y_{n-1}
```

Here, $x^\theta$ represents the derivative of $x$ with respect to $\theta$.

The slopes at the intermediate waypoints are chosen as:
```math
x^\theta_{d,i}(0) = \lambda (x_i - x_{i-2}) \; \; \; \; \; \; i = 2, ... , n
```
```math
y^\theta_{d,i}(0) = \lambda (y_i - y_{i-2}) \; \; \; \; \; \; i = 2, ... , n
```
```math
x^\theta_{d,i}(1) = \lambda (x_{i+1} - x_{i-1}) \; \; \; \; \; \; i = 1, ... , n-1
```
```math
y^\theta_{d,1}(1) = \lambda (y_{i+1} - y_{i-1}) \; \; \; \; \; \; i = 1, ... , n-1
```
where $\lambda > 0$ is a design constant. Choosing $\lambda > 0.5$ gives more rounded corners, choosing $\lambda < 0.5$ gives sharper corners and choosing $\lambda = 0.5$ makes the slope at waypoint $p_i$ be the average of pointing to $p_{i-1}$ and $p_{i+1}$

$C^j$ : Setting derivatives of order $j = 2, 3, ... , k$ to zero for i:
```math
x^{\theta^j}_{d,i}(0) = 0 \; \; \; \; \; \; y^{\theta^j}_{d,i}(0) = 0
```
```math
x^{\theta^j}_{d,i}(1) = 0 \; \; \; \; \; \; y^{\theta^j}_{d,i}(1) = 0
```
This results in the hybrid parametrization of the path,
```math
\bar{p_d}(i,\theta) = \begin{bmatrix} x_{d,i}(\theta) \\ y_{d,i}(\theta) \end{bmatrix}
```

where $\theta \in [0,1)$.

If the differentiability requirement of the path is $C^r$, then the above equations up to $j=r$ gives $2(r+1) \cdot 2n$ equations to solve for $(k + 1) \cdot 2n$ unknown coefficients. As a result, the order $k$ of the polynomials must be
```math
k = 2r + 1
```

### Guidance system
So far we have defined the desired path
```math
p_d(i,\theta) = \begin{bmatrix} x_d(i,\theta) \\ y_d(i,\theta) \end{bmatrix},\; \theta \in [0,1)
```
. Now we define the desired heading
```math
\psi_d = atan2(y^\theta_d(i,\theta), x^\theta_d(i,\theta))
```
where $atan2(y,x)$ is the four-quadrant version of $arctan(y/x)$. As mentioned previously, the pair $(i,\theta)$ tells us which path segment $i$ we are on and where on the segment we are (given by $\theta$). Since we also need the first and second derivatives of the heading for the controller, we define them as:
```math
\psi^\theta_d(i,\theta) = \frac{x^\theta_d(i,\theta)y^{\theta^2}_d(i,\theta)-x^{\theta^2}_d(i,\theta)y^\theta_d(i,\theta)}{x^\theta_d(i,\theta)^2+y^\theta_d(i,\theta)^2}
```

Differentiating one more time yields:

```math
\psi^{\theta^2}_d(i,\theta) = \frac{x^\theta_d(i,\theta)y^{\theta^3}_d(i,\theta)-x^{\theta^3}_d(i,\theta)y^\theta_d(i,\theta)}{x^\theta_d(i,\theta)^2+y^\theta_d(i,\theta)^2} \\-2\frac{(x^\theta_d(i,\theta)y^{\theta^2}_d(i,\theta)-x^{\theta^2}_d(i,\theta)y^\theta_d(i,\theta))(x^\theta_d(i,\theta)x^{\theta^2}_d(i,\theta)-y^{\theta^2}_d(i,\theta)y^\theta_d(i,\theta))}{(x^\theta_d(i,\theta)^2+y^\theta_d(i,\theta)^2)^2}
```

Source: https://folk.ntnu.no/rskjetne/Publications/SkjetnePhDthesis_B5_compressed.pdf

### Example plots

These plots showcases the what the $r$ and $\lambda$ parameters does to the path.

![Path Plots](https://drive.google.com/uc?export=download&id=1CE8kN1yJSjEgiCdWGQYgjdIfSkE40V1f)

![Lambda Plots](https://drive.google.com/uc?export=download&id=1TtpIAwBRKcZhpuXAUEinpuqUhN-WKoX-)

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**:
ros__parameters:
hybridpath_guidance:
lambda_val: 0.15 # Curvature constant
path_generator_order: 1 # Differentiability order
time_to_max_speed: 10.0 # Time to reach maximum speed
dt: 0.1 # Time step
u_desired: 0.5 # Desired speed
mu: 0.03 # Tuning parameter
Empty file.
Loading
Loading