Skip to content

Commit c957819

Browse files
authored
Merge pull request #117 from JuliaComputing/nonegw
rm some uses of neg_w=false
2 parents 38abc92 + 17acb1b commit c957819

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

docs/src/examples/pendulum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ nothing # hide
139139
### Why do we need a joint?
140140
In the example above, we introduced a prismatic joint to model the oscillating motion of the mass-spring system. In reality, we can suspend a mass in a spring without any joint, so why do we need one here? The answer is that we do not, in fact, need the joint, but if we connect the spring directly to the world, we need to make the body (mass) the root object of the kinematic tree instead:
141141
```@example pendulum
142-
@named root_body = Body(; m = 1, isroot = true, r_cm = [0, 1, 0], phi0 = [0, 1, 0], neg_w=false)
142+
@named root_body = Body(; m = 1, isroot = true, r_cm = [0, 1, 0], phi0 = [0, 1, 0])
143143
@named multibody_spring = Multibody.Spring(c=10)
144144
145145
connections = [connect(world.frame_b, multibody_spring.frame_a)
@@ -148,11 +148,11 @@ connections = [connect(world.frame_b, multibody_spring.frame_a)
148148
@named model = ODESystem(connections, t, systems = [world, multibody_spring, root_body])
149149
ssys = structural_simplify(IRSystem(model))
150150
151-
defs = Dict()
151+
defs = Dict(collect(root_body.r_0) .=> [0, 1e-3, 0]) # The spring has a singularity at zero length, so we start some distance away
152152
153153
prob = ODEProblem(ssys, defs, (0, 10))
154154
155-
sol = solve(prob, Rodas4(), u0 = prob.u0 .+ 1e-5 .* randn.())
155+
sol = solve(prob, Rodas4())
156156
plot(sol, idxs = multibody_spring.r_rel_0[2], title="Mass-spring system without joint")
157157
```
158158
Here, we used a [`Multibody.Spring`](@ref) instead of connecting a `Translational.Spring` to a joint. The `Translational.Spring`, alongside other components from `ModelingToolkitStandardLibrary.Mechanical`, is a 1-dimensional object, whereas multibody components are 3-dimensional objects.

docs/src/examples/swing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Next, we create the full swing assembly
102102
body_left = BodyShape(m=0.1, r = [0, 0, w])
103103
body_right = BodyShape(m=0.1, r = [0, 0, -w])
104104
105-
body = Body(m=6, isroot=true, r_cm = [w/2, -w/2, w/2], neg_w=true, cylinder_radius=0.01)
105+
body = Body(m=6, isroot=true, r_cm = [w/2, -w/2, w/2], cylinder_radius=0.01)
106106
107107
damper = Damper(d=0.5)
108108
end

test/test_quaternions.jl

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# test utils
1+
using Test
22
import Multibody.Rotations.QuatRotation as Quat
33
import Multibody.Rotations
44
import Multibody.Rotations: RotXYZ
@@ -149,7 +149,7 @@ end
149149
t = Multibody.t
150150
world = Multibody.world
151151

152-
@named joint = Multibody.FreeMotion(isroot = true, state=true, quat=true, neg_w=false)
152+
@named joint = Multibody.FreeMotion(isroot = true, state=true, quat=true, neg_w=true)
153153
@named body = Body(; m = 1, r_cm = [0.0, 0, 0])
154154

155155
connections = [connect(world.frame_b, joint.frame_a)
@@ -196,15 +196,15 @@ end
196196
## Spherical joint pendulum with quaternions
197197
# ============================================================
198198

199-
@testset "Spherical joint with quaternion state" begin
199+
# @testset "Spherical joint with quaternion state" begin
200200
using LinearAlgebra, ModelingToolkit, Multibody, JuliaSimCompiler
201201
t = Multibody.t
202202
world = Multibody.world
203203

204204

205205
@named joint = Multibody.Spherical(isroot=false, state=false, quat=false)
206206
@named rod = FixedTranslation(; r = [1, 0, 0])
207-
@named body = Body(; m = 1, isroot=true, quat=true, air_resistance=0.0, neg_w=false)
207+
@named body = Body(; m = 1, isroot=true, quat=true, air_resistance=0.0, neg_w=true)
208208

209209
# @named joint = Multibody.Spherical(isroot=true, state=true, quat=true)
210210
# @named body = Body(; m = 1, r_cm = [1.0, 0, 0], isroot=false)
@@ -217,45 +217,42 @@ end
217217
@named model = ODESystem(connections, t,
218218
systems = [world, joint, body, rod])
219219
irsys = IRSystem(model)
220-
@test_skip begin # https://github.com/JuliaComputing/JuliaSimCompiler.jl/issues/298
221-
ssys = structural_simplify(irsys)
220+
ssys = structural_simplify(irsys)
222221

223222

224-
D = Differential(t)
225-
# q0 = randn(4); q0 ./= norm(q0)
226-
# q0 = [1,0,0,0]
227-
prob = ODEProblem(ssys, [
228-
collect(body.w_a) .=> [1,0,0];
229-
# collect(body.Q) .=> q0;
230-
# collect(body.Q̂) .=> q0;
231-
], (0, 30))
223+
D = Differential(t)
224+
# q0 = randn(4); q0 ./= norm(q0)
225+
# q0 = [1,0,0,0]
226+
prob = ODEProblem(ssys, [
227+
# collect(body.w_a) .=> [1,0,0];
228+
# collect(body.Q) .=> q0;
229+
body.k => 0.1;
230+
collect(body.Q̂d) .=> [0,0,0,0];
231+
], (0, 30))
232232

233-
using OrdinaryDiffEq, Test
234-
sol = solve(prob, Rodas4(); u0 = prob.u0 .+ 0 .* randn.())
235-
@test SciMLBase.successful_retcode(sol)
236-
# doplot() && plot(sol, layout=21)
233+
using OrdinaryDiffEq, Test
234+
sol = solve(prob, Rodas5Pr(); u0 = prob.u0 .+ 0 .* randn.())
235+
@test SciMLBase.successful_retcode(sol)
236+
# doplot() && plot(sol, layout=21)
237237

238238

239-
ts = 0:0.1:2pi
240-
Q = Matrix(sol(ts, idxs = [body.Q...]))
241-
Qh = Matrix(sol(ts, idxs = [body....]))
242-
n = Matrix(sol(ts, idxs = [body.n...]))
243-
@test mapslices(norm, Qh, dims=1).^2 n
244-
@test Q Qh ./ sqrt.(n) atol=1e-2
245-
@test norm(mapslices(norm, Q, dims=1) .- 1) < 1e-2
239+
ts = 0:0.1:2pi
240+
Q = Matrix(sol(ts, idxs = [body.Q...]))
241+
Qh = Matrix(sol(ts, idxs = [body....]))
242+
n = Matrix(sol(ts, idxs = [body.n...]))
243+
@test mapslices(norm, Qh, dims=1).^2 n
244+
@test Q Qh ./ sqrt.(n) atol=1e-2
245+
@test norm(mapslices(norm, Q, dims=1) .- 1) < 1e-2
246246

247-
Matrix(sol(ts, idxs = [body.w_a...]))
247+
Matrix(sol(ts, idxs = [body.w_a...]))
248248

249-
@test get_R(sol, joint.frame_b, 0pi) I
250-
@test get_R(sol, joint.frame_b, sqrt(9.81/1)) diagm([1, -1, -1]) atol=1e-3
251-
@test get_R(sol, joint.frame_b, 2pi) I atol=1e-3
249+
@test get_R(sol, joint.frame_b, 0pi) I
252250

253251

254-
# Matrix(sol(ts, idxs = [joint.w_rel_b...]))
252+
# Matrix(sol(ts, idxs = [joint.w_rel_b...]))
255253

256-
# render(model, sol)
257-
end
258-
end
254+
# render(model, sol)
255+
# end
259256

260257

261258
# ==============================================================================

0 commit comments

Comments
 (0)