Skip to content

Instantly share code, notes, and snippets.

@rfdickerson
Created February 27, 2021 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfdickerson/44fd0a35292b9c798b26b5458d086f2c to your computer and use it in GitHub Desktop.
Save rfdickerson/44fd0a35292b9c798b26b5458d086f2c to your computer and use it in GitHub Desktop.
ik- newton
@jit
def forward(state):
return forward_ik(state["angles"], state["lengths"])
@jit
def checker(state):
end_location = forward(state)
distance = jnp.linalg.norm(end_location - state["target"])
return distance > 0.00001
@jit
def step(state):
d = forward(state) - state["target"]
J_inv = jnp.linalg.pinv(J(state["angles"], state["lengths"]))
state["angles"] -= jnp.dot(J_inv, d)
state["history"]["iterations"] += 1
return state
def inverse_kinematics(state):
return while_loop(checker, step, state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment