Skip to content

Potentially naive question: are collision callbacks a thing/possible in brax? #492

Answered by erikfrey
guydav asked this question in Q&A
Discussion options

You must be logged in to vote

We don't offer explicit hooks, but we have designed the API to be easily decomposable to inject your own physics if you wish.

Consider your use case, adding an external force. You could take MJX's forward function and add some extra forces after detecting contacts:

def my_cool_forward(m: Model, d: Data) -> Data:
  """My cool forward dynamics that adds extra forces to contact."""
  d = fwd_position(m, d)
  # add forces based on contacts
  d = d.replace(xfrc_applied=sum_contacts_to_body(d, force=0.1))
  d = fwd_velocity(m, d)
  d = fwd_actuation(m, d)
  d = fwd_acceleration(m, d)

  if d.efc_J.size == 0:
    d = d.replace(qacc=d.qacc_smooth)
    return d

  d = named_scope(solver.solve)(m, d)…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@guydav
Comment options

@erikfrey
Comment options

@guydav
Comment options

Answer selected by guydav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants