google / brax

Massively parallel rigidbody physics simulation on accelerator hardware.
Apache License 2.0
2.26k stars 249 forks source link

'Q' object has no attribute 'vel' #243

Closed theorska closed 1 year ago

theorska commented 1 year ago

Hello!

I am looking at a code that was made a couple of years ago, probably in version 0.0.5. Here is the code that I am trying to implement for my case:

    dp_j += env_sys.joint_universal.apply(qp)
    dp_j += env_sys.joint_spherical.apply(qp)
    dp_vel = (env_sys.config.velocity_damping * qp.vel + (
            dp_j.vel + vec_to_np(env_sys.config.gravity))) * env_sys.active_pos
    dp_ang = (env_sys.config.angular_damping * qp.ang + dp_j.ang) * env_sys.active_rot

In this qp is a QP object. In recent versions I believe this would look something like this:

    dp_j = sum([jax.jit(j.apply)(qp) for j in env.sys.joints], q_zero)
    dp_vel = (env.sys.config.velocity_damping * qp.vel + (
            dp_j.vel + vec_to_arr(env.sys.config.gravity))) * env.sys.active_pos
    dp_ang = (env.sys.config.angular_damping * qp.ang + dp_j.ang) * env.sys.active_rot

The code that I am transforming accesses dp_j.vel and dp_j.ang, but dp_j is a Q object which does not have these attributes and the return of joint apply confirms that it is indeed a Q object. Can I ask why was this possible to do in that version of Brax, or what am I missing? How would I get these values in current versions? Maybe something like: env.sys.integrator.update(qp, pos_q=dq_j)?

Thank you for your answer in advance.

btaba commented 1 year ago

Hi @theorska ! I think you want to use the legacy spring joint update by tacking on a dynamics_mode: "legacy_spring" to your brax config. The newer version of brax does a position update for the joint constraint, and the "legacy_spring" does an acceleration level update for the joint constraint See https://github.com/google/brax/blob/main/brax/physics/spring_joints.py#L89 vs https://github.com/google/brax/blob/main/brax/physics/joints.py#L79