Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with MX variables #81

Closed
AFusco99 opened this issue Jun 7, 2024 · 8 comments
Closed

Compatibility with MX variables #81

AFusco99 opened this issue Jun 7, 2024 · 8 comments

Comments

@AFusco99
Copy link

AFusco99 commented Jun 7, 2024

Hello,
I wanted to know if you had any suggestion on how to make this library compatible with casadi MX symbolic variables. The joint angles of my manipulator are currently only available in this format and I would like to use your library for the computation of forward and inverse kynematics.
Thank you very much

@DanielePucci
Copy link
Member

CC @Giulero

@Giulero
Copy link
Collaborator

Giulero commented Jun 10, 2024

Hi @AFusco99! Can you provide a snippet of code on how you're using the library? Thanks!

@AFusco99
Copy link
Author

Yes, thanks

import casadi as cs
import numpy as np
model_path = "panda.urdf"
import adam
from adam.casadi import KinDynComputations

joints_name_list = [
           'panda_joint1', 'panda_joint2', 'panda_joint3', 'panda_joint4',
           'panda_joint5', 'panda_joint6', 'panda_joint7'
            ]
joint_angles=cs.MX.sym('q', 7)
root_link = 'panda_link0'
w_H_b = np.eye(4)
 kinDyn = KinDynComputations(model_path, joints_name_list, root_link)
frame="panda_hand"
Tmat=(kinDyn.forward_kinematics(frame,w_H_b,joint_angles))


This code is functional as long as joint_angles is defined as an SX symbolic variable however in my case I need to define it as an MX symbolic variable as I am using external functions and CasADI only supports MX variables in these cases.

@Giulero
Copy link
Collaborator

Giulero commented Jun 10, 2024

Got it! It shouldn't be possible to convert SX to MX and vice-versa (it seems open casadi/casadi#1870).

I created a branch with some modifications in order to let adam accept also MX types.

I opened this PR: #84. You might test changing the branch!

@Giulero
Copy link
Collaborator

Giulero commented Jun 11, 2024

Fyi: PR #84 merged

@Giulero
Copy link
Collaborator

Giulero commented Jun 17, 2024

Hi @AFusco99 ! I just noticed that you are using the forward_kinematics function.

I guess also that you could use the function forward_kinematics_fun function. This function returns the casadi function directly, and it should be possible to use it with SX, MX and DM (and numpy).

Your snippet would become

import casadi as cs
import numpy as np
model_path = "panda.urdf"
import adam
from adam.casadi import KinDynComputations

joints_name_list = [
           'panda_joint1', 'panda_joint2', 'panda_joint3', 'panda_joint4',
           'panda_joint5', 'panda_joint6', 'panda_joint7'
            ]
joint_angles=cs.MX.sym('q', 7)
root_link = 'panda_link0'
w_H_b = np.eye(4)
 kinDyn = KinDynComputations(model_path, joints_name_list, root_link)
frame="panda_hand"
T_mat_fun = kinDyn.forward_kinematics_fun(frame)
Tmat=T_mat_fun(w_H_b,joint_angles)

@Giulero
Copy link
Collaborator

Giulero commented Jun 25, 2024

@AFusco99, please have a look at #89. Anyway, using the *fun version of the function, you should be able to use MX!

@AFusco99
Copy link
Author

Thank you I just tested both options and I was able to work with Mx variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants