You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From some earlier experiments its pretty straightforward to install mjcb's:
using MuJoCo
using MuJoCo.MJCore
functioncb1(pm::Ptr{mjModel}, pd::Ptr{mjData})
d = Base.unsafe_load(pd)
println(d.time)
nothingendfunctioncb2(m::mjModel, d::mjData)
println(d.time)
nothingendstruct mjfGeneric
jm::jlModel
jd::jlDataendfunction (cb::mjfGeneric)(m::Ptr{mjModel}, d::Ptr{mjData})
println(cb.jd.cptr == d)
nothingendfunctiontest1()
MJCore.mjcb_control[] =C_NULL
m =jlModel(MuJoCo.TESTMODELXML)
d =jlData(m)
mp = m.cptr
dp = d.cptr
f =@cfunction cb1 Cvoid (Ptr{mjModel}, Ptr{mjData})
MJCore.mjcb_control[] = f
mj_step(mp, dp)
mj_step(mp, dp)
mj_step(mp, dp)
endfunctiontest2()
MJCore.mjcb_control[] =C_NULL
m =jlModel(MuJoCo.TESTMODELXML)
d =jlData(m)
mp = m.cptr
dp = d.cptr
f =@cfunction cb2 Cvoid (Ref{mjModel}, Ref{mjData})
MJCore.mjcb_control[] = f
mj_step(mp, dp)
mj_step(mp, dp)
mj_step(mp, dp)
endfunctiontest3()
MJCore.mjcb_control[] =C_NULL
m =jlModel(MuJoCo.TESTMODELXML)
d =jlData(m)
mp = m.cptr
dp = d.cptr
cb =mjfGeneric(m, d)
f =@cfunction$cb Cvoid (Ptr{mjModel}, Ptr{mjData})
MJCore.mjcb_control[] = f
mj_step(mp, dp)
mj_step(mp, dp)
mj_step(mp, dp)
end
test3 is the most useful since it provides access to the underlying jlModel/jlData, but is a little funky because we install a global callback that's bound to single instances to jlModel/jlData. This would break parallel computation.
As far as I can see, full support would require redesigning/getting rid of jlModel/jlData so that the pointers to mjModel and mjData are manipulated directly. CBindings.jl and Blobs.jl may be useful.
The only reason the jl types are needed is to wrap Ptr fields/arrays, which requires knowing the size. You could shove all the size information into the type definition for the mj types like:
struct mjData{nq, nv, ...}
# ...end
which I've tested and works, but seems like an abuse of the type system?
The text was updated successfully, but these errors were encountered:
From some earlier experiments its pretty straightforward to install mjcb's:
test3
is the most useful since it provides access to the underlyingjlModel
/jlData
, but is a little funky because we install a global callback that's bound to single instances tojlModel
/jlData
. This would break parallel computation.As far as I can see, full support would require redesigning/getting rid of
jlModel
/jlData
so that the pointers tomjModel
andmjData
are manipulated directly. CBindings.jl and Blobs.jl may be useful.The only reason the
jl
types are needed is to wrapPtr
fields/arrays, which requires knowing the size. You could shove all the size information into the type definition for themj
types like:which I've tested and works, but seems like an abuse of the type system?
The text was updated successfully, but these errors were encountered: