Code Monkey home page Code Monkey logo

mujoco.jl's Introduction

THIS REPO IS ARCHIVED

Please use https://github.com/Lyceum/MuJoCo.jl for all your MuJoCo needs in Julia. It is nice.

MuJoCo.jl

Julia wrapper for the MuJoCo Physics Engine. This wrapper tries to both keep full access to all MuJoCo functionality through C pointers while also allow faster development through higher level interface.

MuJoCo functions and structs retain their C-library names (e.g. mj_step, mju_copy), while enums are scoped to the module name of mj (e.g. mj.NGROUP, etc). MuJoCo C-library functions can be passed a pointer to the mjModel or mjData structs, or can be passed a convenience wrapper struct of jlModel, jlData.

using MuJoCo

# mj_activate(ENV["MUJOCO_KEY_PATH"]) # this shouldn't be needed as, on load, the module attempts to activate

modelfile = "humanoid.xml"
pm = mj_loadXML(modelfile)  # Raw C pointer to mjModel
pd = mj_makeData(pm)            # Raw C pointer to mjData

mj_step(pm, pd) # At this point you can pass the pointers to mujoco functions

# Access mjModel and mjData structs; this makes a local copy
m = unsafe_load(pm)
println(m.nq, " position elements")
d = unsafe_load(pd)
println(d.qpos, " is a raw pointer still")

Higher level interfacing tries to make it easier to manipulate data in the mjModel and mjData structures through Julia types. We do this by wrapping mjModel & mjData with jlModel and jlData types that expose Vector{Float64} instead of MuJoCo's raw arrays.

m, d = mj.mapmujoco(pm, pd) # wrap with our jlModel, jlData types

# we can manipulate data in the raw C structs now
time = d.d[].time
d.d[].time = 1.0
@assert d.d[].time == 1.0

d.qpos[:] = rand(m.m[].nq) # d.qpos is a jlData Vector; free to access and maps to raw pointer

# functions work on the jlModel and jlData types
mj_step(m, d)
mj_resetData(m, d)

mj_step(m.m, d.d) # our wrapped functions can take in the convenience struct or the Ref pointers

# MuJoCo convenience functions are understood to use 0-based indexing, for now...
id = mj_name2id(m, mj.OBJ_GEOM, "floor") # for humanoid.xml
@assert id == 0

Installation

julia> Pkg.clone("git://www.github.com/klowrey/MuJoCo.jl.git")
julia> Pkg.build("MuJoCo")

MuJoCo v2.00 should be installed automatically through Julia Pkg. You will need a mjkey.txt license file, and your system should set the environment variable "MUJOCO_KEY_PATH" to be the path to your mjkey.txt file.

Currently, this package is less on Windows and OSX.

Examples

Temporary examples can be found in test suite.

Visualization

A version of simulate.cpp has been ported to julia here: https://github.com/klowrey/MujocoSim.jl This allows you to build up the visualization features you need for your experiments, but nominally does passive dynamics.

Todo

Test using @cfunctions to pass Julia code to MuJoCo callback functions Test / contemplate making sure all conversions from 0-based to 1-based indexing is correct? make convert functions that convert enums to Ints or Int32s

mujoco.jl's People

Contributors

klowrey avatar rejuvyesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mujoco.jl's Issues

Demo in README not working

I am on a Mac and MuJoCo by itself and every other part of the demo code in the readme works except these lines of code and their following errors:

mj.set(m, :opt, :timestep, -0.002)

ERROR: MethodError: no method matching update_ptr(::Base.RefValue{mjModel}, ::UInt64, ::Float64)
Closest candidates are:
update_ptr(::Ptr, ::Integer, ::Float64) at /Users/powers/.julia/packages/MuJoCo/GRTFJ/src/mjextra.jl:152
update_ptr(::Ptr, ::Integer, ::Integer) at /Users/powers/.julia/packages/MuJoCo/GRTFJ/src/mjextra.jl:149
update_ptr(::Ptr, ::Integer, ::StaticArrays.SArray{Tuple{S},T,1,S} where T where S) at /Users/powers/.julia/packages/MuJoCo/GRTFJ/src/mjextra.jl:155
Stacktrace:
[1] set(::jlModel, ::Symbol, ::Symbol, ::Float64) at /Users/powers/.julia/packages/MuJoCo/GRTFJ/src/mjextra.jl:204
[2] top-level scope at none:0

m.m[].opt.timestep = 0.002

ERROR: setfield! immutable struct of type mjOption cannot be changed
Stacktrace:
[1] setproperty!(::mjOption, ::Symbol, ::Float64) at ./sysimg.jl:19
[2] top-level scope at none:0

d.qpos[:] = rand(nq)

ERROR: UndefVarError: nq not defined
Stacktrace:
[1] top-level scope at none:0

"using MuJoCo" LoadError: UndefVarError: Cvoid not defined

Hi, I am using MuJoCo in OSX with Julia-v0.6.4. Before it worked well but today after I update the packages with "Pkg.update()", it first has an error with not finding the "Libdl" module. Then I fix it by changing the "using Libdl" to "using Base.Libdl" in the MuJoCo.jl. However, now it has another bug as followed:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.