kuka_experimental icon indicating copy to clipboard operation
kuka_experimental copied to clipboard

Command gear torque A3/A2 error when using kuka_rsi_hw_interface

Open RhysMcK opened this issue 6 years ago • 40 comments

KUKA System:

Controller- KRC4 compact Robot- Kr3-540 Agilus

Environment

ROS Distro: Kinetic Moveit

Problem

Hi all, I have been struggling with this issue for a while now. While controlling the kuka robot through the RSI hardware interface , every now and again i will receive a command gear torque error, typically for axis A3 or A2. This is an issue which has been reported before (https://github.com/ros-industrial/kuka_experimental/issues/89) however none of the comments have solved the problem for me personally. I don't believe this to be a communication issue, as this happens when i have not lost any communication packets ( according to the kuka RSI monitor). I have played with the HOLD_ON parameter and that does not seem to make any difference.

A possible suggestion which was bought up in https://github.com/ros-industrial/kuka_experimental/issues/89 was the tool load data not being set correctly. It is possible that this could be the cause, as i must admit i have not set the payload 100% accurately ( due to not having any cad program currently available to me). I have however entered the mass and estimated the location of CoM and moment of inertia's. However, the reason i don't believe this to be at fault is that i have played with big and small values for the mass/ inertias and have seen no difference in the behavior. I would have thought that setting values significantly far away from the true values would cause this error to happen instantly or more frequently. To me it doesn't seem as if this data has any effect. But i could be very wrong.

A more likely possibility in my opinion is that the motion plans from moveit are not abiding by the acceleration limits, as previously mention in https://github.com/ros-planning/moveit/issues/416. I will try and get some trajectory plots in the next day or so but in the mean time i just wanted to get this discussion going again and see if people had any other insights into this issue.

Cheers!

RhysMcK avatar Apr 17 '18 06:04 RhysMcK

Update: This issue persists after i have physically removed the tool from the robot arm. Which surely must indicate that this is not an issue with inaccurate tool load data.

RhysMcK avatar Apr 18 '18 01:04 RhysMcK

I have had a chance to do some further testing on this issue. It seems the problem is most likely to do with the trajectories that are being sent to the KUKA robot. I recorded all of the position commands that were being set from within the KukaHardwareInterface::write function. From this data i was then able to extrapolate the commanding velocities by taking the difference between the last two commanding positions and assuming cycle time of 12ms. From the figures below, it can be seen that just before i receive this error on A2 there is a noticeable velocity spike. Trial 1: trail1_a2 Trial 2: trail2_a2 Trial 3: trail3_a2

The Moveit! motion planners definitely seem to be generating non-ideal trajectories, which leads to this issue. There has been discussion previously about the OMPL library (which i am using), potentially causing this issue on Kinetic (https://github.com/ros-planning/moveit/issues/416). However i'm not sure if this issue has been further discussed/fixed.

A simple, first attempt fix might be to just adjust the command position if the change in velocity ( acceleration) is too great, i.e set a threshold for the acceleration. A very basic moving average filter could be used to determine the command position if this limit is exceeded. I will try this and see how it goes. Any further ideas on this issue would be greatly appreciated it!

Note that adjusting your payload data on the kuka controller will effect when you will receive this error, as the kuka motion planner is looking at the commanded motion, relative to the current inertial conditions, and predicting that the commanded motion will exceed torque limits. $LOAD is taken into account when making these predictions [1]. However, this does not really solve the root of the problem.

Cheers!

[1] https://www.robot-forum.com/robotforum/kuka-robot-forum/command-gear-torque-a23-with-rsi-control/

RhysMcK avatar Apr 19 '18 00:04 RhysMcK

Hi. Thanks for the detailed description.

I believe your analysis could be true: the OMPL version used in Kinetic MoveIt is known to generate (sometimes) discontinous paths, leading to time parameterisation artefacts such as the one you've plotted.

Unfortunately there isn't much we can do about that, other than implementing something like the filter you mention. I'm not entirely sure I'd be willing to do that in the driver though: perhaps an intermediate node should do the filtering before the trajectory gets passed to the driver (the driver (actually: RSI) just requires smooth trajectories, it is the producer's responsibility to provide those).

ros-planning/moveit#416 has not been resolved, and in fact, the linked issue on the OMPL bitbucket repository (ompl/ompl#309) is also still open. Perhaps commenting on that might help get this some more attention.

In the meantime MoveIt has also seen some changes to the time parameterisation components. ros-planning/moveit#441 got merged into Kinetic. The interplay with the OMPL issue is not clear to me, but perhaps one is related to the other.

An interesting PR that has not been merged yet could be ros-planning/moveit#809: this adds a parameterisation plugin based on TOTG. In my experience this produces rather impressively smooth trajectories, but I'm again not sure how the OMPL issue influences this.

From this data i was then able to extrapolate the commanding velocities

You're probably aware, but the driver only uses position control. Any velocities are only the distance travelled in one interpolation period.

gavanderhoorn avatar Apr 19 '18 13:04 gavanderhoorn

@rtonnaer

gavanderhoorn avatar Apr 19 '18 13:04 gavanderhoorn

Unfortunately there isn't much we can do about that, other than implementing something like the filter you mention. I'm not entirely sure I'd be willing to do that in the driver though: perhaps an intermediate node should do the filtering before the trajectory gets passed to the driver (the driver (actually: RSI) just requires smooth trajectories, it is the producer's responsibility to provide those).

I think I'll change my opinion on this: I would like to add this to the driver, but not to filter (ie: change) the trajectory, but to check it before accepting it for execution.

That way, we can at least avoid executing trajectories that will (probably) lead to problems some time later after we've started executing them.

A complicating factor is that we only provide a ros_control hardware_interface, and do not control any of the infrastructure that accepts and processes the trajectories. That would be joint_trajectory_controller.

Note: the JTC actually does the interpolation of the received trajectory. MoveIt et al influence the initial parameterisation, but the JTC is ultimately the one that interpolates the trajectories and sends the values to the hardware_interface.

gavanderhoorn avatar Apr 20 '18 14:04 gavanderhoorn

Possibly a more robust solution could be to also add a RSI FILTER object on the Kuka side. I have not experimented with this before and the documentation is a bit scarce, but it is possible to implement a bunch of standard filters (butterworth, low-pass, high-pass, etc.). A simple low-pass filter should help omit any random jerks and inconsistency outputted from the JTC.

RhysMcK avatar Apr 22 '18 21:04 RhysMcK

So apparently this issue has been solved, see https://github.com/ros-planning/moveit/issues/416 https://github.com/ros-planning/moveit/pull/869

Can you confirm that this solves your problem?

cschindlbeck avatar May 02 '18 09:05 cschindlbeck

@cschindlbeck: I'm not sure it has been really solved. The MoveIt changes are related, but do not address the cause afaict. Changes in OMPL are needed as well, and until those are released into Kinetic the situation as-is remains.

See also the bitbucket issue.

gavanderhoorn avatar May 02 '18 10:05 gavanderhoorn

See https://github.com/ros-planning/moveit/issues/416#issuecomment-386040826 if you can't wait :)

gavanderhoorn avatar May 03 '18 11:05 gavanderhoorn

Thanks @gavanderhoorn, i've been keeping a close eye on that thread!.... I'll try this out and see if it makes any improvements. Although i now believe the weird velocity spikes seen the plots above is more likely due to the current default method of time parameterization used in moveit. I'm eager to try either TOPP and/or TOTG when its ready for kinetic :) https://github.com/ros-planning/moveit/pull/809

RhysMcK avatar May 03 '18 23:05 RhysMcK

Getting ros-planning/moveit#809 to work on Kinetic should not too difficult. It's fairly stand-alone. You would just need to add the plugin and update your MoveIt config to load that parameterisation adapter instead of the default one (it's configured in the OMPL planning adapter section).

gavanderhoorn avatar May 04 '18 08:05 gavanderhoorn

@RhysMcK: have you had any opportunity to test the fixes in OMPL+MoveIt?

gavanderhoorn avatar May 15 '18 20:05 gavanderhoorn

Haven't had a chance yet @gavanderhoorn. This is top of my todo list though, hopefully i get around to it in the next couple days.

RhysMcK avatar May 15 '18 21:05 RhysMcK

Had a chance to test today. Unfortunately the problem still persists after using the latest OMPL + Moveit updates. I expect this problem as i stated above is most likely due to the current method of time parameterization. Which i will confirm once i get a spare moment!

plot_after_update

Despite the velocity spikes between consequence points, the latest updates definitely remove some jerkiness to the planned paths. In generally, the trajectories are a lot smoother from a "macro-view". i.e less zero-crossings.

RhysMcK avatar May 18 '18 04:05 RhysMcK

@RhysMcK wrote:

Unfortunately the problem still persists after using the latest OMPL + Moveit updates.

just making sure: you compiled everything from source, correct? There hasn't been an updated release yet.

I expect this problem as i stated above is most likely due to the current method of time parameterization. Which i will confirm once i get a spare moment!

I would suggest to try and use ros-planning/moveit#809 to see whether that improves things.

One thing we keep ignoring in this context (or at I believe we've not given it much attention) is that ros_control's joint_trajectory_controller also interpolates. The data you're plotting is what comes out of that, not MoveIt itself. It could be that the two agree with each other, but would still be good to check.

gavanderhoorn avatar May 18 '18 05:05 gavanderhoorn

Not everything, I have Moveit! installed from source, and i am using the debian binary for OMPL, which as far as i can see is up-to-date and includes the above mentioned fixes...Or am i wrong?

yep, https://github.com/ros-planning/moveit/pull/809 is my next step :)

And yes, good point about the joint_trajectory_controller interpolation... I will investigate this.

RhysMcK avatar May 18 '18 09:05 RhysMcK

https://github.com/ros/rosdistro/pull/17747 was merged two weeks ago. Kinetic sync was yesterday so you'll only have OMPL updated if you updated your ROS pkgs just now (or at least: after the sync).

gavanderhoorn avatar May 18 '18 09:05 gavanderhoorn

I did update my ROS packages, so i am using the latest ompl! Thanks for clarifying

RhysMcK avatar May 18 '18 09:05 RhysMcK

sigh.....

screenshot from 2018-05-18 20-35-37

This is TOTG (https://github.com/ros-planning/moveit/pull/809 ) implemented in the kinetic/devel branch. Admittedly, the profiles on general look smother... but still, the bug persists.

RhysMcK avatar May 18 '18 10:05 RhysMcK

But this is still taken from the hardware_interface, right?

If so, we're looking at JTC output, which is influenced by TOTG/IPTP, but does not have a 1-to-1 relationship with it.

I would be really interested in a plot of velocities coming out of MoveIt (that is hard(er) to get hold of, but would help diagnosing whether this is still a MoveIt/OMPL/IPTP/TOTG issue, or is in JTC).

gavanderhoorn avatar May 18 '18 10:05 gavanderhoorn

Also: I'm assuming you're using a real-time kernel and that the driver/hardware_interface has real-time priority. If not, then scheduling could be an issue here.

gavanderhoorn avatar May 18 '18 10:05 gavanderhoorn

But this is still taken from the hardware_interface, right?

Yep, thats correct

I would be really interested in a plot of velocities coming out of the MoveIt (that is hard(er) to get hold of, but would help diagnosing whether this is still a MoveIt/OMPL/IPTP/TOTG issue, or is in JTC).

Yes i agree, I will attempt to do this ASAP.

Also: I'm assuming you're using a real-time kernel and that the driver/hardware_interface has real-time priority. If not, then scheduling could be an issue here.

I am not at the moment, however i have previously... and this problem still persisted. I believe the need for a RT / low latency kernel would only really be an issue if i was experiencing communication issues, i.e packet losses. According to the Diagnostic monitor i always have connection quality of 100. With no more than about 1 or 2 contiguous packet loss.

RhysMcK avatar May 18 '18 11:05 RhysMcK

I switched to moveit from source and upgraded the ROS packages via apt-get. I am a little bit confused, i still see libompl.so.1.2.1 in /opt/ros/kinetic/lib/x86_64-linux-gnu. Shouldn't that be libompl.so.1.2.3?

@RhysMcK Can you tell me how you obtained the velocity profiles? I might be interested in recording these by myself. Is this a numerically differentiated ROS topic?

cschindlbeck avatar May 23 '18 12:05 cschindlbeck

So today i tested my setup again as in https://github.com/ros-industrial/kuka_experimental/issues/123 where i got the same error with moveit from source and (hopefully) the new OMPL (i used the default time parameterization)

So regarding your comment @RhysMcK

i fear you might once again encounter this error when you speed things back up to "normal" speed.

Now i am able to execute motions with normal speed without getting an error. However, i still hear "knocking" during the motions which i believe is likely caused by "jerky" motions as you already showed in the velocity profiles...so i can confirm that there is still an issue

cschindlbeck avatar May 24 '18 07:05 cschindlbeck

@cschindlbeck i just did a quick-and-dirty print out of the position commands i was sending from within /kuka_hardware_interface.cpp and then a python script to collect the data and plot it. The velocity profile is just the differences between the last two sent position commands.

RhysMcK avatar May 24 '18 23:05 RhysMcK

@RhysMcK wrote:

i just did a quick-and-dirty print out of the position commands

just a note: both printf(..) as well as std stream output are two of the worst cases when it comes to predictive scheduling of tasks. In a real-time system, they are absolutely off-limits. On a soft real-time system, they'll probably influence scheduling in a negative way.

If you have the option, and want to implement this nicely, use an internal buffer that stores n last samples, and use a ROS service (or topic) to retrieve the contents of that buffer after the trajectory has been executed.

That way we avoid any kind of timing influence that may be caused by console IO.

gavanderhoorn avatar May 25 '18 07:05 gavanderhoorn

The velocity profile is just the differences between the last two sent position commands.

Without dividing by duration? The spikes in the TOTG graph always come in pairs with a point too fast, followed by a point too slow. This would happen if the first call to JTC is late and the second therefore has a smaller duration.

@gavanderhoorn Related: Should the call to controller manager update be changed to use a fixed duration and increment the time with fixed 4ms/12ms, since the robot expects points interpolated at this rate? Currently, if scheduling is a few ms late, JTC will return a point too far ahead, which could introduce micro-stutter even if the packet reaches the robot in time.

hartmanndennis avatar May 29 '18 13:05 hartmanndennis

@hartmanndennis wrote:

Related: Should the call to controller manager update be changed to use a fixed duration and increment the time with fixed 4ms/12ms, since the robot expects points interpolated at this rate? Currently, if scheduling is a few ms late, JTC will return a point too far ahead, which could introduce micro-stutter even if the packet reaches the robot in time.

This could be something to try. However, I think I can imagine a situation where it is possible for a 'desync' to build up between real-time and trajectory execution.

Implementation-wise I would still use the pkts from the controller to dictate control flow in the node, but then instead of using real time assume a fixed delta.

Is this something you could test?


Edit: it would be nice if we could use IPOC-deltas for the dt, instead of having to configure the dt somewhere.

gavanderhoorn avatar May 29 '18 17:05 gavanderhoorn

I'll make a PR soon. I already tested a bit and updated #95 with velocity graphs. I'm still unsure, if only the duration parameter should be set constant or if the time parameter should be increased by the constant IPOC. I don't know about possible consequences for the controllers, if the clocks do diverge.

hartmanndennis avatar May 30 '18 15:05 hartmanndennis

If possible, I would vote for using IPOC_(t_n+1) - IPOC_(t_n). That would seem to keep things in sync with the controller.

gavanderhoorn avatar May 30 '18 15:05 gavanderhoorn