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

[JTC] Fix state offset tests #797

Merged

Conversation

christophfroehlich
Copy link
Contributor

@christophfroehlich christophfroehlich commented Oct 10, 2023

I tried to write tests for #794 and copied the initialization of joint_pos_ from test_hw_states_has_offset_first_controller_start/test_hw_states_has_offset_later_controller_start: This did not work because ActivateTrajectoryController always has set it to the constant values from the utils-header -> I fixed that.

Tests failed now, and thinking about the test criteria itself, considering #189, I rewrote the tests -> succeed now.

add approach to change controller without "jumps" from the command to state values:

  • when started HW interface has to set command_interfaces to N aN
  • controller checks if command interfaces are NaN --> then is a controller started for the first time, so read states
  • if command interface have a value --> so a controller was running already (supports switching between controllers)

@destogl You have added this part, before it got changed a bit by #340 by @AndyZe and @mechwiz

  • Why should we set state_desired_ to the value of read_state_from_command_interfaces? If there is no active trajectory (start_with_holding is false), this value will only be published on the state-topic. If there is a new trajectory, it will be overwritten by the sampled trajectory.
  • Setting state_current to the command read from the hardware interface is fine: It is only used for setting the set_hold_position if start_with_holding is set. It will be overwritten by the first call of update.

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #797 (387afc7) into master (232154d) will decrease coverage by 0.49%.
Report is 1 commits behind head on master.
The diff coverage is 28.57%.

❗ Current head 387afc7 differs from pull request most recent head efcf0d1. Consider uploading reports for the commit efcf0d1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #797      +/-   ##
==========================================
- Coverage   45.40%   44.92%   -0.49%     
==========================================
  Files          40       40              
  Lines        3649     3642       -7     
  Branches     1723     1716       -7     
==========================================
- Hits         1657     1636      -21     
- Misses        810      834      +24     
+ Partials     1182     1172      -10     
Flag Coverage Δ
unittests 44.92% <28.57%> (-0.49%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...jectory_controller/joint_trajectory_controller.hpp 0.00% <ø> (ø)
...ory_controller/src/joint_trajectory_controller.cpp 47.72% <28.57%> (+0.45%) ⬆️

... and 3 files with indirect coverage changes

Copy link
Member

@bmagyar bmagyar left a comment

Choose a reason for hiding this comment

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

let's wait for @destogl to reply too

Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

Just a small proposal for optimization since we are discussing those functions.

Answers to comments

  • Why should we set state_desired_ to the value of read_state_from_command_interfaces? If there is no active trajectory (start_with_holding is false), this value will only be published on the state-topic. If there is a new trajectory, it will be overwritten by the sampled trajectory.

Can it be that we change this when fixing the “hold on start” feature? I think the reason was that we have immediate output to the command interface even if there is no reference. If we can achieve that by using start_with_holding this is also fine with me. Nevertheless, I would not add additional if, even if we set the value “unnecessary”. Or do you think that this could be confusing?

  • Setting state_current to the command read from the hardware interface is fine: It is only used for setting the set_hold_position if start_with_holding is set. It will be overwritten by the first call of update.

OK, you are right. Then we probably should not set state_desired in that case.

@christophfroehlich
Copy link
Contributor Author

  • Why should we set state_desired_ to the value of read_state_from_command_interfaces? If there is no active trajectory (start_with_holding is false), this value will only be published on the state-topic. If there is a new trajectory, it will be overwritten by the sampled trajectory.

Can it be that we change this when fixing the “hold on start” feature? I think the reason was that we have immediate output to the command interface even if there is no reference. If we can achieve that by using start_with_holding this is also fine with me. Nevertheless, I would not add additional if, even if we set the value “unnecessary”. Or do you think that this could be confusing?

I'll think that trough again if this is achieved with the hold-on-start in a fresh moment.

Optional override is already inside an if, for me it is clearer to have it in the else branch instead (but that's only my personal preference).

@christophfroehlich
Copy link
Contributor Author

  • Why should we set state_desired_ to the value of read_state_from_command_interfaces? If there is no active trajectory (start_with_holding is false), this value will only be published on the state-topic. If there is a new trajectory, it will be overwritten by the sampled trajectory.

Can it be that we change this when fixing the “hold on start” feature? I think the reason was that we have immediate output to the command interface even if there is no reference. If we can achieve that by using start_with_holding this is also fine with me. Nevertheless, I would not add additional if, even if we set the value “unnecessary”. Or do you think that this could be confusing?

The current way with this PR is:

  • If we have start_with_holding=false, no update of the command interface until the first trajectory is received. See has_active_trajectory() in update method.
  • start_with_holding=true: There will be an immediate update of the command interfaces, with position set from state_current_, which is
    • set to the values of the command interfaces, if they are not NaN or
    • set to the values read from the state interfaces otherwise.

Notes:

@destogl What do you think?

Copy link
Contributor

mergify bot commented Nov 15, 2023

This pull request is in conflict. Could you fix it @christophfroehlich?

@christophfroehlich christophfroehlich force-pushed the jtc/fix_state_offset_tests branch from 8937354 to 5a111e3 Compare November 15, 2023 17:13
Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks!

@destogl destogl merged commit b13ae5b into ros-controls:master Nov 15, 2023
10 of 13 checks passed
mergify bot pushed a commit that referenced this pull request Nov 15, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
(cherry picked from commit b13ae5b)

# Conflicts:
#	joint_trajectory_controller/test/test_trajectory_controller_utils.hpp
@christophfroehlich christophfroehlich deleted the jtc/fix_state_offset_tests branch November 15, 2023 18:40
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 17, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 17, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 19, 2023
Squashed commit of the following:

commit 0a9f4b0
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Nov 16 23:17:20 2023 +0000

    Bump ros-tooling/action-ros-ci from 0.3.4 to 0.3.5 (ros-controls#833)

commit 3fc0f50
Author: Christoph Fröhlich <[email protected]>
Date:   Wed Nov 15 20:03:40 2023 +0100

    [JTC] Activate update of dynamic parameters (ros-controls#761)

commit b13ae5b
Author: Christoph Fröhlich <[email protected]>
Date:   Wed Nov 15 19:14:09 2023 +0100

    [JTC] Fix tests when state offset is used (ros-controls#797)

    * Simplify initialization of states
    * Rename read_state_from_hardware method
    * Don't set state_desired in on_activate
    ---------

    Co-authored-by: Dr. Denis <[email protected]>

commit f1a5397
Author: Christoph Fröhlich <[email protected]>
Date:   Wed Nov 15 12:18:38 2023 +0100

    [JTC] Remove deprecation warnings, set `allow_nonzero_velocity_at_trajectory_end` default false (ros-controls#834)

commit 232154d
Author: Christoph Fröhlich <[email protected]>
Date:   Sat Nov 11 15:30:19 2023 +0100

    [CI] Update coverage workflows and some cleanup (ros-controls#819)

    * Add CI coverage jobs for humble and iron

    * Add all packages to source build

    * Update repos files

    * Build ros-control packages from source

    * use humble job names

    Co-authored-by: Christoph Fröhlich <[email protected]>

    ---------

    Co-authored-by: Bence Magyar <[email protected]>

commit 0196eeb
Author: Tony Baltovski <[email protected]>
Date:   Thu Nov 9 17:15:45 2023 -0500

    [diff_drive_controller] Fixed typos in diff_drive_controller_parameter.yaml. (ros-controls#822)

commit 71ec842
Author: Christoph Fröhlich <[email protected]>
Date:   Tue Nov 7 13:47:23 2023 +0100

    [CI] Re-add humble workflow files and add iron to readme (ros-controls#818)

commit 9d4ea6b
Author: Bence Magyar <[email protected]>
Date:   Tue Nov 7 12:01:23 2023 +0000

    [diff_drive_controller] Remove non-stamped Twist option (ros-controls#812)

commit 5f78fe4
Author: Bence Magyar <[email protected]>
Date:   Tue Nov 7 12:01:02 2023 +0000

    Adjust tests after passing URDF to controllers (ros-controls#817)

commit 2c6d7a6
Author: Bence Magyar <[email protected]>
Date:   Mon Nov 6 18:29:10 2023 +0000

    Add iron branch (ros-controls#814)

commit f81a82c
Author: Christoph Fröhlich <[email protected]>
Date:   Fri Nov 3 21:18:31 2023 +0100

    [CI] Codecov  (ros-controls#807)

commit c6ecab7
Author: Bence Magyar <[email protected]>
Date:   Wed Nov 1 21:38:16 2023 +0000

    Use pre-commit fork of clang-format instead of local (ros-controls#813)

commit 6e46053
Author: Bence Magyar <[email protected]>
Date:   Tue Oct 31 21:34:10 2023 +0000

    3.17.0

commit 822552f
Author: Bence Magyar <[email protected]>
Date:   Tue Oct 31 21:33:40 2023 +0000

    Update changelogs

commit 8a90b51
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Oct 31 20:27:04 2023 +0000

    Bump ros-tooling/action-ros-ci from 0.3.3 to 0.3.4 (ros-controls#810)

commit b65314d
Author: Christoph Fröhlich <[email protected]>
Date:   Thu Oct 26 12:09:27 2023 +0200

    Cleanup comments and unnecessary checks (ros-controls#803)

commit b36b9d2
Author: Christoph Fröhlich <[email protected]>
Date:   Tue Oct 24 20:17:28 2023 +0200

    [CI] Fix coverage build and codecov stats (ros-controls#804)

commit 22356e0
Author: Dr. Denis <[email protected]>
Date:   Mon Oct 16 18:49:47 2023 +0200

    [TestNodes] Optimize output about setup of JTC publisher (ros-controls#792)

commit ac291ab
Author: Christoph Fröhlich <[email protected]>
Date:   Mon Oct 16 13:00:53 2023 +0200

    Steering controllers library: fix open loop mode (ros-controls#793)

    * set last*velocity variables for open loop odometry

    * Make function arguments const

    * Update function in header file too

commit c831b6c
Author: Christoph Fröhlich <[email protected]>
Date:   Mon Oct 16 12:58:44 2023 +0200

    Update requirements of state interfaces (ros-controls#798)
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 27, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 29, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 29, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
bmagyar pushed a commit that referenced this pull request Nov 30, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Nov 30, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
christophfroehlich added a commit to christophfroehlich/ros2_controllers that referenced this pull request Dec 5, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
bmagyar pushed a commit that referenced this pull request Dec 6, 2023
* Simplify initialization of states
* Rename read_state_from_hardware method
* Don't set state_desired in on_activate
---------

Co-authored-by: Dr. Denis <[email protected]>
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.

3 participants