Skip to content

Commit

Permalink
Check if the encoders timestamps are consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed May 18, 2022
1 parent 225ed49 commit 5ca0b54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/devices/ControlBoardWrapper/ControlBoard_nws_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ControlBoardLogComponent.h"

#include <numeric>
#include <math.h>

using namespace yarp::os;
using namespace yarp::dev;
Expand Down Expand Up @@ -72,7 +73,7 @@ bool ControlBoard_nws_ros::open(Searchable& config)
}

// Check if we need to create subdevice or if they are
// passed later on thorugh attachAll()
// passed later on through attachAll()
if (prop.check("subdevice")) {
prop.setMonitor(config.getMonitor());
if (!openAndAttachSubDevice(prop)) {
Expand Down Expand Up @@ -310,6 +311,17 @@ void ControlBoard_nws_ros::run()
YARP_UNUSED(torqueOk);
}

// Check if the encoders timestamps are consistent.
double tt = *times.data();
for (auto it = times.begin(); it != times.end(); it++)
{
if (fabs(tt - *it) > 1.0)
{
yCError(CONTROLBOARD, "Encoder Timestamps are not consistent! Data will not be published.");
return;
}
}

// Update the port envelope time by averaging all timestamps
time.update(std::accumulate(times.begin(), times.end(), 0.0) / subdevice_joints);
yarp::os::Stamp averageTime = time;
Expand Down
15 changes: 13 additions & 2 deletions src/devices/ControlBoardWrapper/ControlBoard_nws_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <yarp/dev/impl/jointData.h>

#include <numeric>

#include <math.h>

using namespace yarp::os;
using namespace yarp::dev;
Expand Down Expand Up @@ -112,7 +112,7 @@ bool ControlBoard_nws_yarp::open(Searchable& config)
}

// Check if we need to create subdevice or if they are
// passed later on thorugh attachAll()
// passed later on through attachAll()
if (prop.check("subdevice")) {
prop.setMonitor(config.getMonitor());
if (!openAndAttachSubDevice(prop)) {
Expand Down Expand Up @@ -440,6 +440,17 @@ void ControlBoard_nws_yarp::run()
yCWarning(CONTROLBOARD) << "Number of streaming input messages to be read is " << inputStreamingPort.getPendingReads() << " and can overflow";
}

// Check if the encoders timestamps are consistent.
double tt = *times.data();
for (auto it = times.begin(); it != times.end(); it++)
{
if (fabs(tt - *it) > 1.0)
{
yCError(CONTROLBOARD, "Encoder Timestamps are not consistent! Data will not be published.");
return;
}
}

// Update the port envelope time by averaging all timestamps
time.update(std::accumulate(times.begin(), times.end(), 0.0) / subdevice_joints);
yarp::os::Stamp averageTime = time;
Expand Down

0 comments on commit 5ca0b54

Please sign in to comment.