Lyceum / LyceumMuJoCoViz.jl

MIT License
3 stars 0 forks source link

Trajectory/Controller mode doesn't work #27

Open amack315 opened 3 years ago

amack315 commented 3 years ago

I'm trying to run the example from the docs, e.g.:

using LyceumMuJoCo, LyceumMuJoCoViz

env = LyceumMuJoCo.SwimmerV2()
T = 100
states = Array(undef, statespace(env), T)
for t = 1:T
    step!(env)
    states[:, t] .= getstate(env)
end

visualize(
    env,
    trajectories=[states],
    controller = env -> setaction!(env, rand(actionspace(env)))
    )

If I run the above code, it displays a window with swimmer at the center of the screen, with a paused simulation. When I press the space bar, the simulation timer starts running, but the swimmer doesn't move. (Here, I'm using SwimmerV2 instead of HopperV2 to make it obvious what the problem is, since in the absence of any control inputs SwimmerV2 will not move at all. If I try the above with HopperV2, the same problem happens - it simply falls to the ground, and does not appear to be perturbed by any control actions).

At first I thought maybe there was a bug in the example code. For example, if we're modifying the state in realtime based off the output of the controller, why would we have to feed a sequence of states into visualize()? This didn't make logical sense to me, so I also tried running the above code without the trajectories= argument in visualize(), and I get the same issue; swimmer doesn't move.

Finally, I tried running a random controller in pure trajectory mode using the following code:

using LyceumMuJoCo, LyceumMuJoCoViz

env = LyceumMuJoCo.SwimmerV2()
T = 100
states = Array(undef, statespace(env), T)
for t = 1:T
    setaction!(env, rand(actionspace(env))) # use random controller to generate trajectories
    step!(env)
    states[:, t] .= getstate(env)
end

@show states[:,1]
@show states[:,100] # check the controller actually perturbed the state

visualize(
    env,
    trajectories = [states]
    )

Again, I get the same issue; the swimmer doesn't move.

I'm using Julia 1.3.1 and the latest version of the Lyceum packages.

amack315 commented 3 years ago

Actually, I see what's going on. I needed to change the interactive mode in the simulation window to Trajectory or Controller mode by pressing CTRL + right-arrow. Only that keyboard shortcut wasn't working on my mac. But if I change the shortcut in src/defaulthandlers.jl to SHIFT + right-arrow, then I'm able to get the different modes working.

In any case, this could have been more clear in the docs (i.e. change mode with keyboard shortcut in the simulation window).