Skip to content

Commit

Permalink
Throttle error message on inconsistent encoder timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Nov 28, 2022
1 parent a00b1e6 commit 41e406e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
12 changes: 12 additions & 0 deletions doc/release/yarp_3_7/throttle_consistency_checker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
throttle_consistency_checker {#yarp_3_7}
-----------

### Devices

#### `controlBoard_nws_yarp`

* The error message upon inconsistent encoder timestamps has been throttled.

#### `controlBoard_nws_ros`

* Now using a consistency checker mechanism like the nws_yarp counterpart.
9 changes: 4 additions & 5 deletions src/devices/ControlBoardWrapper/ControlBoard_nws_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "ControlBoardLogComponent.h"

#include <cmath> // std::abs
#include <numeric>
#include <math.h>

using namespace yarp::os;
using namespace yarp::dev;
Expand Down Expand Up @@ -312,12 +312,11 @@ void ControlBoard_nws_ros::run()
}

// Check if the encoders timestamps are consistent.
double tt = *times.data();
for (auto it = times.begin(); it != times.end(); it++)
for (double tt : times)
{
if (fabs(tt - *it) > 1.0)
if (std::abs(times[0] - tt) > 1.0)
{
yCError(CONTROLBOARD, "Encoder Timestamps are not consistent! Data will not be published.");
yCErrorThrottle(CONTROLBOARD, 1.0, "Encoder timestamps are not consistent! Data will not be published.");
return;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/devices/ControlBoardWrapper/ControlBoard_nws_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ void ControlBoard_nws_yarp::run()
{
if (std::abs(times[0] - tt) > 1.0)
{
yCError(CONTROLBOARD, "Encoder Timestamps are not consistent! Data will not be published.");
yarp::sig::Vector _data(subdevice_joints);
yCErrorThrottle(CONTROLBOARD, 1.0, "Encoder timestamps are not consistent! Data will not be published.");
return;
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/devices/ControlBoard_nws_ros/ControlBoard_nws_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <yarp/rosmsg/impl/yarpRosHelper.h>

#include <cmath> // std::abs
#include <numeric>

using namespace yarp::os;
Expand Down Expand Up @@ -74,7 +75,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 @@ -312,6 +313,16 @@ void ControlBoard_nws_ros::run()
YARP_UNUSED(torqueOk);
}

// Check if the encoders timestamps are consistent.
for (double tt : times)
{
if (std::abs(times[0] - tt) > 1.0)
{
yCErrorThrottle(CONTROLBOARD, 1.0, "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 41e406e

Please sign in to comment.