Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warnings to jog_arm low_pass filter #1872

Merged
merged 8 commits into from
Feb 14, 2020

Conversation

tylerjw
Copy link
Member

@tylerjw tylerjw commented Feb 3, 2020

Description

These warnings and errors handle warning the user of bad input parameter values for the low pass filter in jog arm. Here is the function of the feedback magnitude with respect to the low_pass_filter_coeff value: https://www.wolframalpha.com/input/?i=y+%3D+%281%2F%281%2Bx%29%29+*+%281-x%29

Here is a small python script that shows why these values are problematic:

def run_filter(mu, length):
  x0 = x1 = y1 = 0

  y = x = [0 for i in range(length)]
  x[0] = 1

  for i in range(length):
    x1 = x0
    x0 = x[i]

    y[i] = (1.0 / (1.0 + mu)) * (x1 + x0 + (1.0 - mu)*y1)
    y1 = y[i]

  print(mu, sum(y))

run_filter(2.0, 1000)
run_filter(1.0, 1000)
run_filter(0.5, 1000)
run_filter(0, 1000)
run_filter(-0.5, 1000)
run_filter(-0.999, 1000)
run_filter(-2, 1000)

output:

(2.0, 0.5000000000000002)
(1.0, 1.0)
(0.5, 1.9999999999999991)
(0, 1999.0)
(-0.5, inf)
(-0.999, inf)
(-2, nan)

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Create tests, which fail without this PR reference
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@tylerjw tylerjw requested a review from AndyZe February 3, 2020 20:22
@codecov-io
Copy link

codecov-io commented Feb 3, 2020

Codecov Report

Merging #1872 into master will increase coverage by 0.11%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1872      +/-   ##
==========================================
+ Coverage   50.15%   50.27%   +0.11%     
==========================================
  Files         313      313              
  Lines       24641    24628      -13     
==========================================
+ Hits        12359    12381      +22     
+ Misses      12282    12247      -35
Impacted Files Coverage Δ
...xperimental/moveit_jog_arm/src/low_pass_filter.cpp 95.45% <90.9%> (-4.55%) ⬇️
...anning_scene_monitor/src/current_state_monitor.cpp 52.82% <0%> (-0.28%) ⬇️
...erimental/moveit_jog_arm/src/jog_cpp_interface.cpp 11.9% <0%> (ø) ⬆️
...veit_jog_arm/include/moveit_jog_arm/jog_arm_data.h 100% <0%> (ø) ⬆️
...cessing/src/time_optimal_trajectory_generation.cpp 76.2% <0%> (ø) ⬆️
...ics_plugin_loader/src/kinematics_plugin_loader.cpp 62.58% <0%> (+0.25%) ⬆️
moveit_core/robot_model/src/joint_model.cpp 71.42% <0%> (+6.66%) ⬆️
...veit_experimental/moveit_jog_arm/src/jog_calcs.cpp 72.79% <0%> (+8.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2395183...9bc7eee. Read the comment docs.

Copy link
Contributor

@jliukkonen jliukkonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved but see comments.

Copy link
Member

@AndyZe AndyZe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error message about an unstable coefficient is awesome, greatly needed.

moveit_experimental/moveit_jog_arm/src/low_pass_filter.cpp Outdated Show resolved Hide resolved
@tylerjw
Copy link
Member Author

tylerjw commented Feb 4, 2020

The last change was to make it C++11 compatible (the way I used static_assert was from C++17).

{
filter_coeff_ = low_pass_filter_coeff;
// guarantee this doesn't change because the logic depends on this length implicity
static_assert(LowPassFilter::FILTER_LENGTH == 2, "moveit_jog_arm::LowPassFilter::FILTER_LENGTH should be 2");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that a little paranoid? Also, what if someone initializes previous_measurements_ with another constant... ;)

Copy link
Member Author

@tylerjw tylerjw Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is too paranoid. The indexes of the array are explicitly used instead of loops below this and this check is just a compiler check. It won't add any code to the binary. This is just helping protecting against someone modifying this value.

I don't know why changing the values of previous_measurements_ with the reset method would affect this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, initialization using reset is not an issue. This check here only warns other developers from changing the value of FILTER_LENGTH in the header file. But you could just declare previous_measurement_ with another constant and this assertion will never be triggered, so it's not really a guarantee that logic doesn't break. I'm not concerned about performance, I just think that a simple comment in the header file is more effective than letting developers run into warnings at compile time.

moveit_experimental/moveit_jog_arm/src/low_pass_filter.cpp Outdated Show resolved Hide resolved
@henningkayser henningkayser merged commit 15cb1a2 into moveit:master Feb 14, 2020
@tylerjw tylerjw deleted the p/tylerjw/iir_warnings branch February 14, 2020 14:59
@tylerjw tylerjw mentioned this pull request May 8, 2020
20 tasks
tylerjw added a commit to PickNikRobotics/moveit that referenced this pull request May 12, 2020
tylerjw added a commit to PickNikRobotics/moveit that referenced this pull request May 12, 2020
tylerjw added a commit to PickNikRobotics/moveit that referenced this pull request May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants