xfrc_applied attribute seems unwrittable externally?

Discussion in 'Simulation' started by Jiali, Dec 8, 2018.

  1. Hi,

    The goal is to apply force to object of interest. I noticed that some modified xfrc_applied attribute to do this.
    However, when I do so explicitly and print it out, it's not changing at all. (always printing out [0.,0.,0.,0.,0.,0]), but I modify the first to be 10. as below.

    for i in range(10000):
    ac.pro=env.action_space.sample()
    ac.adv=env.adv_action_space.sample()
    if(i %20==0):
    i=0
    print('high', env.adv_action_space.high)
    idx=env._adv_bindex
    print('adv_index', idx)
    print('xfrc_applied', env.sim.data.xfrc_applied[idx])
    env.sim.data.xfrc_applied[idx] = np.array([10, 0, 0, 0.0, 0.0, 0.0])

    env.step(ac)
    env.render()

    So, it's not right to apply force through modifying xfrc_applied, correct?
    I tried another approach, which is to translate simulate.cpp into mujoco_py's (1.5.0) mjSim.pyx and mjrendercontext.pyx as well as mjviewer.py. This way, I achieved similar effect as simulate.cpp. When I used the above code, I realized it's only when I applied force with ctrl+right mouse, the xfrc_applied printed out will be changed.

    My question is, if I want to apply force through code, rather than with human interface (as shown in simulate.cpp), what's the right way to do (it seems modify xfrc_applied alone is wrong)?

    Thanks!
     
    Last edited: Dec 8, 2018