pantor / ruckig

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

Bug after decreasing maximum velocity #146

Closed cesarmoreno1991 closed 1 year ago

cesarmoreno1991 commented 1 year ago

Hi,

I found a bug if the maximum velocity is decreased. Please find this simple example:

#include <iostream>
#include <ruckig/ruckig.hpp>
using namespace ruckig;
int main() {
    // Create instances: the Ruckig OTG as well as input and output parameters
    const double cycleTime_s = 0.002;
    Ruckig<1> otg {cycleTime_s};  // control cycle
    InputParameter<1> input;
    OutputParameter<1> output;

    // Set input parameters
    input.control_interface = ControlInterface::Position;
    input.current_position = {0.0};
    input.current_velocity = {0.0};
    input.current_acceleration = {0.0};

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

    input.max_velocity = {0.55};
    input.max_acceleration = {1.0};
    input.max_jerk = {2.0};

    // Generate the trajectory within the control loop
    bool velocityChangeDone = false;
    double time_s = 0.0;
    while( otg.update( input, output ) == Result::Working ) {
        auto& p = output.new_position;
        auto& v = output.new_velocity;
        auto& a = output.new_acceleration;
        // Change maximum velocity after 1.5 seconds
        if( !velocityChangeDone && time_s > 1.5 )
    {
            input.max_velocity = {0.10};
            velocityChangeDone = true;
        }

        time_s += cycleTime_s;
        std::cout << time_s << ";" << p[0] << ";" << v[0] << ";" << a[0] << std::endl;

        output.pass_to_input(input);
    }
}

After the velocity change is done, there is a really weird behavior of the system. Could you please check it?

Thanks in advance. Regards, Cesar

fxd0h commented 1 year ago

I'm facing the same problem while trying to use ruckig community ed. for a joystick jogger (servoing) with jerk limited motion. It act weird if the max velocity is decreased. Attached cesar's program output plotted values.

ruckigReport1
pantor commented 1 year ago

This seems in line with the current implementation that Ruckig will brake as fast as possible to stay within the limits.

When reducing max_velocity limit below current_velocity, the trajectory will de-accelerate until the velocity limit is reached exactly, however then it can only ramp-up the acceleration slowly due to the jerk limitation. Therefore, an overshoot in the velocity occurs.

This relates to the soft constraints issue (#45) so that Ruckig will brake to stay on the velocity limit afterwards.