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

Adding thrust coefficient calculation #1652

Merged
merged 14 commits into from
Oct 6, 2022

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Aug 17, 2022

Signed-off-by: Marco A. Gutierrez marco@openrobotics.org

🎉 New feature

Work towards osrf/lrauv#225

Summary

Thrust coefficient in Thruster plugin can only be set to a fixed number, by default 1. This PR adds a calculation that makes it depend on the velocity of the vehicle. The calculation implemented here is based Fossen's equations described in "Guidance and Control of Ocean Vehicles".

Test it

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@github-actions github-actions bot added the 🏯 fortress Ignition Fortress label Aug 17, 2022
@marcoag marcoag changed the title adding thrust coefficient calculation Adding thrust coefficient calculation Aug 17, 2022
@marcoag marcoag added enhancement New feature or request MBARI-LRAUV Sponsored by MBARI-LRAUV project: https://github.com/osrf/lrauv labels Aug 17, 2022
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.cc Outdated Show resolved Hide resolved
src/systems/thruster/Thruster.hh Outdated Show resolved Hide resolved
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag force-pushed the marcoag/thrust_coefficient_for_thrust_plugin branch from 59ec256 to f8550f1 Compare August 17, 2022 15:17
marcoag and others added 8 commits August 17, 2022 15:21
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag force-pushed the marcoag/thrust_coefficient_for_thrust_plugin branch from 4a7d797 to 0cd1d65 Compare August 17, 2022 15:22
@nkoenig nkoenig requested a review from caguero August 22, 2022 18:24
@arjo129 arjo129 mentioned this pull request Aug 24, 2022
22 tasks
…_plugin

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
(((1 - this->wakeFraction) * this->linearVelocity)
/ (this->propellerAngVel * this->propellerDiameter));
if (!std::isnan(calculatedThrustCoefficient)
&& calculatedThrustCoefficient!=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

@marcoag meta: hmm, something's off here. If the thrust coefficient is zero, then no thrust should apply. If the propeller angular velocity is zero, then no thrust should apply and the thrust coefficient is not defined (and it doesn't matter anyways). I see this cause-effect relationship is reversed in this plugin: we assume thrust is always applicable and compute propeller angular velocity. I think we should set that straight. Then you would not need this conditional.

Copy link
Member Author

Choose a reason for hiding this comment

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

When the plugin starts the angular velocity is zero, making the thrust coefficient nan. Since it's used later on to calculate the propeller angular velocity then the model would never start moving. The intent of this check was to break this loop and use the default thrust coefficient which is 1 and won't affect the final result. I think it might suffice with the isnan check for this or another option is to only update the thrust coefficient once the propeller angular velocity is not 0, maybe the later makes more sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, almost forgot to reply.

I guess my point is that the current implementation is not a good approximation. It takes thrust commands instead of propeller angular velocities, and applies forces instantaneously. That's why we are running into this odd corner cases. It makes me wonder, why use this improved thrust coefficient if the dynamics are not there.

Anyways, I think that if we want to keep everything as-is, we could (a) set propeller angular velocity to zero if thrust is zero, bypassing all calculations, and (b) solve the quadratic-like equation to get propeller angular velocity in all other cases, as if it had reached steady state instantaneously (like with forces).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know the reason to take thrust commands instead of propeller angular velocities here, the later would be even easier since it seems the thrust gets converter into an angular velocity anyway.

a) The propeller angular velocity would be zero if thrust is zero using calculations, so there doesn't seem a to be a need to bypass them.

Still the problem is a chicken egg dependency between velocity and thrust coefficient, due to a mutual dependency, if any of them is zero it would make the other one zero, preventing the vehicle to move when starting from stationary. With the conditional above I was trying to avoid this problem. I guess it makes more sense to only calculate when angular_velocity != 0 and use the default thrust coefficient (or latest) when that happens. Will add this change for now.

Copy link
Contributor

@hidmic hidmic Sep 7, 2022

Choose a reason for hiding this comment

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

As per offline discussion, let's go with this as-is. I ran a couple, very much simplified numerical experiments and the coefficient converges even if we start from a guess. I can't swear on convergence, but if the sim looks OK we should be fine.

solve the quadratic-like equation to get propeller angular velocity in all other cases, as if it had reached steady state instantaneously (like with forces).

Re: to myself. This is not super easy, I missed the linear velocity term in the thrust coefficient model.

Comment on lines 73 to 81
/// - <wake_fraction> - Relative speed reduction between the water
/// at the propeller vs behind the vessel.
/// [Optional, defults to 0.2]
/// - <alpha_1> - Constant given by the open water propeller diagram. Used
/// in the calculation of the thrust coefficient.
/// [Optional, defults to 1]
/// - <alpha_2> - Constant given by the open water propeller diagram. Used
/// in the calculation of the thrust coefficient.
/// [Optional, defults to 0]
Copy link
Contributor

Choose a reason for hiding this comment

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

@marcoag bibliographic references here would be great.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 7351aab.

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM but for two relatively minor comments

// Only update if the thrust coefficient was not set by configuration
// and angular velocity is not zero. Some velocity is needed to calculate
// the thrust coefficient otherwise it will never start moving.
if (!this->thrustCoefficientSet && this->propellerAngVel !=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

@marcoag could the thrust coefficient ever become zero while moving (in other words, could either $\alpha_1$ or $\alpha_2$ be negative)? If so, maybe we should reset thrust coefficient to one if propeller angular velocity ever becomes zero. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'm surprised the compiler didn't complain about a floating point comparison to zero. AFAIK std::abs(this->propellerAngVel) < std::numeric_limits<double>::epsilon() would be a slightly more robust test.

Copy link
Member Author

Choose a reason for hiding this comment

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

It did threw a warning, I assumed anything that is not a strict zero would work.

Changed to your suggestion: 51337cd.

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM pending green CI

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@codecov
Copy link

codecov bot commented Sep 15, 2022

Codecov Report

Merging #1652 (b051ef0) into ign-gazebo6 (69e7757) will increase coverage by 0.03%.
The diff coverage is 85.18%.

@@               Coverage Diff               @@
##           ign-gazebo6    #1652      +/-   ##
===============================================
+ Coverage        64.69%   64.73%   +0.03%     
===============================================
  Files              321      321              
  Lines            26062    26155      +93     
===============================================
+ Hits             16862    16931      +69     
- Misses            9200     9224      +24     
Impacted Files Coverage Δ
src/systems/thruster/Thruster.cc 89.50% <85.18%> (-0.87%) ⬇️
src/SimulationRunner.cc 90.93% <0.00%> (-0.96%) ⬇️
src/gui/plugins/scene_manager/GzSceneManager.cc 17.58% <0.00%> (-0.60%) ⬇️
.../systems/triggered_publisher/TriggeredPublisher.cc 83.28% <0.00%> (-0.38%) ⬇️
.../systems/triggered_publisher/TriggeredPublisher.hh 100.00% <0.00%> (ø)
src/rendering/RenderUtil.cc 39.01% <0.00%> (+0.11%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@nkoenig nkoenig merged commit 4dd1858 into ign-gazebo6 Oct 6, 2022
@nkoenig nkoenig deleted the marcoag/thrust_coefficient_for_thrust_plugin branch October 6, 2022 17:17
@Crola1702
Copy link
Contributor

👨‍🌾 Hi there!

I was taking a look at this issue on the buildfarm and I noticed we have a new gcc warning.

  • Gcc warning:
comparing floating point with == or != is unsafe [-Wfloat-equal] 247 | if (_calculateCoefficient && angularVelocity != 0) | ^

On thruster.cc:247.

Do you mind taking a look at how to solve/supress it? Thanks

@j-rivero
Copy link
Contributor

Do you mind taking a look at how to solve/supress it? Thanks

I think that @ahcorde arrived to this #1754

nkoenig added a commit that referenced this pull request Nov 2, 2022
* Add topic parameter to thrust plugin (#1681)

* Add topic parameter.

Signed-off-by: Carlos Agüero <caguero@openrobotics.org>

* 🎈 6.12.0: bumped minor and updated changelog (#1682)

* bumped minor and updated changelog

Signed-off-by: Dharini Dutia <dharini@openrobotics.org>

* fixed changelog as per feedback and updated migration guide

Signed-off-by: Dharini Dutia <dharini@openrobotics.org>

Signed-off-by: Dharini Dutia <dharini@openrobotics.org>

* Fix reference link in ackermann steering (#1683)

Signed-off-by: Kenji Brameld <kenjibrameld@gmail.com>

* Fix installation instructions on Ubuntu 22.04 (#1686)

Signed-off-by: Silvio Traversaro <silvio@traversaro.it>

* Add a service to trigger functionality (#1611)

* initial commit to allow plugin to call a service

Signed-off-by: Liam Han <liam@openrobotics.org>

* adding tutorial and modifying the world sdf

Signed-off-by: Liam Han <liam@openrobotics.org>

* added test for single input and single service output

Signed-off-by: Liam Han <liam@openrobotics.org>

* added test for single input and multiple service output

Signed-off-by: Liam Han <liam@openrobotics.org>

* added test for invalid matching service name => timeout

Signed-off-by: Liam Han <liam@openrobotics.org>

* modified variables the camelCase

Signed-off-by: Liam Han <liam@openrobotics.org>

* fixed typo, indentation, grammar, lines that exceeded 80 char

Signed-off-by: Liam Han <liam@openrobotics.org>

* fixing ubuntu bionic ci issue

Signed-off-by: Liam Han <liam@openrobotics.org>

* silly syntax mistake on expect_eq

Signed-off-by: Liam Han <liam@openrobotics.org>

* added three more test cases that addesses incorrect response type, incorrect request type and false result

Signed-off-by: Liam Han <liam@openrobotics.org>

* WIP: major restructuring and currently working. Requires more cleanup and test

Signed-off-by: Liam Han <liam@openrobotics.org>

* WIP: fixed preprocessor define bug

Signed-off-by: Liam Han <liam@openrobotics.org>

* WIP: working but extremely convoluted

Signed-off-by: Liam Han <liam@openrobotics.org>

* WIP major modification but a lot of errors and tests failed

Signed-off-by: Liam Han <liam@openrobotics.org>

* stable version: had to revert back to previous work. all tests passed

Signed-off-by: Liam Han <liam@openrobotics.org>

* modified to use blocking Request method as well as reduce a service worker thread to just one thread with the publisher. all tests passed

Signed-off-by: Liam Han <liam@openrobotics.org>

* stable version: had to revert back to previous work. all tests passed

Signed-off-by: Liam Han <liam@openrobotics.org>

* successfully reverted and tested

Signed-off-by: Liam Han <liam@openrobotics.org>

* fixing PR suggestions

Signed-off-by: Liam Han <liam@openrobotics.org>

* changed string with 'serv' to 'srv' and included <mutex> to the header

Signed-off-by: Liam Han <liam@openrobotics.org>

* fixed indentation and removed rep.set_data since it's unused on the client service

Signed-off-by: Liam Han <liam@openrobotics.org>

* getting rid of the id

Signed-off-by: Liam Han <liam@openrobotics.org>

* fixed race condition resulting seldom test failure

Signed-off-by: Liam Han <liam@openrobotics.org>

* changed from triggerSrv to serviceCount. This compensates for the two threads running at different rate

Signed-off-by: Liam Han <liam@openrobotics.org>

* braces indentation

Signed-off-by: Mabel Zhang <mabel@openrobotics.org>

* addressing gnu c compiler (gcc) warnings

Signed-off-by: Liam Han <liam@openrobotics.org>

Signed-off-by: Liam Han <liam@openrobotics.org>
Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
Co-authored-by: Mabel Zhang <mabel@openrobotics.org>

* Fix loading render engine plugins in GUI  (#1694)

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* Enable inherited model topic name. (#1689)

Allows for inheriting model name for robotNamespace when SDF element is not set and provides a debug message showing the topics it subscribes to.

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
Co-authored-by: Nate Koenig <nkoenig@users.noreply.github.com>

* Add ResourceSpawner example file (#1701)

Add an example file for the ResourceSpawner plugin. I'm using this to link from https://github.com/gazebosim/docs/blob/master/garden/Model_insertion_fuel.md. To improve gazebosim/garden-tutorial-party#1991.

Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>

* Update triggered_publisher.sdf (#1737)

found a silly typo that was pushed back in PR (#1611)

* Adds sky cubemap URI to the sky.proto's header (#1739)

* Adds sky cubemap URI to the sky.proto's header

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* require sdf 12.6

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Signed-off-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Nate Koenig <nate@openrobotics.org>

* Return absolute path when finding a resource (#1741)

* Adds sky cubemap URI to the sky.proto's header

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* Return absolute path when finding a resource

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Signed-off-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Nate Koenig <nate@openrobotics.org>

* Restore Add System GUI plugin (#1685)

* cherry pick aef3020

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* Adding thrust coefficient calculation (#1652)

* adding thrust coefficient calculation

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.cc

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* Update src/systems/thruster/Thruster.hh

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* thrust coefficient test and behavior updates

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* making float comparision more robust

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

* fix float comparision and lint

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>

* Enable/Disable individual hydrodynamic components. (#1692)

This commit enables and disables individual components of the hydrodynamics. This is often useful for debugging odd behaviours of a hydrodynamic model.

* Fortress: Removed warnings (#1754)

* Fortress: Removed warnings

* Removed unused speedlimit file (#1761)

Signed-off-by: ahcorde <ahcorde@gmail.com>

* Enable use of ign gazebo -s on Windows (take two) (#1764)

* Enable use of ign gazebo -s on Windows

Signed-off-by: Silvio <silvio@traversaro.it>

* Update src/CMakeLists.txt

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Silvio <silvio@traversaro.it>

* Fix cmdmodel6.rb and cmdgazebo6.rb contining the same code

Signed-off-by: Silvio <silvio@traversaro.it>

Signed-off-by: Silvio <silvio@traversaro.it>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>

* Script and tutorial for generating procedural datasets with Blender (#1412)

Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>

* Fix scene_broadcaster_system test (#1766)

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Signed-off-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Nate Koenig <nate@openrobotics.org>

* Lint

Signed-off-by: Michael Carroll <michael@openrobotics.org>

* Clean build and update test

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
Signed-off-by: Dharini Dutia <dharini@openrobotics.org>
Signed-off-by: Kenji Brameld <kenjibrameld@gmail.com>
Signed-off-by: Silvio Traversaro <silvio@traversaro.it>
Signed-off-by: Liam Han <liam@openrobotics.org>
Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Signed-off-by: Nate Koenig <nate@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: Silvio <silvio@traversaro.it>
Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
Signed-off-by: Michael Carroll <michael@openrobotics.org>
Co-authored-by: Carlos Agüero <caguero@openrobotics.org>
Co-authored-by: Dharini Dutia <dharini@openrobotics.org>
Co-authored-by: Kenji Brameld <kenjibrameld@gmail.com>
Co-authored-by: Silvio Traversaro <silvio@traversaro.it>
Co-authored-by: Liam Han <liam@openrobotics.org>
Co-authored-by: Mabel Zhang <mabel@openrobotics.org>
Co-authored-by: Ian Chen <ichen@osrfoundation.org>
Co-authored-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
Co-authored-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Marco A. Gutierrez <marcogg@marcogg.com>
Co-authored-by: Arjo Chakravarty <arjo@openrobotics.org>
Co-authored-by: Andrej Orsula <orsula.andrej@gmail.com>
Co-authored-by: Michael Carroll <michael@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🏯 fortress Ignition Fortress MBARI-LRAUV Sponsored by MBARI-LRAUV project: https://github.com/osrf/lrauv
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants