Skip to content

Commit

Permalink
Use timeout for checking iHumanState interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGrieco authored and lrapetti committed Sep 2, 2022
1 parent c8c681a commit 0b8881b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 11 additions & 3 deletions devices/HumanDynamicsEstimator/HumanDynamicsEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const std::string DeviceName = "HumanDynamicsEstimator";
const std::string LogPrefix = DeviceName + " :";
constexpr double DefaultPeriod = 0.01;

// Timeout for checking that the iHumanState interface is providing consistent data
constexpr static double INTERFACE_CHECK_TIMEOUT_S = 10;

using namespace hde::devices;

static bool parseYarpValueToStdVector(const yarp::os::Value& option, std::vector<double>& output)
Expand Down Expand Up @@ -1235,12 +1238,17 @@ bool HumanDynamicsEstimator::attach(yarp::dev::PolyDriver* poly)
return false;
}

//TODO Check the interface
// Check the iHumanState interface
double interfaceCheckStart = yarp::os::Time::now();
int count = 1000000;
while (pImpl->iHumanState->getNumberOfJoints() == 0
|| pImpl->iHumanState->getNumberOfJoints() != pImpl->iHumanState->getJointNames().size()) {
yError() << LogPrefix<<"The IHumanState interface might not be ready";
if(count--==0) return false;

if(yarp::os::Time::now()-interfaceCheckStart>INTERFACE_CHECK_TIMEOUT_S)
{
yError() << LogPrefix<<"The iHumanState interface has been providing inconsistent data for"<<INTERFACE_CHECK_TIMEOUT_S<<"seconds!";
return false;
}
}

yInfo() << LogPrefix << deviceName << "attach() successful";
Expand Down
16 changes: 12 additions & 4 deletions devices/HumanWrenchProvider/HumanWrenchProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

const std::string DeviceName = "HumanWrenchProvider";
const std::string LogPrefix = DeviceName + " :";

// Timeout in seconds for checking that the iHumanState interface is providing consistent data
constexpr double INTERFACE_CHECK_TIMEOUT_S = 10;

constexpr double DefaultPeriod = 0.01;

using namespace hde::devices;
Expand Down Expand Up @@ -1274,13 +1278,17 @@ bool HumanWrenchProvider::attach(yarp::dev::PolyDriver* poly)
return false;
}

//TODO Check the interface
// Check the iHumanState interface
double interfaceCheckStart = yarp::os::Time::now();
int count = 1000000;
while (pImpl->iHumanState->getNumberOfJoints() == 0
|| pImpl->iHumanState->getNumberOfJoints() != pImpl->iHumanState->getJointNames().size()) {
yError() << LogPrefix<<"The IHumanState interface might not be ready";
count--;
if(count==0) return false;

if(yarp::os::Time::now()-interfaceCheckStart>INTERFACE_CHECK_TIMEOUT_S)
{
yError() << LogPrefix<<"The iHumanState interface has been providing inconsistent data for"<<INTERFACE_CHECK_TIMEOUT_S<<"seconds!";
return false;
}
}

yInfo() << LogPrefix << deviceName << "attach() successful";
Expand Down

0 comments on commit 0b8881b

Please sign in to comment.