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

Parse new param for enabling / disabling IMU orientation output #899

Merged
merged 10 commits into from
Sep 30, 2021
23 changes: 22 additions & 1 deletion src/systems/imu/Imu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class ignition::gazebo::systems::ImuPrivate
/// \brief Ign-sensors sensor factory for creating sensors
public: sensors::SensorFactory sensorFactory;

/// \brief True to compute and output orientation values,
/// false to leave the orientation field empty in the published msg.
public: bool outputOrientation = true;

public: Entity worldEntity = kNullEntity;

/// \brief Create IMU sensor
Expand All @@ -82,6 +86,19 @@ Imu::Imu() : System(), dataPtr(std::make_unique<ImuPrivate>())
//////////////////////////////////////////////////
Imu::~Imu() = default;

//////////////////////////////////////////////////
void Imu::Configure(const Entity & /*_entity*/,
const std::shared_ptr<const sdf::Element> &_sdf,
gazebo::EntityComponentManager & /*_ecm*/,
gazebo::EventManager & /*_eventMgr*/)
{
if (_sdf->HasElement("output_orientation"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This would apply to all IMUs in simulation. Have you considered providing more granular configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated changes in this PR to parse a new enable_orientation SDF element (gazebosim/sdformat#651) that allows each imu sensor to enable/disable orientation output. 48e171f

{
this->dataPtr->outputOrientation =
_sdf->Get<bool>("output_orientation");
}
}

//////////////////////////////////////////////////
void Imu::PreUpdate(const UpdateInfo &/*_info*/,
EntityComponentManager &_ecm)
Expand Down Expand Up @@ -186,6 +203,9 @@ void ImuPrivate::CreateImuEntities(EntityComponentManager &_ecm)
// Set topic
_ecm.CreateComponent(_entity, components::SensorTopic(sensor->Topic()));

// Set whether to output orientation
sensor->SetOrientationEnabled(this->outputOrientation);

this->entitySensorMap.insert(
std::make_pair(_entity, std::move(sensor)));

Expand Down Expand Up @@ -254,7 +274,8 @@ void ImuPrivate::RemoveImuEntities(

IGNITION_ADD_PLUGIN(Imu, System,
Imu::ISystemPreUpdate,
Imu::ISystemPostUpdate
Imu::ISystemPostUpdate,
Imu::ISystemConfigure
)

IGNITION_ADD_PLUGIN_ALIAS(Imu, "ignition::gazebo::systems::Imu")
9 changes: 8 additions & 1 deletion src/systems/imu/Imu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ namespace systems
class Imu:
public System,
public ISystemPreUpdate,
public ISystemPostUpdate
public ISystemPostUpdate,
public ISystemConfigure
{
/// \brief Constructor
public: explicit Imu();

/// \brief Destructor
public: ~Imu() override;

/// Documentation inherited
public: void Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
gazebo::EventManager &_eventMgr) final;

/// Documentation inherited
public: void PreUpdate(const UpdateInfo &_info,
EntityComponentManager &_ecm) final;
Expand Down
40 changes: 40 additions & 0 deletions test/integration/imu_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,43 @@ TEST_F(ImuTest, ModelFalling)
EXPECT_EQ(imuMsgs.back().entity_name(), scopedName);
mutex.unlock();
}

/////////////////////////////////////////////////
// The test checks to make sure orientation is not published if it is deabled
TEST_F(ImuTest, OrientationDisabled)
{
imuMsgs.clear();

// Start server
ServerConfig serverConfig;
const auto sdfFile = std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/imu_no_orientation.sdf";
iche033 marked this conversation as resolved.
Show resolved Hide resolved
serverConfig.SetSdfFile(sdfFile);

Server server(serverConfig);
EXPECT_FALSE(server.Running());
EXPECT_FALSE(*server.Running(0));

const std::string sensorName = "imu_sensor";

auto topic =
"world/imu_sensor/model/imu_model/link/link/sensor/imu_sensor/imu";
Copy link
Contributor

Choose a reason for hiding this comment

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

common::joinPaths

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm this string if for topic name so I think it's not necessary to use joinPaths as that's intended for file paths?


// subscribe to imu topic
transport::Node node;
node.Subscribe(topic, &imuCb);

// step world and verify imu's orientation is not published
// Run server
size_t iters200 = 200u;
server.Run(true, iters200, false);

// Check we received messages
EXPECT_GT(imuMsgs.size(), 0u);
mutex.lock();
for (const auto &msg : imuMsgs)
{
EXPECT_FALSE(msg.has_orientation());
}
mutex.unlock();
}