Skip to content

Commit 45edc91

Browse files
committed
Fixed RNE_inertance_matrix by considering only inertance components.
1 parent af3a612 commit 45edc91

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

RSONs/rsons/trivial2link.rson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"rson_version": "0.1.0",
33
"type": "mechanism",
4-
"name": "robot2L",
4+
"name": "trivial2link",
55
"frames": [
66
"root_frame",
77
"L1_frame",

examples/rne_visualization.jl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ using
3939
# end
4040

4141
# We compile the mechanism, and setup an ODE problem to simulate the dynamics of the rail robot.
42-
m = compiled_mechanisms[end]
42+
# m = compiled_mechanisms[5]
43+
m = compile(parseRSON("./RSONs/rsons/trivial2link.rson"))
4344
cache = Observable(new_inverse_dynamics_cache(m))
4445
# @testset test_inverse_dynamics(m)
4546

@@ -50,9 +51,8 @@ begin
5051

5152
t = 0.0
5253
q = [0.0, π/2]
53-
q = zero_q(m) + randn(7)
54-
= zero_q̇(m) + randn(7)
55-
g = SVector{3, Float64}(0.0, 0.0, -10) #+ rand(SVector{3, Float64})
54+
= zero_q̇(m)
55+
g = SVector{3, Float64}(0.0, 0.0, 0.0)
5656

5757
# rng = MersenneTwister(1234)
5858
# t = 0.0
@@ -62,21 +62,30 @@ g = SVector{3, Float64}(0.0, 0.0, -10) #+ rand(SVector{3, Float64})
6262

6363
u = zero_u(m)
6464

65-
dcache = new_dynamics_cache(m)
66-
dynamics!(dcache, t, q, q̇, g, u)
67-
= get_q̈(dcache)
65+
# dcache = new_dynamics_cache(m)
66+
# dynamics!(dcache, t, q, q̇, g, u)
67+
# q̈ = get_q̈(dcache)
68+
onehot_q̈ = [1.0, 0.0]
69+
= onehot_q̈
70+
6871

6972
VMRobotControl._inverse_dynamics_set_inputs!(bundle, t, q, q̇, q̈, g)
7073
VMRobotControl._inverse_dynamics_forward_pass!(bundle)
7174
VMRobotControl._inverse_dynamics_zero!(bundle)
7275
VMRobotControl._inverse_dynamics_backward_pass_a!(bundle)
7376
VMRobotControl._inverse_dynamics_backward_pass_b!(bundle)
74-
VMRobotControl._inverse_dynamics_backward_pass_c!(bundle)
75-
VMRobotControl._inverse_dynamics_backward_pass_d!(bundle)
77+
# VMRobotControl._inverse_dynamics_backward_pass_c!(bundle)
78+
# VMRobotControl._inverse_dynamics_backward_pass_d!(bundle)
79+
80+
# @show get_u(bundle)
81+
82+
# @show inverse_dynamics!(bundle, t, q, zero_q̇(m), onehot_q̈, 0*g)
83+
84+
# _test_RNE_inertance_matrix(bundle, dcache, t, q)
7685

7786
# q̈_out = dynamics!(dcache, t, q, q̇, g, get_u(bundle))
7887

79-
@test get_u(cache[]) u atol=1e-7 rtol=1e-7
88+
# @test get_u(cache[]) ≈ u atol=1e-7 rtol=1e-7
8089
# @test q̈ ≈ q̈_out atol=1e-7 rtol=1e-7
8190
end
8291

@@ -86,6 +95,7 @@ fig = Figure()
8695
display(fig)
8796
ls = LScene(fig[1, 1]; show_axis=false)
8897
robotsketch!(ls, cache; linewidth=3, scale=0.05)
98+
robotvisualize!(ls, cache)
8999

90100
frameIDs = get_compiled_frameID.((cache[],), frames(cache[]))
91101
tfs = map(cache) do cache
@@ -114,8 +124,8 @@ arrows!(ls, positions, τs; lengthscale=τ_scale, arrowsize=0.04, color=:blue, )
114124

115125
end
116126

117-
using Test, Random
118-
Revise.includet("../test/inverse_dynamics_test.jl")
127+
# using Test, Random
128+
# Revise.includet("../test/inverse_dynamics_test.jl")
119129
@testset test_inverse_dynamics(m)
120130

121131
# function create_rotated_cylinder_mesh(N1, N2, r1, r2, ϕ)

src/interface.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,22 @@ function _RNE_inertance_matrix!(M::Matrix, bundle::MechRNEBundle, t, q)
585585
# Set acceleration for one joint
586586
fill!(q̈, zero(eltype(q̈)))
587587
q̈[j] = 1.0
588-
# Compute inverse dynamics
589-
u = inverse_dynamics!(bundle, t, q, q̇, q̈, g)
588+
# Compute inverse dynamics, on inertance/generic components only.
589+
u = begin
590+
_inverse_dynamics_set_inputs!(bundle, t, q, q̇, q̈, g)
591+
_inverse_dynamics_forward_pass!(bundle)
592+
_inverse_dynamics_zero!(bundle)
593+
# WARNING any generic components which applies a force other than due
594+
# to an inertance will break this computation.
595+
inertance_components = get_inertance_components(bundle.mechanism)
596+
foreach(inertance_components) do component
597+
_add_opspace_force!(bundle, component)
598+
end
599+
_inverse_dynamics_backward_pass_b!(bundle)
600+
_inverse_dynamics_backward_pass_c!(bundle)
601+
_inverse_dynamics_backward_pass_d!(bundle)
602+
get_u(bundle)
603+
end
590604
M[:, j] .= u
591605
end
592606
M

0 commit comments

Comments
 (0)