Skip to content

Instantly share code, notes, and snippets.

@rejuvyesh
Created October 13, 2018 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rejuvyesh/a69f0add3179aa9b40deb8fab2f4e5e6 to your computer and use it in GitHub Desktop.
Save rejuvyesh/a69f0add3179aa9b40deb8fab2f4e5e6 to your computer and use it in GitHub Desktop.
using MuJoCo
modelfile = "test/humanoid.xml"
pm = mj_loadXML(modelfile) # Raw C pointer to mjModel
pd = mj_makeData(pm) # Raw C pointer to mjData
m, d = mj.mapmujoco(pm, pd) # wrap with our jlModel, jlData types
# we can manipulate data in the raw C structs now
nq = mj.get(m, :nq)
mj.set(m, :nq, -20.0)
@assert mj.get(m, :nq) == -20.0
mj_resetData(m, d)
#=
unknown function (ip: 0x7efe45a8dc3f)
unknown function (ip: 0x7efe2530f066)
mj_resetData at /home/jayeshkg/.julia/dev/MuJoCo/src/mujoco_c.jl:275
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7efe35ff79df)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:813
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:838
jl_load at /buildworker/worker/package_linux64/build/src/toplevel.c:847
include at ./boot.jl:317 [inlined]
include_relative at ./loading.jl:1041
include at ./sysimg.jl:29
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
exec_options at ./client.jl:229
_start at ./client.jl:421
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
unknown function (ip: 0x401ae8)
unknown function (ip: 0x401513)
__libc_start_main at /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
unknown function (ip: 0x4015b4)
Allocations: 8452922 (Pool: 8450575; Big: 2347); GC: 18
zsh: segmentation fault (core dumped) julia test/segfault.jl
=#
@klowrey
Copy link

klowrey commented Oct 14, 2018

:nq is the number of joint positions, so telling the model that there are -20 will cause the program to mess up: it doesn't know how many joints to allocate for the mjData struct.

Only some fields can be changed online in mjModel (such as mjOptions), while most fields in mjData can be changed. Some are still read-only, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment