Skip to content

Commit 65a64db

Browse files
committed
Partially successful tests for frame angular velocity in RNE tests
1 parent 651d894 commit 65a64db

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

src/coordinates/coordinate_implementations.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ _velocity(cache::CacheBundle, c::CMC{<:FrameAngularVelocity}) = get_angular_vel(
489489
_jacobian(cache::CacheBundle, c::CMC{<:FrameAngularVelocity}) = J_cache_view(cache, c)
490490
_acceleration(cache::CacheBundle, c::CMC{<:FrameAngularVelocity}) = _get_angular_acc(cache, c.coord_data.frameID)
491491

492+
function __propagate_opspace_force!(cache::CacheBundle, mc::CMC{<:FrameAngularVelocity})
493+
c = mc.coord_data
494+
f_view = f_cache_view(cache, mc)
495+
@assert length(f_view) == 3
496+
f = f_cache_view(cache, mc)[SVector(1, 2, 3)] # Get the force applied to the coord as an SVector
497+
fID = c.frameID
498+
get_frame_torques(cache)[fID] += f
499+
nothing
500+
end
501+
502+
492503
####################################################################################################
493504
# CoordNorm
494505
####################################################################################################

src/interface.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,20 @@ function _inverse_dynamics!(bundle::MechRNEBundle)
505505
# Backward pass
506506
foreach(get_force_components(m)) do component # add forces for each component to coordinates
507507
_add_opspace_force!(bundle, component)
508-
@show f_cache_view(bundle, m[component.coord])
508+
# @show f_cache_view(bundle, m[component.coord])
509509
end
510-
@show frame_forces
511-
println("Backward pass part 1")
510+
# @show frame_forces
511+
# println("Backward pass part 1")
512512
compute_in_reverse_coordinate_order(coordinates(m)) do coord # propagate forces through coordinates
513513
__propagate_opspace_force!(bundle, coord)
514-
@show frame_forces
514+
# @show frame_forces
515515
end
516-
println("Backward pass part 2")
516+
# println("Backward pass part 2")
517517
for (parent, child) in Iterators.reverse(m.rbtree.walk) # propagate forces through frames/joints
518518
frame_forces[parent] += frame_forces[child]
519519
δ = origin(get_transform(cache, CompiledFrameID(parent))) - origin(get_transform(cache, CompiledFrameID(child)))
520520
frame_torques[parent] += frame_torques[child] - cross(δ, frame_forces[child])
521-
@show frame_forces
521+
# @show frame_forces
522522
end
523523
# Project forces to joints
524524
foreach(joints(m)) do joint

test/inverse_dynamics_test.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
function test_inverse_dynamics(m)
1+
function test_inverse_dynamics(m; N=20)
22
rng = MersenneTwister(1234)
33

4-
# q = rand!(rng, zero_q(Float64, m))
5-
# q̇ = rand!(rng, zero_q̇(Float64, m))
6-
# u = rand!(rng, zero_u(Float64, m))
7-
# u = zero_u(Float64, m)
8-
q = [0., π/2]
9-
= [0., 0.]
10-
u = [1., 0.]
11-
time = 0.0 # Time is irrelevant to these tests as no `TimeFuncJoint`s
12-
gravity = SVector(0.0, 0.0, -10.)
4+
for i = 1:N
5+
t = 0.0
6+
q = rand!(rng, zero_q(Float64, m))
7+
= rand!(rng, zero_q̇(Float64, m))
8+
gravity = randn(rng, SVector{3, Float64})
9+
_test_inverse_dynamics(m, t, q, q̇, gravity)
10+
end
11+
end
12+
13+
function _test_inverse_dynamics(m, time, q, q̇, gravity)
14+
u = zero_u(Float64, m)
1315

1416
icache = new_inverse_dynamics_cache(m)
1517
dcache = new_dynamics_cache(m)
@@ -18,8 +20,8 @@ function test_inverse_dynamics(m)
1820
= get_q̈(dcache)
1921
inverse_dynamics!(icache, time, q, q̇, q̈, gravity)
2022

21-
@show get_u(icache)
22-
@show u
23+
# u is the control input used to compute forward dynamics, and is correct
24+
# get_u(icache) is the result of the inverse dynamics computation, and should be equal to u
2325
@test get_u(icache) u atol=1e-7 rtol=1e-7
2426

2527
# @show icache.cache.frame_cache.forces[6] - icache.cache.frame_cache.rbstates[6].acceleration.linear

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ results = @testset "All tests" begin
143143
results = @testset "Velocity Kinematics AD" test_on_mechanisms(test_velocity_kinematics_vs_autodiff, small_immut_mechanisms);
144144
results = @testset "Coordinate tests" test_on_mechanisms(test_coordinates, compiled_systems);
145145
results = @testset "Dynamics tests" test_on_mechanisms(test_dynamics, systems_with_inertances);
146-
# results = @testset "Inverse Dynamics tests" test_on_mechanisms(test_inverse_dynamics, compiled_mechanisms); # TODO
146+
results = @testset "Inverse Dynamics tests" test_on_mechanisms(test_inverse_dynamics, compiled_mechanisms); # TODO
147147
results = @testset "Energy tests" test_on_mechanisms(test_energy, systems_with_inertances);
148148
results = @testset "RSON tests" test_on_mechanisms(test_rson, systems);
149149
# TODO ForwardDiff compat tests

0 commit comments

Comments
 (0)