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

Force offset and vector magnitude support in ApplyForceTorque #2056

Merged
merged 69 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
89c5b9c
Create ApplyForceTorque GUI
Henrique-BO Jun 4, 2023
15746ef
Apply forces using the apply_link_wrench system
Henrique-BO Jun 5, 2023
992a6f5
Add the ability to select the link of wrench application
Henrique-BO Jun 6, 2023
2c69d18
Clean up ApplyForceTorque and improve debug messages
Henrique-BO Jun 7, 2023
5d63bdf
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jun 13, 2023
5af8dfc
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jun 14, 2023
2364fc9
Fix codecheck
Henrique-BO Jun 14, 2023
17693a0
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jun 30, 2023
6fbbfc0
Remove force offset from interface and store only the selected entity
Henrique-BO Jun 30, 2023
6b3f196
Add force offset support to ApplyLinkWrench system and to Link API
Henrique-BO Jun 30, 2023
34101f7
Added additional tests to LinkAddWorldForce integration test
Henrique-BO Jul 6, 2023
06cd84e
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 11, 2023
814d501
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jul 11, 2023
7450833
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jul 14, 2023
9409fe7
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 14, 2023
ca1c904
Apply force to COM and minor changes
Henrique-BO Jul 14, 2023
de6000b
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jul 17, 2023
e05b134
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 17, 2023
4243567
Wrench specified in link-fixed frame
Henrique-BO Jul 17, 2023
361cd4f
Rename function to AddWorldWrenchRelativeToCOM
Henrique-BO Jul 17, 2023
12f6fbe
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jul 19, 2023
f6dc7c4
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 19, 2023
3f08e6d
Merge branch 'gazebosim:gz-sim7' into apply_force_torque
Henrique-BO Jul 24, 2023
802ccbd
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 24, 2023
336b119
Using link inertial frame
Henrique-BO Jul 24, 2023
3911d73
Automatically load ApplyLinkWrench and minor fixes
Henrique-BO Jul 26, 2023
cc162ca
Add force and torque visual indicators
Henrique-BO Jul 26, 2023
10f6873
Merge branch 'gz-sim7' into apply_force_torque_vis
Henrique-BO Jul 27, 2023
f9e26da
Offset and magnitude support in ApplyForceTorque
Henrique-BO Jul 27, 2023
32b11af
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Jul 27, 2023
5b31c43
Add GizmoVisual to rotate force vector
Henrique-BO Jul 28, 2023
86be94c
Enable selecting vector for rotation
Henrique-BO Jul 28, 2023
bfbb1bd
New WrenchVisualizer class and fix rotation tool bugs
Henrique-BO Aug 3, 2023
7a12d22
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 3, 2023
d9e7b7a
Fixed rotation tool behavior
Henrique-BO Aug 3, 2023
bcac463
Merge branch 'apply_force_torque_vis' of github.com:Henrique-BO/gz-si…
Henrique-BO Aug 3, 2023
3490f44
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Aug 3, 2023
911b45e
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO Aug 3, 2023
31afa94
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO Aug 3, 2023
96eb087
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO Aug 3, 2023
6ad2200
Minor fixes and spinbox step adjustment
Henrique-BO Aug 3, 2023
a8b804a
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO Aug 7, 2023
b0890b7
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 7, 2023
3651a31
Merge branch 'gazebosim:gz-sim7' into force_offset
Henrique-BO Aug 7, 2023
ee693bc
Use all offsets on link frame
Henrique-BO Aug 9, 2023
36732e4
Merge branch 'force_offset' of github.com:Henrique-BO/gz-sim into for…
Henrique-BO Aug 9, 2023
a867825
Merge branch 'force_offset' into apply_force_torque_offset
Henrique-BO Aug 9, 2023
36e2f23
Update ApplyLinkWrench system usage
Henrique-BO Aug 9, 2023
ad8911e
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 10, 2023
b0bf815
Merge remote-tracking branch 'origin/gz-sim7' into apply_force_torque…
Henrique-BO Aug 10, 2023
c5f5cb6
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 16, 2023
b5cafc3
Minor changes
Henrique-BO Aug 16, 2023
a5afaa7
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO Aug 16, 2023
251dab8
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO Aug 17, 2023
f3ee0d6
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 17, 2023
8f31b53
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 21, 2023
d6afb10
Use SensorCount instead of NodeCount
Henrique-BO Aug 21, 2023
60f9413
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO Aug 21, 2023
9da0347
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_offset
Henrique-BO Aug 21, 2023
9561e68
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 21, 2023
2a2bf8f
Merge branch 'gazebosim:gz-sim7' into apply_force_torque_vis
Henrique-BO Aug 22, 2023
419b34f
Update ApplyForceTorque interface
Henrique-BO Aug 22, 2023
5bef192
Merge branch 'apply_force_torque_vis' into apply_force_torque_offset
Henrique-BO Aug 22, 2023
f93a400
Merge branch 'apply_force_torque_offset' of github.com:Henrique-BO/gz…
Henrique-BO Aug 22, 2023
9c897a4
Merge branch 'gz-sim7' into apply_force_torque_offset
Henrique-BO Aug 23, 2023
c4819ef
Add includes
Henrique-BO Aug 23, 2023
0a7e7b3
Change dimgrey to black
Henrique-BO Aug 23, 2023
2c83ce2
Destroy visuals when closing plugin
Henrique-BO Aug 24, 2023
db942e4
Use DestroyNode
Henrique-BO Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 74 additions & 16 deletions src/gui/plugins/apply_force_torque/ApplyForceTorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

#include <memory>
#include <mutex>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <mutex>
#include <memory>
#include <mutex>

#include <string>

Expand All @@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <gz/math/Vector3.hh>
#include <gz/math/Vector2.hh>
#include <gz/math/Vector3.hh>

#include <gz/msgs/entity_plugin_v.pb.h>
#include <gz/msgs/entity_wrench.pb.h>
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}

/////////////////////////////////////////////////
Expand All @@ -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);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions src/gui/plugins/apply_force_torque/ApplyForceTorque.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QStringList>
#include <QObject>
#include <QEvent>
#include <QVector3D>
azeey marked this conversation as resolved.
Show resolved Hide resolved

#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/gui/GuiSystem.hh>
Expand Down Expand Up @@ -73,6 +74,14 @@ namespace sim
NOTIFY ForceChanged
)

/// \brief Force magnitude
Q_PROPERTY(
double forceMag
READ ForceMag
WRITE SetForceMag
NOTIFY ForceMagChanged
)

/// \brief Torque
Q_PROPERTY(
QVector3D torque
Expand All @@ -81,6 +90,14 @@ namespace sim
NOTIFY TorqueChanged
)

/// \brief Torque magnitude
Q_PROPERTY(
double torqueMag
READ TorqueMag
WRITE SetTorqueMag
NOTIFY TorqueMagChanged
)

/// \brief Constructor
public: ApplyForceTorque();

Expand All @@ -98,24 +115,28 @@ namespace sim
EntityComponentManager &_ecm) override;

/// \brief Get the name of the selected model
/// \return The model name
public: Q_INVOKABLE QString ModelName() const;

/// \brief Notify that the model name changed
signals: void ModelNameChanged();

/// \brief Get the name of the links of the selected model
/// \return The list of link names
public: Q_INVOKABLE QStringList LinkNameList() const;

/// \brief Notify that the link list changed
signals: void LinkNameListChanged();

/// \brief Get index of the link in the list
/// \return The link index
public: Q_INVOKABLE int LinkIndex() const;

/// \brief Notify that the link index changed
signals: void LinkIndexChanged();

/// \brief Set the index of the link in the list
/// \param[in] _linkIndex The new link index
public: Q_INVOKABLE void SetLinkIndex(int _linkIndex);

/// \brief Get the force vector
Expand All @@ -129,6 +150,18 @@ namespace sim
/// \param[in] _force The new force vector
public: Q_INVOKABLE void SetForce(QVector3D _force);

/// \brief Get the magnitude of the force vector
/// \return The force magnitude
public: Q_INVOKABLE double ForceMag() const;

/// \brief Notify that the force magnitude changed
signals: void ForceMagChanged();

/// \brief Set the magnitude of the force vector, scaling it to
/// keep its direction
/// \param[in] _forceMag The new force magnitude
public: Q_INVOKABLE void SetForceMag(double _forceMag);

/// \brief Get the torque vector
/// \return The torque vector
public: Q_INVOKABLE QVector3D Torque() const;
Expand All @@ -140,6 +173,24 @@ namespace sim
/// \param[in] _torque The new torque vector
public: Q_INVOKABLE void SetTorque(QVector3D _torque);

/// \brief Get the magnitude of the torque vector
/// \return The torque magnitude
public: Q_INVOKABLE double TorqueMag() const;

/// \brief Notify that the torque magnitude changed
signals: void TorqueMagChanged();

/// \brief Set the magnitude of the torque vector, scaling it to
/// keep its direction
/// \param[in] _torqueMag The new torque magnitude
public: Q_INVOKABLE void SetTorqueMag(double _torqueMag);

/// \brief Set components of offset vector
/// \param[in] _x X component of offset
/// \param[in] _y Y component of offset
/// \param[in] _z Z component of offset
public: Q_INVOKABLE void UpdateOffset(double _x, double _y, double _z);

/// \brief Apply the specified force
public: Q_INVOKABLE void ApplyForce();

Expand Down
Loading