mahaarbo / urdf2casadi

Python library for getting a casadi function for the forward kinematics of a URDF chain
MIT License
95 stars 32 forks source link

Export symbolic expression and integrate into CasADi optimization #11

Closed kunpengyao closed 3 years ago

kunpengyao commented 3 years ago

Hello, thanks for sharing this nice work! I am interested in using this package to solve one problem I am working on. I have following questions: (1) I see that in the example, it is possible to use forward_kinematics([0.3, 0.3, 0.3, 0., 0.3, 0.7]) to evaluate the symbolic form. However, I wonder how can I export the symbolic expression to a local file? I want to perform extra symbolic operation of the expression, for example, calculate the manipulability index, which can be obtained based on the end-effector Jacobian. (2) If there is a way to use any symbolic expression directly in a CasADi optimization problem? For example, using the symbolic expression of the forward kinematic as an objective function, and treat joint angles as variables, to solve a simple IK problem. I could not find any clues in the example. (3) I received information when I load urdf model using robot_parser.from_file(urdf_path): "Unknown tag xx in xx". I think such tags haven't been considered. However, will they by any chance affect the calculation? Many thanks.

mahaarbo commented 3 years ago

Hi, nice that you like the work!

  1. CasADi is an automatic differentiation system, not a symbolic one. As such, the symbolic expression is not simplified, nor easy to use in analytical work, and I don't quite know what you mean by exporting the symbolic expression to a local file. You can generate C-code from a function if that is what you need (see: Generating C-code). Otherwise you can define the manipulability index directly as a function in CasADi and evaluate that.
  2. Sure, that's possible if you mean you want to implement the closed-loop inverse kinematics algorithm in some form. The cost could e.g. be the error between the desired pose and the pose generated by forward_kinematics(q) where q is the symbol for the generalized coordinates of your system.
  3. This is an error in urdfdom/urdf_parser_py, and should not affect the calculation, but feel free to verify by comparing against e.g. an output from PyKDL.
kunpengyao commented 3 years ago

Many thanks for your answer. I think my first question is more related to CasADi instead of this package.