pantor / ruckig

Motion Generation for Robots and Machines. Real-time. Jerk-constrained. Time-optimal.
https://ruckig.com
MIT License
634 stars 155 forks source link

Wrong independent minimum duration #128

Closed Danielxyz123 closed 2 years ago

Danielxyz123 commented 2 years ago

Hi Pantor,

trajectory reaches the target 1400 at 0.167347 seconds, but i got with "get_independent_min_durations" 0.230593 seconds as result. The correct duration is important for me to control actuators and start the next step of movement.

There is the same fault with DOF > 1... when synchronization ist "None". It happens if the current velocity ist bigger than the max velocity.

Thx a lot


#include <iostream>

#include <ruckig/ruckig.hpp>

using namespace ruckig;

int main() {
    // Create instances: the Ruckig OTG as well as input and output parameters
    Ruckig<1> otg {0.002};  // control cycle
    InputParameter<1> input;
    OutputParameter<1> output;

    // Set input parameters
    input.current_position      = { 1300.0 };
    input.current_velocity      = { 1200.0};
    input.current_acceleration  = { 0.0 };

    input.target_position       = {1400};
    input.target_velocity       = {0.0};
    input.target_acceleration   = {0.0};

    input.max_velocity          = {800};
    input.max_acceleration      = {40000.0};
    input.max_jerk              = {200000.0};

    // Generate the trajectory within the control loop
    std::cout << "t | p1 " << std::endl;
    auto& p = output.new_position;

    while ((otg.update(input, output) == Result::Working) ) {

        std::cout << output.time << " " << p[0] << " " << std::endl;

        output.pass_to_input(input);
    }
    auto mindurations = output.trajectory.get_independent_min_durations();
    std::cout << "Trajectory duration: " << output.trajectory.get_duration() << " [s]." << std::endl;
    std::cout << "Trajectory min duration 0: " << mindurations[0] << " [s]." << std::endl;
}
pantor commented 2 years ago

This should be fixed with the latest commit. There was indeed a bug where the duration of the brake trajectory was added twice to the independent min duration. Thanks for spotting!