-
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.
Merge branch 'butbetter' into 'main'
butbetter See merge request acubesat/adcs/adcs-simulation-julia!4
- Loading branch information
Showing
13 changed files
with
220 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ authors = ["Orestis Ousoultzoglou <[email protected]>", "Romanos Voulgar | |
version = "0.0.1-DEV" | ||
|
||
[deps] | ||
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
Optim = "429524aa-4258-5aef-a3af-852621145aeb" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
|
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,33 +1,27 @@ | ||
qderiv(w, q) = 0.5 * (quat_mult(vcat(0, w), q)) | ||
qderiv(w, q) = 0.5 * (Quaternion([w; 0.0]) * q) | ||
|
||
function wqderiv(I, w, torque, q) | ||
dw_dt = vec(I \ (torque - w × (I * w))) | ||
|
||
dq_dt = qderiv(w, q) | ||
|
||
return dw_dt, dq_dt | ||
end | ||
|
||
function rk4(I, w, torque, q, dt) | ||
k1_w, k1_q = wqderiv(I, w, torque, q) | ||
k2_w, k2_q = wqderiv(I, w .+ 0.5 .* dt .* k1_w, torque, q .+ 0.5 .* dt .* k1_q) | ||
k3_w, k3_q = wqderiv(I, w .+ 0.5 .* dt .* k2_w, torque, q .+ 0.5 .* dt .* k2_q) | ||
k4_w, k4_q = wqderiv(I, w .+ dt .* k3_w, torque, q .+ dt .* k3_q) | ||
|
||
k2_w, k2_q = wqderiv(I, w .+ 0.5 .* dt .* k1_w, torque, q + 0.5 * dt * k1_q) | ||
k3_w, k3_q = wqderiv(I, w .+ 0.5 .* dt .* k2_w, torque, q + 0.5 * dt * k2_q) | ||
k4_w, k4_q = wqderiv(I, w .+ dt .* k3_w, torque, q + dt * k3_q) | ||
new_w = w .+ (dt / 6.0) .* (k1_w .+ 2 .* k2_w .+ 2 .* k3_w .+ k4_w) | ||
new_q = q .+ (dt / 6.0) .* (k1_q .+ 2 .* k2_q .+ 2 .* k3_q .+ k4_q) | ||
|
||
new_q = q + (dt / 6.0) * (k1_q + 2 * k2_q + 2 * k3_q + k4_q) | ||
new_q = normalize(new_q) | ||
|
||
return new_w, new_q | ||
end | ||
|
||
function rk4_filter(w, q, dt) | ||
k1_q = qderiv(w, q) | ||
k2_q = qderiv(w, q .+ 0.5 .* dt .* k1_q) | ||
k3_q = qderiv(w, q .+ 0.5 .* dt .* k2_q) | ||
k4_q = qderiv(w, q .+ dt .* k3_q) | ||
new_q = q .+ (dt / 6.0) .* (k1_q .+ 2 .* k2_q .+ 2 .* k3_q .+ k4_q) | ||
new_q = normalize(new_q) | ||
k2_q = qderiv(w, q + 0.5 * dt * k1_q) | ||
k3_q = qderiv(w, q + 0.5 * dt * k2_q) | ||
k4_q = qderiv(w, q + dt * k3_q) | ||
new_q = normalize(q + (dt / 6.0) * (k1_q + 2 * k2_q + 2 * k3_q + k4_q)) | ||
return new_q | ||
end |
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 +1,6 @@ | ||
mse(ŷ, y; agg = mean) = agg(abs2.(ŷ .- y)) | ||
mse(ŷ, y; agg=mean) = agg(abs2.(ŷ .- y)) | ||
|
||
function qloss(q̂, q) | ||
relq = q * conj(q̂) | ||
return norm(vector(relq)) | ||
end |
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
Oops, something went wrong.