pantor / ruckig

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

Without jerk limits, `validate_input()` prints nothing yet returns false. Ruckig `update()` fails. #200

Open AndyZe opened 1 month ago

AndyZe commented 1 month ago

Ruckig works great for me when jerk limits are present. However I see weird behavior when no jerk limit / current acceleration / target acceleration is specified. Here's the state of the system. Seems fine as far as I can tell. All joint positions are valid.

[component_container_mt-5] [ERROR] [1723213314.987161591] [moveit_servo_demo_container.moveit.core.ruckig_filter_plugin]: Ruckig jerk-limited smoothing failed with code: -100
[component_container_mt-5] [INFO] [1723213314.987237738] [moveit_servo_demo_container.moveit.core.ruckig_filter_plugin]: 0.01
[component_container_mt-5] Ruckig input:
[component_container_mt-5] 
[component_container_mt-5] inp.current_position = [0, -0.785, 0, -2.356, 0, 1.571, 0.785]
[component_container_mt-5] inp.current_velocity = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] inp.current_acceleration = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] inp.target_position = [6.299675467958987e-14, -0.7692521485658494, -1.22995790864666e-13, -2.346922384414514, 2.207760663970184e-14, 1.577670235848665, 0.7850000000000851]
[component_container_mt-5] inp.target_velocity = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] inp.target_acceleration = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] inp.max_velocity = [2.175, 2.175, 2.175, 2.175, 2.61, 2.61, 2.61]
[component_container_mt-5] inp.max_acceleration = [15, 7.5, 10, 12.5, 15, 20, 20]
[component_container_mt-5] inp.max_jerk = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] 
[component_container_mt-5] Ruckig output:
[component_container_mt-5] 
[component_container_mt-5] out.new_position = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] out.new_velocity = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] out.new_acceleration = [0, 0, 0, 0, 0, 0, 0]
[component_container_mt-5] out.time = [0]
[component_container_mt-5] out.calculation_duration = [5.384967072957742e-310]

When I try to run validateInput() the results are a little strange. Try/catch does not print anything! Did I use this correctly?

  try
  {
    ruckig_->validate_input(*ruckig_input_, true, true);
  }
  catch (const std::runtime_error& error)
  {
    // This does not print
    RCLCPP_ERROR_STREAM(getLogger(), "Invalid Ruckig input. " << error.what() << std::endl);
  }

There is a false boolean returned, but that doesn't give me much info to debug:

  if (!ruckig_->validate_input(*ruckig_input_, true, true))
  {
    std::cerr << "Invalid input!" << std::endl;
  }

This is for a MoveIt2 PR btw.

pantor commented 1 month ago

Two quick responses:

  1. There is a RuckigError exception type that you need to catch.
  2. Do you mean to have all zero jerk, or do you want to have infinite jerk limits?
AndyZe commented 1 month ago
2. Do you mean to have all zero jerk, or do you want to have infinite jerk limits?

I'm trying to do what's mentioned in the README:

If you only want to have a acceleration-constrained trajectory, you can also omit the max_jerk as well as the current and target_acceleration value.

Not clear if that means I need to clear the vectors (current accel, target accel, max jerk) or just leave them as they were initialized. Doesn't seem to work either way.

Good point though, I could fill max_jerk with DBL_MAX and effectively get the same thing.

AndyZe commented 1 month ago
1. There is a `RuckigError` exception type that you need to catch.

Doesn't compile!

catch (const ruckig::RuckigError& error) --> error: expected unqualified-id before ‘&’ token

catch (ruckig::RuckigError error) --> error: ‘RuckigError’ in namespace ‘ruckig’ does not name a type; did you mean ‘RuckigThrow’?

I've included the header file #include <ruckig/ruckig.hpp> which includes ruckig/error.hpp

pantor commented 1 month ago

The input parameters are initialized with infinite max jerk and max acceleration - omitting means that you can just leave them as they are. Filling the max limits with DBL_MAX wouldn't work due to numerical issues stated in the Readme.

Not sure about the RuckigError include error. It seems that your compiler is not picking up the error class at all. Are you certain that ruckig/error.hpp is included?

Are you using the most recent Ruckig version?