Skip to content

Commit a653392

Browse files
authored
Merge pull request #30 from RoboticExplorationLab/upgrade_rotations
Change UnitQuaternion to QuatRotation
2 parents de615b6 + 8b7e6db commit a653392

15 files changed

+471
-451
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name = "RobotDynamics"
22
uuid = "38ceca67-d8d3-44e8-9852-78a5596522e1"
33
authors = ["Brian Jackson <[email protected]>"]
4-
version = "0.4.7"
4+
version = "0.4.8"
55

66
[deps]
77
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
88
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
11+
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
1112
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1213
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
1314
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -17,6 +18,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1718
FiniteDiff = "2.8"
1819
ForwardDiff = "0.10"
1920
RecipesBase = "1"
20-
Rotations = "~1.0"
21+
Rotations = "1.0"
2122
StaticArrays = "1"
23+
Quaternions = "0.7"
2224
julia = "1"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ end
116116

117117
# Build model
118118
T = Float64
119-
R = UnitQuaternion{T}
119+
R = QuatRotation{T}
120120
mass = 1.0
121121
J = Diagonal(@SVector ones(3))
122122
model = Satellite{R,T}(mass, J)

examples/satellite_pair.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function RobotDynamics.dynamics(model::SatellitePair, x, u)
1919
q2 = qs[2]
2020

2121
J1, J2 = model.J1, model.J2
22-
u1 = u[SA[1,2,3]]
23-
u2 = u[SA[4,5,6]]
24-
ω1dot = J1\(u1 - ω1 × (J1 * ω1))
25-
ω2dot = J2\(u2 - ω2 × (J2 * ω2))
22+
u1 = u[SA[1, 2, 3]]
23+
u2 = u[SA[4, 5, 6]]
24+
ω1dot = J1 \ (u1 - ω1 × (J1 * ω1))
25+
ω2dot = J2 \ (u2 - ω2 × (J2 * ω2))
2626
q1dot = Rotations.kinematics(q1, ω1)
2727
q2dot = Rotations.kinematics(q2, ω2)
2828
SA[
@@ -35,27 +35,27 @@ end
3535

3636
RobotDynamics.control_dim(::SatellitePair) = 6
3737

38-
RobotDynamics.LieState(::SatellitePair{R}) where R = RobotDynamics.LieState(R, (0,3,3))
38+
RobotDynamics.LieState(::SatellitePair{R}) where {R} = RobotDynamics.LieState(R, (0, 3, 3))
3939

4040
J1 = SMatrix{3,3}(Diagonal(fill(1.0, 3)))
4141
J2 = SMatrix{3,3}(Diagonal(fill(2.0, 3)))
42-
model = SatellitePair{UnitQuaternion{Float64}, Float64}(J1, J2)
43-
x,u = rand(model)
42+
model = SatellitePair{QuatRotation{Float64},Float64}(J1, J2)
43+
x, u = rand(model)
4444
@test norm(x[1:4]) 1
4545
@test norm(x[8:11]) 1
4646
s = RobotDynamics.LieState(model)
4747
@test length(s) == 14
4848

4949
ω1 = x[5:7]
5050
ω2 = x[12:14]
51-
q1 = UnitQuaternion(x[1:4],false)
52-
q2 = UnitQuaternion(x[8:11],false)
51+
q1 = QuatRotation(x[1:4], false)
52+
q2 = QuatRotation(x[8:11], false)
5353
@test all(RobotDynamics.vec_states(s, x)[2:3] .≈ (ω1, ω2))
54-
@test all(RobotDynamics.rot_states(s, x) .≈ (q1,q2))
54+
@test all(RobotDynamics.rot_states(s, x) .≈ (q1, q2))
5555

5656

57-
model = SatellitePair{MRP{Float64}, Float64}(J1, J2)
58-
x,u = rand(model)
57+
model = SatellitePair{MRP{Float64},Float64}(J1, J2)
58+
x, u = rand(model)
5959
@test length(x) == 12
6060
s = RobotDynamics.LieState(model)
6161
@test length(s) == 12
@@ -65,4 +65,4 @@ s = RobotDynamics.LieState(model)
6565
q1 = MRP(x[1:3]...)
6666
q2 = MRP(x[7:9]...)
6767
@test all(RobotDynamics.vec_states(s, x)[2:3] .≈ (ω1, ω2))
68-
@test all(RobotDynamics.rot_states(s, x) .≈ (q1,q2))
68+
@test all(RobotDynamics.rot_states(s, x) .≈ (q1, q2))

examples/single_satellite.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RobotDynamics.inertia(model::Satellite) = model.J
1818
function RobotDynamics.forces(model::Satellite, x::StaticVector, u::StaticVector)
1919
q = orientation(model, x)
2020
F = @SVector [u[1], u[2], u[3]]
21-
q*F # world frame
21+
q * F # world frame
2222
end
2323

2424
# Define the 3D moments at the center of mass, in the body frame
@@ -29,14 +29,14 @@ end
2929

3030
# Build model
3131
T = Float64
32-
R = UnitQuaternion{T}
32+
R = QuatRotation{T}
3333
mass = 1.0
3434
J = Diagonal(@SVector ones(3))
3535
model = Satellite{R,T}(mass, J)
3636

3737
# Initialization
38-
x,u = rand(model)
39-
z = KnotPoint(x,u,0.1)
38+
x, u = rand(model)
39+
z = KnotPoint(x, u, 0.1)
4040
∇f = RobotDynamics.DynamicsJacobian(model)
4141

4242
# Continuous dynamics
@@ -51,8 +51,8 @@ function RobotDynamics.wrench_jacobian!(F, model::Satellite, z)
5151
u = control(z)
5252
q = orientation(model, x)
5353
ir, iq, iv, iω, iu = RobotDynamics.gen_inds(model)
54-
iF = SA[1,2,3]
55-
iM = SA[4,5,6]
54+
iF = SA[1, 2, 3]
55+
iM = SA[4, 5, 6]
5656
F[iF, iq] .= Rotations.∇rotate(q, u[iF])
5757
F[iF, iu[iF]] .= RotMatrix(q)
5858
for i = 1:3
@@ -63,8 +63,8 @@ end
6363
b2 = @benchmark jacobian!($∇f, $model, $z)
6464

6565
function RobotDynamics.wrench_sparsity(::Satellite)
66-
SA[false true false false true;
67-
false false false false true]
66+
SA[false true false false true;
67+
false false false false true]
6868
end
6969
b3 = @benchmark jacobian!($∇f, $model, $z)
7070
println("Analytical Wrench Jacobian: ", judge(minimum(b2), minimum(b1)))

src/RobotDynamics.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using FiniteDiff
88
using RecipesBase
99
using SparseArrays
1010
using Pkg
11+
using Quaternions
1112

1213
using Rotations: skew
1314
using StaticArrays: SUnitRange
@@ -51,7 +52,7 @@ function FiniteDiff.finite_difference_gradient!(
5152
# c1 is x1 if we need a complex copy of x, otherwise Nothing
5253
# c2 is Nothing
5354
fx, c1, c2, c3 = cache.fx, cache.c1, cache.c2, cache.c3
54-
copyto!(c3,x)
55+
copyto!(c3, x)
5556
if fdtype == Val(:forward)
5657
for i eachindex(x)
5758
epsilon = compute_epsilon(fdtype, x[i], relstep, absstep, dir)

0 commit comments

Comments
 (0)