Skip to content

Commit 57851df

Browse files
committed
add test for JointRRR
change order of operations
1 parent 4776119 commit 57851df

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed

src/fancy_joints.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ The rest of this joint aggregation is defined by the following parameters:
519519
end
520520

521521
@parameters begin
522-
n1_a[1:3] = n1_a, [description = "Axis 1 of universal joint fixed and resolved in frame_a (axis 2 is orthogonal to axis 1 and to rod 1)"]
522+
# n1_a[1:3] = n1_a, [description = "Axis 1 of universal joint fixed and resolved in frame_a (axis 2 is orthogonal to axis 1 and to rod 1)"]
523523
# n_b[1:3] = n_b, [description = "Axis of revolute joint fixed and resolved in frame_b"]
524524
rRod1_ia[1:3] = rRod1_ia, [description = "Vector from origin of frame_a to spherical joint, resolved in frame_ia"]
525525
# rRod2_ib[1:3] = rRod2_ib, [description = "Vector from origin of frame_ib to spherical joint, resolved in frame_ib"]
@@ -648,15 +648,15 @@ Basically, the JointRRR model internally consists of a universal-spherical-revol
648648
rRod2_ib = [-1,0,0],
649649
phi_offset = 0,
650650
phi_guess = 0,
651-
651+
positive_branch = true,
652652
)
653653

654654
@parameters begin
655-
n_a[1:3] = n_a, [description = "Axes of revolute joints resolved in frame_a (all axes are parallel to each other)"]
656-
n_b[1:3] = n_b, [description = "Axis of revolute joint fixed and resolved in frame_b"]
655+
# n_a[1:3] = n_a, [description = "Axes of revolute joints resolved in frame_a (all axes are parallel to each other)"]
656+
# n_b[1:3] = n_b, [description = "Axis of revolute joint fixed and resolved in frame_b"]
657657
rRod1_ia[1:3] = rRod1_ia, [description = "Vector from origin of frame_a to revolute joint in the middle, resolved in frame_ia"]
658-
rRod2_ib[1:3] = rRod2_ib, [description = "Vector from origin of frame_ib to revolute joint in the middle, resolved in frame_ib"]
659-
phi_offset = phi_offset, [description = "Relative angle offset of revolute joint at frame_b (angle = phi(t) + from_deg(phi_offset))"]
658+
# rRod2_ib[1:3] = rRod2_ib, [description = "Vector from origin of frame_ib to revolute joint in the middle, resolved in frame_ib"]
659+
# phi_offset = phi_offset, [description = "Relative angle offset of revolute joint at frame_b (angle = phi(t) + from_deg(phi_offset))"]
660660
phi_guess = phi_guess, [description = "Select the configuration such that at initial time |phi(t0) - from_deg(phi_guess)| is minimal"]
661661

662662
end
@@ -675,6 +675,7 @@ Basically, the JointRRR model internally consists of a universal-spherical-revol
675675
phi_guess,
676676
rRod2_ib,
677677
rRod1_ia,
678+
positive_branch
678679
)
679680
end
680681

test/runtests.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1323,3 +1323,9 @@ sol = solve(prob, Rodas4())
13231323
@test sol[model.cyl.v][end] -9.81 atol=0.01
13241324
@test sol[model.cyl.phi][end] 1 atol=0.01
13251325

1326+
## =============================================================================
1327+
1328+
@testset "JointUSR_RRR" begin
1329+
@info "Testing JointUSR_RRR"
1330+
include("test_JointUSR_RRR.jl")
1331+
end

test/test_JointUSR_RRR.jl

+32-45
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ using OrdinaryDiffEq
77
using LinearAlgebra
88
using JuliaSimCompiler
99

10-
t = Multibody.t
11-
D = Differential(t)
1210
world = Multibody.world
1311
W(args...; kwargs...) = Multibody.world
12+
t = Multibody.t
13+
D = Differential(t)
1414

15-
# A JointUSR is connected to a prismatic joint, with a Body at their common tip
15+
# ==============================================================================
16+
## A JointUSR is connected to a prismatic joint, with a Body at their common tip
17+
# ==============================================================================
1618
@mtkmodel TestUSR begin
1719
@components begin
1820
world = W()
1921
j1 = JointUSR(positive_branch=true, use_arrays=false)
2022
fixed = FixedTranslation(r=[1,0,0])
21-
b1 = Body(m=1, isroot=false, neg_w=true)
23+
b1 = Body(m=1)
2224
p1 = Prismatic(state_priority=100, n = [1, 0, 0])
2325
end
2426
@equations begin
@@ -40,48 +42,33 @@ sol = solve(prob, FBDF(autodiff=true))
4042
@test sol(1.0, idxs=model.p1.s) -2.8 rtol=0.01 # test vs. OpenModelica
4143

4244

43-
# NOTE: I was working on trying to register the compute_angle function so that there are no symbolic arguments left in the generated code
44-
45-
# foo(x::AbstractArray, p::AbstractArray) = sum(-p .* x .^ 2)
46-
# @register_symbolic foo(x::AbstractArray, p::AbstractArray)
47-
# onetwo = [1, 2]
48-
49-
# @mtkmodel ArrayX begin
50-
# @variables begin
51-
# x(t)[1:2] = ones(2)
52-
# end
53-
# @parameters begin
54-
# p[1:2] = onetwo
55-
# end
56-
# begin
57-
# x = collect(x)
58-
# end
59-
# @equations begin
60-
# D(x[1]) ~ foo(x, p)
61-
# D(x[2]) ~ foo(x, p)
62-
# end
63-
# end
64-
65-
# @named model = ArrayX()
66-
# model = complete(model)
67-
# ssys = structural_simplify(IRSystem(model))
68-
# prob = ODEProblem(ssys, [], (0.0, 1.0))
69-
# sol = solve(prob, FBDF())
7045

46+
# ==============================================================================
47+
## A JointRRR is connected to a prismatic joint, with a Body at their common tip
48+
# ==============================================================================
49+
@mtkmodel TestRRR begin
50+
@components begin
51+
world = W()
52+
j1 = JointRRR(positive_branch=true)
53+
fixed = FixedTranslation(r=[1,0,0])
54+
b1 = Body(m=1)
55+
p1 = Prismatic(state_priority=100, n = [1, 0, 0])
56+
end
57+
@equations begin
58+
connect(world.frame_b, j1.frame_a, fixed.frame_a)
59+
connect(fixed.frame_b, p1.frame_a)
60+
connect(p1.frame_b, j1.frame_b)
61+
connect(j1.frame_im, b1.frame_a)
62+
end
63+
end
7164

72-
# @variables begin
73-
# x(t)[1:2] = 1
74-
# end
75-
# @parameters begin
76-
# p[1:2] = onetwo
77-
# end
78-
# begin
79-
# x = collect(x)
80-
# end
65+
@named model = TestRRR()
66+
model = complete(model)
67+
ssys = structural_simplify(IRSystem(model))
68+
@test length(unknowns(ssys)) == 2
69+
##
8170

82-
# foo(x, p)
83-
# # @equations begin
84-
# # D(x[1]) ~ foo(x, p)[1]
85-
# # D(x[2]) ~ foo(x, p)[2]
86-
# # end
71+
prob = ODEProblem(ssys, [model.p1.v => 0.0], (0.0, 1.4))
72+
sol = solve(prob, FBDF(autodiff=true))
73+
@test sol(1.0, idxs=model.p1.s) -2.8 rtol=0.01 # test vs. OpenModelica
8774

0 commit comments

Comments
 (0)