Skip to content
Snippets Groups Projects
Commit 185c2ffb authored by Mirko Wächter's avatar Mirko Wächter
Browse files

added mutex for robotstatehistory

parent 57c1a822
No related branches found
No related tags found
No related merge requests found
...@@ -230,8 +230,12 @@ namespace armarx ...@@ -230,8 +230,12 @@ namespace armarx
bool RobotStateComponent::interpolate(double time, RobotStateConfig& config) const bool RobotStateComponent::interpolate(double time, RobotStateConfig& config) const
{ {
boost::shared_lock<SharedMutex> lock(historyMutex);
auto it = history.lower_bound(time); auto it = history.lower_bound(time);
if (history.size() == 0)
{
return false;
}
if (time > history.rbegin()->first) if (time > history.rbegin()->first)
{ {
config = history.rbegin()->second; config = history.rbegin()->second;
...@@ -245,7 +249,7 @@ namespace armarx ...@@ -245,7 +249,7 @@ namespace armarx
config = it->second; config = it->second;
if (it->first == time) if (it->first == time)
{ {
// ARMARX_INFO_S << "No Interpolation needed: " << time; // ARMARX_INFO_S << "No Interpolation needed: " << time;
} }
else else
{ {
...@@ -256,7 +260,7 @@ namespace armarx ...@@ -256,7 +260,7 @@ namespace armarx
long deltaT = it->first - prevIt->first; long deltaT = it->first - prevIt->first;
double influenceNext = 1.0f - (double)(it->first - time) / deltaT; double influenceNext = 1.0f - (double)(it->first - time) / deltaT;
double influencePrev = 1.0f - (double)(time - prevIt->first) / deltaT; double influencePrev = 1.0f - (double)(time - prevIt->first) / deltaT;
// ARMARX_INFO_S << "Interpolating: " << time << " prev: " << time - prevIt->first << " next: " << it->first - time << VAROUT(influenceNext) << VAROUT(influencePrev) << " sum: " << (influenceNext + influencePrev); // ARMARX_INFO_S << "Interpolating: " << time << " prev: " << time - prevIt->first << " next: " << it->first - time << VAROUT(influenceNext) << VAROUT(influencePrev) << " sum: " << (influenceNext + influencePrev);
auto jointIt = prevIt->second.jointMap.begin(); auto jointIt = prevIt->second.jointMap.begin();
for (auto & joint : config.jointMap) for (auto & joint : config.jointMap)
{ {
...@@ -315,11 +319,11 @@ namespace armarx ...@@ -315,11 +319,11 @@ namespace armarx
{ {
_sharedRobotServant->setTimestamp(time); _sharedRobotServant->setTimestamp(time);
} }
boost::unique_lock<SharedMutex> lock(historyMutex);
history[time.toMicroSecondsDouble()] = {time.toMicroSecondsDouble(), history.insert(history.end(), std::make_pair(time.toMicroSecondsDouble(), RobotStateConfig {time.toMicroSecondsDouble(),
new FramedPose(_synchronized->getGlobalPose(), GlobalFrame, ""), new FramedPose(_synchronized->getGlobalPose(), GlobalFrame, ""),
jointAngles jointAngles
}; }));
if (history.size() > historyLength) if (history.size() > historyLength)
{ {
......
...@@ -171,6 +171,8 @@ namespace armarx ...@@ -171,6 +171,8 @@ namespace armarx
std::string robotFile; std::string robotFile;
std::string relativeRobotFile; std::string relativeRobotFile;
RobotStateObserverPtr robotStateObs; RobotStateObserverPtr robotStateObs;
mutable SharedMutex historyMutex;
std::map<double, RobotStateConfig> history; std::map<double, RobotStateConfig> history;
size_t historyLength; size_t historyLength;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment