Skip to content

Commit

Permalink
Fix HumanLogger not working when logging just one quantity (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGrieco authored Feb 16, 2023
1 parent d3a2f54 commit 3c036dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed a typo in `DynamicalInverseKinematics` that caused a wrong calculation of the rotation mean error. (https://github.com/robotology/human-dynamics-estimation/pull/330)
- Fixed `HumanLogger` when logging just one kind of data (https://github.com/robotology/human-dynamics-estimation/pull/338)

## [2.7.0] - 2020-10-20

Expand Down
39 changes: 19 additions & 20 deletions devices/HumanLogger/HumanLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ struct hde::devices::HumanLoggerSettings

using namespace hde::devices;

using MatlabChannelName = std::string;

class HumanLogger::impl
{
public:
Expand All @@ -61,7 +59,6 @@ class HumanLogger::impl
bool& option);
bool configureBufferManager();

bool firstRun = true;
size_t waitingFirstReadCounter = 1;

interfaces::IHumanState* iHumanState = nullptr;
Expand Down Expand Up @@ -321,7 +318,7 @@ bool HumanLogger::attach(yarp::dev::PolyDriver* poly)
std::cerr << "attaching " << deviceName << std::endl;
if (deviceName == "human_state_provider" || deviceName == "human_state_remapper") {
// Attach IHumanState interface
if (pImpl->iHumanState || !poly->view(pImpl->iHumanState) || !pImpl->iHumanState) {
if (!poly->view(pImpl->iHumanState) || !pImpl->iHumanState) {
yError() << logPrefix << "Failed to view IHumanState interface from the polydriver";
return false;
}
Expand All @@ -338,7 +335,7 @@ bool HumanLogger::attach(yarp::dev::PolyDriver* poly)

if (deviceName == "human_dynamics_estimator" || deviceName == "human_dynamics_remapper") {
// Attach IHumanDynamics interface
if (pImpl->iHumanDynamics || !poly->view(pImpl->iHumanDynamics) || !pImpl->iHumanDynamics) {
if (!poly->view(pImpl->iHumanDynamics) || !pImpl->iHumanDynamics) {
yError() << logPrefix << "Failed to view IHumanDynamics interface from the polydriver";
return false;
}
Expand All @@ -353,6 +350,22 @@ bool HumanLogger::attach(yarp::dev::PolyDriver* poly)
yInfo() << logPrefix << deviceName << "attach() successful";
}

// If only one type of data is used, attachAll will not be called
// so we have to start the periodic thread from here
if ((!pImpl->settings.logHumanState || pImpl->iHumanState) &&
(!pImpl->settings.logHumanDynamics || pImpl->iHumanDynamics))
{
if (!pImpl->configureBufferManager()) {
yError() << logPrefix << "Failed to configure buffer manager for the logger.";
return false;
}

if(!start()) {
yError() << logPrefix << "Failed to start the loop.";
return false;
}
}

return true;
}

Expand Down Expand Up @@ -427,25 +440,11 @@ bool HumanLogger::attachAll(const yarp::dev::PolyDriverList& driverList)

attachStatus = attachStatus && attach(driver->poly);
}

if (!pImpl->configureBufferManager()) {
yError() << logPrefix << "Failed to configure buffer manager for the logger.";
}


if (attachStatus) {
yDebug() << logPrefix << "attach() successful";
}

// ====
// MISC
// ====

// Start the PeriodicThread loop
if (attachStatus && !start()) {
yError() << logPrefix << "Failed to start the loop.";
return false;
}

return attachStatus;
}

Expand Down

0 comments on commit 3c036dd

Please sign in to comment.