Skip to content

Commit cd5e647

Browse files
committed
Merge branch 'feature_recursive_newton_euler' into dev
2 parents 5b6e6d0 + b923073 commit cd5e647

19 files changed

+585
-263
lines changed

RSONs/rsons/franka_panda/pandaDrill.rson

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"rson_version": "0.1.0",
33
"type": "mechanism",
4-
"name": "panda",
4+
"name": "panda_drill",
55
"frames": [
66
"root_frame",
77
"L1_frame",
@@ -372,49 +372,49 @@
372372
"type": "mesh",
373373
"frame": "root_frame",
374374
"material": "panda_white",
375-
"filename": "./meshes/visual/link0.obj"
375+
"filename": "./meshes/visual/link0.dae"
376376
},
377377
"L1_mesh": {
378378
"type": "mesh",
379379
"frame": "L1_frame",
380380
"material": "panda_white",
381-
"filename": "./meshes/visual/link1.obj"
381+
"filename": "./meshes/visual/link1.dae"
382382
},
383383
"L2_mesh": {
384384
"type": "mesh",
385385
"frame": "L2_frame",
386386
"material": "panda_white",
387-
"filename": "./meshes/visual/link2.obj"
387+
"filename": "./meshes/visual/link2.dae"
388388
},
389389
"L3_mesh": {
390390
"type": "mesh",
391391
"frame": "L3_frame",
392392
"material": "panda_white",
393-
"filename": "./meshes/visual/link3.obj"
393+
"filename": "./meshes/visual/link3.dae"
394394
},
395395
"L4_mesh": {
396396
"type": "mesh",
397397
"frame": "L4_frame",
398398
"material": "panda_white",
399-
"filename": "./meshes/visual/link4.obj"
399+
"filename": "./meshes/visual/link4.dae"
400400
},
401401
"L5_mesh": {
402402
"type": "mesh",
403403
"frame": "L5_frame",
404404
"material": "panda_white",
405-
"filename": "./meshes/visual/link5.obj"
405+
"filename": "./meshes/visual/link5.dae"
406406
},
407407
"L6_mesh": {
408408
"type": "mesh",
409409
"frame": "L6_frame",
410410
"material": "panda_white",
411-
"filename": "./meshes/visual/link6.obj"
411+
"filename": "./meshes/visual/link6.dae"
412412
},
413413
"L7_mesh": {
414414
"type": "mesh",
415415
"frame": "L7_frame",
416416
"material": "panda_white",
417-
"filename": "./meshes/visual/link7.obj"
417+
"filename": "./meshes/visual/link7.dae"
418418
},
419419
"drill_mount": {
420420
"type": "cylinder",

RSONs/rsons/franka_panda/pandaDummyInstrument.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": "panda",
4+
"name": "panda_dummy_instrument",
55
"frames": [
66
"root_frame",
77
"L1_frame",

RSONs/rsons/franka_panda/pandaSurgical.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": "panda",
4+
"name": "panda_surgical",
55
"frames": [
66
"root_frame",
77
"L1_frame",

RSONs/rsons/franka_panda/pandaSurgicalStryker.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": "panda",
4+
"name": "panda_surgical_stryker",
55
"frames": [
66
"root_frame",
77
"L1_frame",

RSONs/rsons/franka_panda/pandaSurgicalV2.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": "panda",
4+
"name": "panda_surgical_v2",
55
"frames": [
66
"root_frame",
77
"L1_frame",

RSONs/rsons/franka_panda/pandaVeterinarian.rson

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"rson_version": "0.1.0",
33
"type": "mechanism",
4-
"name": "panda",
4+
"name": "panda_veterinarian",
55
"frames": [
66
"root_frame",
77
"L1_frame",
@@ -328,49 +328,49 @@
328328
"type": "mesh",
329329
"frame": "root_frame",
330330
"material": "panda_white",
331-
"filename": "./meshes/visual/link0.obj"
331+
"filename": "./meshes/visual/link0.dae"
332332
},
333333
"L1_mesh": {
334334
"type": "mesh",
335335
"frame": "L1_frame",
336336
"material": "panda_white",
337-
"filename": "./meshes/visual/link1.obj"
337+
"filename": "./meshes/visual/link1.dae"
338338
},
339339
"L2_mesh": {
340340
"type": "mesh",
341341
"frame": "L2_frame",
342342
"material": "panda_white",
343-
"filename": "./meshes/visual/link2.obj"
343+
"filename": "./meshes/visual/link2.dae"
344344
},
345345
"L3_mesh": {
346346
"type": "mesh",
347347
"frame": "L3_frame",
348348
"material": "panda_white",
349-
"filename": "./meshes/visual/link3.obj"
349+
"filename": "./meshes/visual/link3.dae"
350350
},
351351
"L4_mesh": {
352352
"type": "mesh",
353353
"frame": "L4_frame",
354354
"material": "panda_white",
355-
"filename": "./meshes/visual/link4.obj"
355+
"filename": "./meshes/visual/link4.dae"
356356
},
357357
"L5_mesh": {
358358
"type": "mesh",
359359
"frame": "L5_frame",
360360
"material": "panda_white",
361-
"filename": "./meshes/visual/link5.obj"
361+
"filename": "./meshes/visual/link5.dae"
362362
},
363363
"L6_mesh": {
364364
"type": "mesh",
365365
"frame": "L6_frame",
366366
"material": "panda_white",
367-
"filename": "./meshes/visual/link6.obj"
367+
"filename": "./meshes/visual/link6.dae"
368368
},
369369
"L7_mesh": {
370370
"type": "mesh",
371371
"frame": "L7_frame",
372372
"material": "panda_white",
373-
"filename": "./meshes/visual/link7.obj"
373+
"filename": "./meshes/visual/link7.dae"
374374
},
375375
"frame": {
376376
"type": "mesh",

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: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,97 @@ using
55
LinearAlgebra,
66
StaticArrays,
77
VMRobotControl
8+
# begin
9+
# X = SVector{3, Float64}(1.0, 0.0, 0.0)
10+
# Y = SVector{3, Float64}(0.0, 1.0, 0.0)
11+
# Z = SVector{3, Float64}(0.0, 0.0, 1.0)
12+
13+
# T1 = zero(Transform{Float64})
14+
# J1 = Revolute(Y, T1)
15+
16+
# T2 = Transform(Z)
17+
# J2 = Revolute(Y, T2)
18+
19+
# T3 = Transform(Z)
20+
# J3 = Rigid(T3)
21+
22+
# mech = Mechanism{Float64}("2Link")
23+
# cart_frame = add_frame!(mech, "Cart")
24+
# L2_frame = add_frame!(mech, "L2")
25+
# EE_frame = add_frame!(mech, "EE")
26+
27+
# add_joint!(mech, J1; parent="root_frame", child=cart_frame, id="J1")
28+
# add_joint!(mech, J2; parent=cart_frame, child=L2_frame, id="J2")
29+
# add_joint!(mech, J3, parent=L2_frame, child=EE_frame; id="J3")
30+
31+
# # Then, we add a coordinate to the mechanism to represent the tip of the pendulum, and a
32+
# # coordinate to represent the position of the cart. These are used to add point masses to
33+
# # the mechanism.
34+
# add_coordinate!(mech, FrameOrigin(EE_frame); id="tip_pos")
35+
# add_coordinate!(mech, FrameOrigin(cart_frame); id="cart_pos")
36+
# add_component!(mech, PointMass(1.0, "cart_pos"); id="cart_mass")
37+
# add_component!(mech, PointMass(1.0, "tip_pos"); id="pendulum_mass")
38+
# m = compile(mech)
39+
# end
40+
41+
# We compile the mechanism, and setup an ODE problem to simulate the dynamics of the rail robot.
42+
# m = compiled_mechanisms[5]
43+
m = compile(parseRSON("./RSONs/rsons/trivial2link.rson"))
44+
cache = Observable(new_inverse_dynamics_cache(m))
45+
# @testset test_inverse_dynamics(m)
846

9-
X = SVector{3, Float64}(1.0, 0.0, 0.0)
10-
Y = SVector{3, Float64}(0.0, 1.0, 0.0)
11-
Z = SVector{3, Float64}(0.0, 0.0, 1.0)
47+
bundle = cache[]
1248

13-
T1 = zero(Transform{Float64})
14-
J1 = Revolute(Y, T1)
49+
begin
1550

16-
T2 = Transform(Z)
17-
J2 = Revolute(Y, T2)
1851

19-
T3 = Transform(Z)
20-
J3 = Rigid(T3)
52+
t = 0.0
53+
q = [0.0, π/2]
54+
= zero_q̇(m)
55+
g = SVector{3, Float64}(0.0, 0.0, 0.0)
2156

22-
mech = Mechanism{Float64}("2Link")
23-
cart_frame = add_frame!(mech, "Cart")
24-
L2_frame = add_frame!(mech, "L2")
25-
EE_frame = add_frame!(mech, "EE")
57+
# rng = MersenneTwister(1234)
58+
# t = 0.0
59+
# q = rand!(rng, zero_q(Float64, m))
60+
# q̇ = rand!(rng, zero_q̇(Float64, m))
61+
# g = randn(rng, SVector{3, Float64})
2662

27-
add_joint!(mech, J1; parent="root_frame", child=cart_frame, id="J1")
28-
add_joint!(mech, J2; parent=cart_frame, child=L2_frame, id="J2")
29-
add_joint!(mech, J3, parent=L2_frame, child=EE_frame; id="J3")
63+
u = zero_u(m)
3064

31-
# Then, we add a coordinate to the mechanism to represent the tip of the pendulum, and a
32-
# coordinate to represent the position of the cart. These are used to add point masses to
33-
# the mechanism.
34-
add_coordinate!(mech, FrameOrigin(EE_frame); id="tip_pos")
35-
add_coordinate!(mech, FrameOrigin(cart_frame); id="cart_pos")
36-
add_component!(mech, PointMass(1.0, "cart_pos"); id="cart_mass")
37-
add_component!(mech, PointMass(1.0, "tip_pos"); id="pendulum_mass")
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̈
3870

39-
# We compile the mechanism, and setup an ODE problem to simulate the dynamics of the rail robot.
40-
m = compile(mech)
41-
cache = Observable(new_inverse_dynamics_cache(m))
4271

72+
VMRobotControl._inverse_dynamics_set_inputs!(bundle, t, q, q̇, q̈, g)
73+
VMRobotControl._inverse_dynamics_forward_pass!(bundle)
74+
VMRobotControl._inverse_dynamics_zero!(bundle)
75+
VMRobotControl._inverse_dynamics_backward_pass_a!(bundle)
76+
VMRobotControl._inverse_dynamics_backward_pass_b!(bundle)
77+
# VMRobotControl._inverse_dynamics_backward_pass_c!(bundle)
78+
# VMRobotControl._inverse_dynamics_backward_pass_d!(bundle)
4379

44-
begin
45-
t = 0.0
46-
q = [0.0, π/2]
47-
= zero_q̇(m)
48-
= zero_q̈(m)
49-
g = SVector{3, Float64}(0.0, 0.0, -9.81)
50-
inverse_dynamics!(cache[], t, q, q̇, q̈, g)
80+
# @show get_u(bundle)
81+
82+
# @show inverse_dynamics!(bundle, t, q, zero_q̇(m), onehot_q̈, 0*g)
5183

84+
# _test_RNE_inertance_matrix(bundle, dcache, t, q)
85+
86+
# q̈_out = dynamics!(dcache, t, q, q̇, g, get_u(bundle))
87+
88+
# @test get_u(cache[]) ≈ u atol=1e-7 rtol=1e-7
89+
# @test q̈ ≈ q̈_out atol=1e-7 rtol=1e-7
90+
end
91+
92+
93+
begin
5294
fig = Figure()
5395
display(fig)
5496
ls = LScene(fig[1, 1]; show_axis=false)
55-
robotsketch!(ls, cache; linewidth=3)
97+
robotsketch!(ls, cache; linewidth=3, scale=0.05)
98+
robotvisualize!(ls, cache)
5699

57100
frameIDs = get_compiled_frameID.((cache[],), frames(cache[]))
58101
tfs = map(cache) do cache
@@ -65,20 +108,24 @@ fs = map(cache) do cache
65108
fs = map(id -> VMRobotControl.get_frame_force(cache, id), frameIDs)
66109
end
67110
f_scale = map(fs) do fs
68-
0.1/norm(maximum(fs))
111+
0.2/maximum(norm(fs))
69112
end
70113
τs = map(cache) do cache
71114
map(id -> VMRobotControl.get_frame_torque(cache, id), frameIDs)
72115
end
116+
τ_scale = map(τs) do τs
117+
0.4/maximum(norm(τs))
118+
end
119+
73120

74-
arrows!(ls, positions, fs; lengthscale=f_scale, arrowsize=0.1, color=:red, )
75-
arrows!(ls, positions, τs; lengthscale=f_scale, arrowsize=0.1, color=:red, )
121+
arrows!(ls, positions, fs; lengthscale=f_scale, arrowsize=map(f->*(f, 50), f_scale), color=:red, )
122+
arrows!(ls, positions, τs; lengthscale=τ_scale, arrowsize=0.04, color=:blue, )
76123

77124

78125
end
79126

80-
using Test, Random
81-
Revise.includet("../test/inverse_dynamics_test.jl")
127+
# using Test, Random
128+
# Revise.includet("../test/inverse_dynamics_test.jl")
82129
@testset test_inverse_dynamics(m)
83130

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

ext/VMRobotControlMakieExt.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ function _sketchjoint!(ax, joint::RailData, cache::Observable;
298298
(s,)
299299
end
300300

301+
function _sketchjoint!(ax, joint::ReferenceJoint, cache::Observable;
302+
scale, meshcolor, linecolor, linewidth, shading)
303+
# TODO implement
304+
()
305+
end
306+
307+
301308
################################################################################
302309
# Component Sketch
303310
################################################################################

src/components/components.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,8 @@ Add opspace force `f` to the cache for coordinate `c`.
359359
@inline function _add_opspace_force!(bundle::CacheBundle, c::C) where C<:ComponentData
360360
@assert hasfield(C, :coord) "Component '$c' does not have a field 'coord'. If this is a valid component, please implement `_add_opspace_force!` for it."
361361
f::SVector = opspace_force(bundle, c)
362-
coord_id = c.coord
363-
coord = bundle[coord_id]
364-
f_cache_view(bundle, coord) .-= f # f is negated, due to the definition of bias forces. e.g. If a spring opspace force is Kz
365-
nothing
362+
f_view = f_cache_view(bundle, bundle[c.coord])
363+
f_view .-= f # f is negated, due to the definition of bias forces. e.g. If a spring opspace force is Kz
366364
end
367365

368366
function _opspace_force(cache::CacheBundle, c::ComponentData)

0 commit comments

Comments
 (0)