Skip to content

Commit

Permalink
Merge pull request #3153 from robotology/FakeMotionControl_timestamp
Browse files Browse the repository at this point in the history
FakeMotionControl encoders timestamps
  • Loading branch information
randaz81 authored Dec 3, 2024
2 parents 3636677 + 0d3cdff commit 40e3ef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/devices/fake/fakeMotionControl/FakeMotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void FakeMotionControl::run()
{
std::lock_guard lock(_mutex);

_cycleTimestamp = yarp::os::Time::now();

for (int i=0;i <_njoints ;i++)
{
if (_controlModes[i] == VOCAB_CM_VELOCITY)
Expand Down Expand Up @@ -1694,7 +1696,7 @@ bool FakeMotionControl::getEncodersTimedRaw(double *encs, double *stamps)
bool ret = getEncodersRaw(encs);
_mutex.lock();
for (int i = 0; i < _njoints; i++) {
stamps[i] = _encodersStamp[i];
stamps[i] = _encodersStamp[i] = _cycleTimestamp;
}
_mutex.unlock();
return ret;
Expand All @@ -1704,7 +1706,7 @@ bool FakeMotionControl::getEncoderTimedRaw(int j, double *encs, double *stamp)
{
bool ret = getEncoderRaw(j, encs);
_mutex.lock();
*stamp = _encodersStamp[j];
*stamp = _encodersStamp[j] = _cycleTimestamp;
_mutex.unlock();

return ret;
Expand Down Expand Up @@ -1802,7 +1804,7 @@ bool FakeMotionControl::getMotorEncodersTimedRaw(double *encs, double *stamps)
bool ret = getMotorEncodersRaw(encs);
_mutex.lock();
for (int i = 0; i < _njoints; i++) {
stamps[i] = _encodersStamp[i];
stamps[i] = _encodersStamp[i] = _cycleTimestamp;
}
_mutex.unlock();

Expand All @@ -1813,7 +1815,7 @@ bool FakeMotionControl::getMotorEncoderTimedRaw(int m, double *encs, double *sta
{
bool ret = getMotorEncoderRaw(m, encs);
_mutex.lock();
*stamp = _encodersStamp[m];
*stamp = _encodersStamp[m] = _cycleTimestamp;
_mutex.unlock();

return ret;
Expand Down
1 change: 1 addition & 0 deletions src/devices/fake/fakeMotionControl/FakeMotionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class FakeMotionControl :
};

std::recursive_mutex _mutex;
double _cycleTimestamp;
int _njoints;
int *_axisMap; /** axis remapping lookup-table */
double *_angleToEncoder; /** angle to iCubDegrees conversion factors */
Expand Down

0 comments on commit 40e3ef2

Please sign in to comment.