openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.85k stars 815 forks source link

How to copy value to mjcore.model.body_pos? #19

Open mjm522 opened 7 years ago

mjm522 commented 7 years ago

When I try to copy a value to this variable like this, model.data_pos = newValue it says, ValueError: assignment destination is read-only. So I tried to using the inbuilt function mjlib.mju_copy(data_d.ctypes.data_as(POINTER(c_double)), data_s.ctypes.data_as(POINTER(c_double)), c_int(length)) in the following way. mjlib.mju_copy(model.data_pos.ctypes.data_as(POINTER(c_double)), newValue.ctypes.data_as(POINTER(c_double)), c_int(3)) This statement does not produce any error, nevertheless the value remain unchanged. Could anyone please tell me how to copy a new value to it?

tlbtlbtlb commented 7 years ago

Look for the calls to memmove in mjtypes.py, (most of the mjdata properties have setters that call it) and do something more like that.

aravindsrinivas commented 6 years ago

@tlbtlbtlb Using memmove doesn't work for model.body_pos or model.geom_rgba. It replaces the existing values with random values -1.08420217e-19, 1.82499993e+00, etc instead of the value actually stored in val_ptr.

Is it because these properties were initialized with write=False?

tlbtlbtlb commented 6 years ago

That is likely a mismatch between C float and double types. Make sure you’re passing in the right numpy type, which is float64.

On Sat, Nov 18, 2017 at 14:59 Aravind Srinivas notifications@github.com wrote:

Using memmove doesn't work for model.body_pos or model.geom_rgba. It replaces the existing values with random values -1.08420217e-19, 1.82499993e+00, etc instead of the value actually stored in val_ptr.

Is it because these properties were initialized with write=False?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/openai/mujoco-py/issues/19#issuecomment-345477732, or mute the thread https://github.com/notifications/unsubscribe-auth/AANZdNqrKPqOnf5tTGIRs9uhs1aOMX4wks5s32FTgaJpZM4KVEO7 .

-- Trevor Blackwell tlb@tlb.org 650 776 7870