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 angular acceleration to the Link class #1288

Merged
merged 4 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions include/ignition/gazebo/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ namespace ignition
public: void EnableVelocityChecks(EntityComponentManager &_ecm,
bool _enable = true) const;

/// \brief Get the angular acceleration of the body in the world frame.
/// \param[in] _ecm Entity-component manager.
/// \return Angular acceleration of the body in the world frame or
/// nullopt if acceleration checks aren't enabled.
/// \sa EnableAccelerationChecks
public: std::optional<math::Vector3d> WorldAngularAcceleration(
const EntityComponentManager &_ecm) const;

/// \brief Get the linear acceleration of the body in the world frame.
/// \param[in] _ecm Entity-component manager.
/// \return Linear acceleration of the body in the world frame or nullopt
Expand Down
13 changes: 13 additions & 0 deletions src/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <ignition/msgs/Utility.hh>

#include "ignition/gazebo/components/AngularAcceleration.hh"
#include "ignition/gazebo/components/AngularVelocity.hh"
#include "ignition/gazebo/components/CanonicalLink.hh"
#include "ignition/gazebo/components/Collision.hh"
Expand Down Expand Up @@ -245,6 +246,14 @@ void Link::EnableVelocityChecks(EntityComponentManager &_ecm, bool _enable)
_enable);
}

//////////////////////////////////////////////////
std::optional<math::Vector3d> Link::WorldAngularAcceleration(
const EntityComponentManager &_ecm) const
{
return _ecm.ComponentData<components::WorldAngularAcceleration>(
this->dataPtr->id);
}

//////////////////////////////////////////////////
std::optional<math::Vector3d> Link::WorldLinearAcceleration(
const EntityComponentManager &_ecm) const
Expand All @@ -257,6 +266,10 @@ std::optional<math::Vector3d> Link::WorldLinearAcceleration(
void Link::EnableAccelerationChecks(EntityComponentManager &_ecm, bool _enable)
const
{
enableComponent<components::WorldAngularAcceleration>(_ecm, this->dataPtr->id,
_enable);
enableComponent<components::AngularAcceleration>(_ecm, this->dataPtr->id,
_enable);
enableComponent<components::WorldLinearAcceleration>(_ecm, this->dataPtr->id,
_enable);
enableComponent<components::LinearAcceleration>(_ecm, this->dataPtr->id,
Expand Down
13 changes: 12 additions & 1 deletion test/integration/link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ignition/common/Console.hh>
#include <ignition/common/Util.hh>

#include <ignition/gazebo/components/AngularAcceleration.hh>
#include <ignition/gazebo/components/AngularVelocity.hh>
#include <ignition/gazebo/components/CanonicalLink.hh>
#include <ignition/gazebo/components/Collision.hh>
Expand Down Expand Up @@ -315,23 +316,33 @@ TEST_F(LinkIntegrationTest, LinkAccelerations)

// Before we enable acceleration, acceleration should return nullopt
EXPECT_EQ(std::nullopt, link.WorldLinearAcceleration(ecm));
EXPECT_EQ(std::nullopt, link.WorldAngularAcceleration(ecm));

// After enabling, they should return default values
link.EnableAccelerationChecks(ecm);
EXPECT_EQ(math::Vector3d::Zero, link.WorldLinearAcceleration(ecm));
EXPECT_EQ(math::Vector3d::Zero, link.WorldAngularAcceleration(ecm));
EXPECT_NE(nullptr, ecm.Component<components::WorldLinearAcceleration>(eLink));
EXPECT_NE(nullptr,
ecm.Component<components::WorldAngularAcceleration>(eLink));

// After setting acceleration, we get the value
math::Vector3d linAccel{1.0, 0.0, 0.0};
ecm.SetComponentData<components::WorldLinearAcceleration>(eLink, linAccel);

EXPECT_EQ(linAccel, link.WorldLinearAcceleration(ecm));

math::Vector3d angAccel{0.0, 1.0, 0.0};
ecm.SetComponentData<components::WorldAngularAcceleration>(eLink, angAccel);
EXPECT_EQ(angAccel, link.WorldAngularAcceleration(ecm));

// Disabling accelerations goes back to nullopt
link.EnableAccelerationChecks(ecm, false);

EXPECT_EQ(std::nullopt, link.WorldLinearAcceleration(ecm));
EXPECT_EQ(std::nullopt, link.WorldAngularAcceleration(ecm));
EXPECT_EQ(nullptr, ecm.Component<components::WorldLinearAcceleration>(eLink));
EXPECT_EQ(nullptr,
ecm.Component<components::WorldAngularAcceleration>(eLink));
}

//////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion tutorials/migration_link_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ URI | TODO
UpdateParameters | TODO
VisualPose | See visual API
WindMode | `ignition::gazebo::Link::WindMode`
WorldAngularAccel | TODO
WorldAngularAccel | `ignition::gazebo::Link::WorldAngularAcceleration`
WorldAngularMomentum | TODO
WorldAngularVel | `ignition::gazebo::Link::WorldAngularVelocity`
WorldCoGLinearVel | TODO
Expand Down