Giter Club home page Giter Club logo

struckig's Introduction

Struckig

Instantaneous Motion Generation for Robots and Machines.
Port of ruckig to Structured Text, TwinCAT 3.

Build/Test Documentation Issues Releases GPLv3

This repository ports pantor/ruckig to Structured Text to bring open-source powered Online-Trajectory-Generation to TwinCAT 3. Only the Community Version of Ruckig is ported and pro features are not available. Struckig itself is dual licenced, you can use the source code provided here accordingly to GPLv3. If you want to use this commercially and not disclose your own source code, Struckig is also available with a custom licence. In the latter case, contact me.

Porting progress and learnings

This project started on June 14, 2021 and I am happy to say that after 3 years of working on this project, it finally catched up to the HEAD of the C++ counterpart on May 15, 2024.

In hindsight, the hardest parts of the port were

  • Porting mathematical functions from C++ to Structured Text such that the same accuracy is achieved: Functions like cbrt are not available in Structured Text out-of-the-box and the functionality had to be ported in a way that calculation have the exact same value in the port as C++ compilers do it.
  • Exception handling: While C++ allows control over how div0 exceptions are handled, this is not possible in Structured Text. While ruckig can just ignore div0 exceptions and then throw away calculations yielding NaN durations, this is not possible in Structured Text. This means that every calculation, which might produce a div0 exception have to be handled.

The original project, ruckig is a submodule of this repository and the hashes in "ported" commits reflect the state of the port. Future commits in the will be continuously ported over to Struckig when time sees fit.

Continuous integration & Documentation

This project is using zkbuild for continuous integration and zkdoc for generating the documentation. To run the tests manually, get a copy of TcUnit and activate the testing solution test\Struckig\Struckig_unittest.sln

Example: Create time-based profile for 1 axis

This examples shows how to create a single-axis trajectory from point A=0mm to point B=100mm. The initial state assumes that the trajectory is in stillstand and target velocity and acceleration is set to 0. The MinDuration parameter is set to 10s. Please not that MaxVelocity, MaxAcceleration and MaxJerk would allow for a shorter travel time, but if MinDuration together with Synchronization = SynchronizationType.TimeSync is set, the MinDuration parameter is considered instead.

If you only want to have a acceleration-constrained trajectory, you can also omit the MaxJerk as well as the CurrentAcceleration and TargetAcceleration value.

PROGRAM Example
VAR
  otg : Struckig.Otg(cycletime:=0.001, dofs:=1) := (
    EnableAutoPropagate := TRUE, //< Automatically copies the new trajectory state to the current trajectory state with every otg() call
    Synchronization :=     SynchronizationType.TimeSync, //< Set to TimeSync, otherwise MinDuration is ignored
    MinDuration :=         10.0, //< if MinDuration > 0 and Synchronization is set to TimeSync this sets the duration of the trajectory (if the other limitations would yields a shorter duration)
    MaxVelocity :=         [ 2000.0 ],
    MaxAcceleration :=     [ 20000.0 ],
    MaxJerk :=             [ 800000.0 ],
    CurrentPosition :=     [ 0.0 ],
    CurrentVelocity :=     [ 0.0 ],
    CurrentAcceleration := [ 0.0 ],
    TargetPosition :=      [ 100.0 ],
    TargetVelocity :=      [ 0.0 ],
    TargetAcceleration :=  [ 0.0 ]
  );
END_VAR

// =====================================================================================================================

otg();
// axis.SetTargetPosition(otg.NewPosition[0]); send the new position to your axis, which should be in a cyclic position mode
// axis.SetVelocityOffset(otg.NewVelocity[0]); send the new velocity to your axis, e.g. with a velocity feedforward
// axis.SetTorqueOffset( accelerationTorqueFactor * otg.NewAcceleration[0]) send the new acceleration to your acces, e.g. with a current feedforward

image

Note: Struckig supports motions with multiple degree of freedoms with the Otg function block. If you need to use only 1 degree of freedom you can also utilize the specialized function block Otg1. The latter function block uses single variables instead of arrays, which simplifies the usage a bit.

struckig's People

Contributors

stefanbesler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

struckig's Issues

Division by zero problem

I tried the code on TwinCAT3 and found the PLC will run into fault because the denominator is zero (3 places as shown in the following figure). I am wondering how to fix it?

image

image

image

Also the sqrt of a negative number will occasionally happen:
image

Refactor / cleanup implementation

  • Do a better job at separating user api and internals. At the moment almost everything is publicly accessible.
  • Check for byval parameters
  • Remove temporary variables in favor of instance variables (only after #9 to have a comparison)
  • Unify naming conventions such that merging from upstream is easy, but doesn’t clash too much with (my) structured-text conventions
  • Remove static classes with member variables (e.g. Roots) in favour of actual static classes without members of traditional function blocks. The code has to be thread-safe.

Some help would be appreciated

Hey @pantor,

I am making good progress for trajectories with 1 dof with the port, but I have issues with some test cases.
When calculating a trajectory for

(p0=0; v0=0; a0=0) to (pf=0.1,vf=0,af=0) with (v_max=2000, a_max=20000, j_max=200000)

I don't get any solution for trajectories like this, but my expections are the either a_max or j_max have to be significantly reduced. However, ruckig doesn't seem to take care of something like this?

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.