Code Monkey home page Code Monkey logo

Comments (1)

cdsousa avatar cdsousa commented on September 11, 2024

Ok, this was simpler than I first thought. In fact the problem is the lack of documentation from my part :)

The function robot_code_to_func second argument must be a tuple of the type (list of intermediate variables, expression). The tuple second element is an expression (or a matrix of expression as it is in the case of the Jacobian), and the first element is a list of intermediate variables for which the expression depends on.

So, if we have no intermediate variables (this is the case), we must pass an empty list; something like ([], expression):

J_str = sympybotics.robotcodegen.robot_code_to_func('python', ([], rbt.kin.J[-1]), 'calc_jac', 'jacobian', rbtdef)

The tuple (list of intermediate variables, expression) has the same structure of the output of the Sympy cse (common subexpression elimination) function. This function detects common subexpressions in expressions and put them as auxiliary intermediate variables. This is something a C compiler will also do (when optimization is turned on) on the generated code, although the Sympy.cse can be slightly better as it has more mathematical knowledge about the expression.

For the dynamic model, the Sympybotics.RobotDynCode high level class uses an internal "iteractive" CSE I designed for the purpose. However, the geometric and kinematic parts has no CSE applied.
For the Jacobian, you can produce faster code by doing

J_code = sympy.cse(rbt.kin.J[-1])
J_str = sympybotics.robotcodegen.robot_code_to_func('python', J_code, 'calc_jac', 'jacobian', rbtdef)

(I have a personal script which generates the code for all the transformation matrices and all the Jacobians of all frames of a given robot as a single function, thus sharing the same common subexpressions in a very optimized way. I may release this code later.)

from sympybotics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.