-
Notifications
You must be signed in to change notification settings - Fork 269
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
Force offset and vector magnitude support in ApplyForceTorque #2056
Merged
azeey
merged 69 commits into
gazebosim:gz-sim7
from
Henrique-BO:apply_force_torque_offset
Aug 25, 2023
Merged
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
89c5b9c
Create ApplyForceTorque GUI
Henrique-BO 15746ef
Apply forces using the apply_link_wrench system
Henrique-BO 992a6f5
Add the ability to select the link of wrench application
Henrique-BO 2c69d18
Clean up ApplyForceTorque and improve debug messages
Henrique-BO 5d63bdf
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 5af8dfc
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 2364fc9
Fix codecheck
Henrique-BO 17693a0
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 6fbbfc0
Remove force offset from interface and store only the selected entity
Henrique-BO 6b3f196
Add force offset support to ApplyLinkWrench system and to Link API
Henrique-BO 34101f7
Added additional tests to LinkAddWorldForce integration test
Henrique-BO 06cd84e
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 814d501
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 7450833
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 9409fe7
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO ca1c904
Apply force to COM and minor changes
Henrique-BO de6000b
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO e05b134
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 4243567
Wrench specified in link-fixed frame
Henrique-BO 361cd4f
Rename function to AddWorldWrenchRelativeToCOM
Henrique-BO 12f6fbe
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO f6dc7c4
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 3f08e6d
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO 802ccbd
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 336b119
Using link inertial frame
Henrique-BO 3911d73
Automatically load ApplyLinkWrench and minor fixes
Henrique-BO cc162ca
Add force and torque visual indicators
Henrique-BO 10f6873
Merge branch 'gz-sim7' into apply_force_torque_vis
Henrique-BO f9e26da
Offset and magnitude support in ApplyForceTorque
Henrique-BO 32b11af
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 5b31c43
Add GizmoVisual to rotate force vector
Henrique-BO 86be94c
Enable selecting vector for rotation
Henrique-BO bfbb1bd
New WrenchVisualizer class and fix rotation tool bugs
Henrique-BO 7a12d22
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO d9e7b7a
Fixed rotation tool behavior
Henrique-BO bcac463
Merge branch 'apply_force_torque_vis' of github.com:Henrique-BO/gz-si…
Henrique-BO 3490f44
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO 911b45e
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO 31afa94
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO 96eb087
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO 6ad2200
Minor fixes and spinbox step adjustment
Henrique-BO a8b804a
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO b0890b7
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO 3651a31
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO ee693bc
Use all offsets on link frame
Henrique-BO 36732e4
Merge branch 'force_offset' of github.com:Henrique-BO/gz-sim into for…
Henrique-BO a867825
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO 36e2f23
Update ApplyLinkWrench system usage
Henrique-BO ad8911e
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO b0bf815
Merge remote-tracking branch 'origin/gz-sim7' into apply_force_torque…
Henrique-BO c5f5cb6
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO b5cafc3
Minor changes
Henrique-BO a5afaa7
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO 251dab8
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO f3ee0d6
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO 8f31b53
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO d6afb10
Use SensorCount instead of NodeCount
Henrique-BO 60f9413
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO 9da0347
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO 9561e68
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO 2a2bf8f
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO 419b34f
Update ApplyForceTorque interface
Henrique-BO 5bef192
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO f93a400
Merge branch 'apply_force_torque_offset' of github.com:Henrique-BO/gz…
Henrique-BO 9c897a4
Merge branch 'gz-sim7' into apply_force_torque_offset
Henrique-BO c4819ef
Add includes
Henrique-BO 0a7e7b3
Change dimgrey to black
Henrique-BO 2c83ce2
Destroy visuals when closing plugin
Henrique-BO db942e4
Use DestroyNode
Henrique-BO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ | |||||||
* | ||||||||
*/ | ||||||||
|
||||||||
#include <memory> | ||||||||
#include <mutex> | ||||||||
#include <string> | ||||||||
|
||||||||
|
@@ -26,6 +27,7 @@ | |||||||
#include <gz/gui/MainWindow.hh> | ||||||||
#include <gz/math/Pose3.hh> | ||||||||
#include <gz/math/Quaternion.hh> | ||||||||
#include <gz/math/Vector2.hh> | ||||||||
#include <gz/math/Vector3.hh> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
#include <gz/msgs/entity_plugin_v.pb.h> | ||||||||
#include <gz/msgs/entity_wrench.pb.h> | ||||||||
|
@@ -129,12 +131,12 @@ namespace sim | |||||||
/// \brief Torque to be applied in link-fixed frame | ||||||||
public: math::Vector3d torque{0.0, 0.0, 0.0}; | ||||||||
|
||||||||
/// \brief Offset from the link origin to the center of mass in world coords | ||||||||
public: math::Vector3d inertialPos; | ||||||||
|
||||||||
/// \brief Pose of the link-fixed frame | ||||||||
public: math::Pose3d linkWorldPose; | ||||||||
|
||||||||
/// \brief Pose of the inertial frame relative to the link frame | ||||||||
public: math::Pose3d inertialPose; | ||||||||
|
||||||||
/// \brief Pointer to the rendering scene | ||||||||
public: rendering::ScenePtr scene{nullptr}; | ||||||||
|
||||||||
|
@@ -443,9 +445,8 @@ void ApplyForceTorque::Update(const UpdateInfo &/*_info*/, | |||||||
*this->dataPtr->selectedEntity); | ||||||||
if (inertial) | ||||||||
{ | ||||||||
this->dataPtr->inertialPos = | ||||||||
linkWorldPose.Rot().RotateVector(inertial->Data().Pose().Pos()); | ||||||||
this->dataPtr->linkWorldPose = linkWorldPose; | ||||||||
this->dataPtr->inertialPose = inertial->Data().Pose(); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -499,6 +500,27 @@ void ApplyForceTorque::SetForce(QVector3D _force) | |||||||
this->dataPtr->vectorRot = math::Matrix4d::LookAt( | ||||||||
-this->dataPtr->force, math::Vector3d::Zero).Rotation(); | ||||||||
} | ||||||||
emit this->ForceMagChanged(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
double ApplyForceTorque::ForceMag() const | ||||||||
{ | ||||||||
return this->dataPtr->force.Length(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
void ApplyForceTorque::SetForceMag(double _forceMag) | ||||||||
{ | ||||||||
if (this->dataPtr->force == math::Vector3d::Zero) | ||||||||
{ | ||||||||
this->dataPtr->force.X() = _forceMag; | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
this->dataPtr->force = _forceMag * this->dataPtr->force.Normalized(); | ||||||||
} | ||||||||
emit this->ForceChanged(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
|
@@ -521,6 +543,33 @@ void ApplyForceTorque::SetTorque(QVector3D _torque) | |||||||
this->dataPtr->vectorRot = math::Matrix4d::LookAt( | ||||||||
-this->dataPtr->torque, math::Vector3d::Zero).Rotation(); | ||||||||
} | ||||||||
emit this->TorqueMagChanged(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
double ApplyForceTorque::TorqueMag() const | ||||||||
{ | ||||||||
return this->dataPtr->torque.Length(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
void ApplyForceTorque::SetTorqueMag(double _torqueMag) | ||||||||
{ | ||||||||
if (this->dataPtr->torque == math::Vector3d::Zero) | ||||||||
{ | ||||||||
this->dataPtr->torque.X() = _torqueMag; | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
this->dataPtr->torque = _torqueMag * this->dataPtr->torque.Normalized(); | ||||||||
} | ||||||||
emit this->TorqueChanged(); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
void ApplyForceTorque::UpdateOffset(double _x, double _y, double _z) | ||||||||
{ | ||||||||
this->dataPtr->offset.Set(_x, _y, _z); | ||||||||
} | ||||||||
|
||||||||
///////////////////////////////////////////////// | ||||||||
|
@@ -553,15 +602,21 @@ void ApplyForceTorquePrivate::PublishWrench(bool _applyForce, bool _applyTorque) | |||||||
} | ||||||||
|
||||||||
// Force and torque in world coordinates | ||||||||
math::Vector3d forceToApply = this->linkWorldPose.Rot().RotateVector( | ||||||||
_applyForce ? this->force : math::Vector3d::Zero); | ||||||||
math::Vector3d torqueToApply = this->linkWorldPose.Rot().RotateVector( | ||||||||
_applyTorque ? this->torque : math::Vector3d::Zero) + | ||||||||
this->inertialPos.Cross(forceToApply); | ||||||||
math::Vector3d forceToApply = _applyForce ? | ||||||||
this->linkWorldPose.Rot().RotateVector(this->force) : | ||||||||
math::Vector3d::Zero; | ||||||||
math::Vector3d torqueToApply = _applyTorque ? | ||||||||
this->linkWorldPose.Rot().RotateVector(this->torque) : | ||||||||
math::Vector3d::Zero; | ||||||||
// The ApplyLinkWrench system takes the offset in the link frame | ||||||||
math::Vector3d offsetToApply = _applyForce ? | ||||||||
this->offset + this->inertialPose.Pos() : | ||||||||
math::Vector3d::Zero; | ||||||||
|
||||||||
msgs::EntityWrench msg; | ||||||||
msg.mutable_entity()->set_id(*this->selectedEntity); | ||||||||
msgs::Set(msg.mutable_wrench()->mutable_force(), forceToApply); | ||||||||
msgs::Set(msg.mutable_wrench()->mutable_force_offset(), offsetToApply); | ||||||||
msgs::Set(msg.mutable_wrench()->mutable_torque(), torqueToApply); | ||||||||
|
||||||||
this->pub.Publish(msg); | ||||||||
|
@@ -632,14 +687,16 @@ void ApplyForceTorquePrivate::OnRender() | |||||||
///////////////////////////////////////////////// | ||||||||
void ApplyForceTorquePrivate::UpdateVisuals() | ||||||||
{ | ||||||||
math::Pose3d inertialWorldPose = this->linkWorldPose * this->inertialPose; | ||||||||
// Update force visualization | ||||||||
if (this->force != math::Vector3d::Zero && | ||||||||
this->selectedEntity.has_value()) | ||||||||
{ | ||||||||
math::Vector3d worldForce = | ||||||||
this->linkWorldPose.Rot().RotateVector(this->force); | ||||||||
math::Vector3d applicationPoint = this->linkWorldPose.Pos() + | ||||||||
this->inertialPos + this->linkWorldPose.Rot().RotateVector(this->offset); | ||||||||
math::Vector3d applicationPoint = | ||||||||
inertialWorldPose.Pos() + | ||||||||
this->linkWorldPose.Rot().RotateVector(this->offset); | ||||||||
double scale = applicationPoint.Distance(this->camera->WorldPose().Pos()) | ||||||||
/ 2.0; | ||||||||
this->wrenchVis.UpdateVectorVisual( | ||||||||
|
@@ -658,7 +715,7 @@ void ApplyForceTorquePrivate::UpdateVisuals() | |||||||
math::Vector3d worldTorque = | ||||||||
this->linkWorldPose.Rot().RotateVector(this->torque); | ||||||||
math::Vector3d applicationPoint = | ||||||||
this->linkWorldPose.Pos() + this->inertialPos; | ||||||||
inertialWorldPose.Pos(); | ||||||||
double scale = applicationPoint.Distance(this->camera->WorldPose().Pos()) | ||||||||
/ 2.0; | ||||||||
this->wrenchVis.UpdateVectorVisual( | ||||||||
|
@@ -678,13 +735,13 @@ void ApplyForceTorquePrivate::UpdateVisuals() | |||||||
&& this->force != math::Vector3d::Zero) | ||||||||
{ | ||||||||
pos = | ||||||||
this->linkWorldPose.Pos() + this->inertialPos + | ||||||||
inertialWorldPose.Pos() + | ||||||||
this->linkWorldPose.Rot().RotateVector(this->offset); | ||||||||
} | ||||||||
else if (this->activeVector == RotationToolVector::TORQUE | ||||||||
&& this->torque != math::Vector3d::Zero) | ||||||||
{ | ||||||||
pos = this->linkWorldPose.Pos() + this->inertialPos; | ||||||||
pos = inertialWorldPose.Pos(); | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
|
@@ -865,7 +922,8 @@ void ApplyForceTorquePrivate::HandleMouseEvents() | |||||||
} | ||||||||
|
||||||||
/// get start and end pos in world frame from 2d point | ||||||||
math::Vector3d pos = this->linkWorldPose.Pos() + this->inertialPos + | ||||||||
math::Pose3d inertialWorldPose = this->linkWorldPose * this->inertialPose; | ||||||||
math::Vector3d pos = inertialWorldPose.Pos() + | ||||||||
this->linkWorldPose.Rot().RotateVector(this->offset); | ||||||||
double d = pos.Dot(axis); | ||||||||
math::Planed plane(axis, d); | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.