Skip to content

Commit

Permalink
Don't attach disabled external encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Jan 22, 2024
1 parent 9b8e3ec commit 32ec086
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions libraries/YarpPlugins/TechnosoftIpos/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ bool TechnosoftIposBase::open(yarp::os::Searchable & config)
}
}

if (yarp::os::Value * val; iposGroup.check("disabledEncoders", val, "disabled encoder IDs") && val->isList())
{
const auto * ids = val->asList();

for (int i = 0; i < ids->size(); i++)
{
disabledEncoderIds.push_back(ids->get(i).asInt32());
}
}

return true;
}

Expand Down
15 changes: 13 additions & 2 deletions libraries/YarpPlugins/TechnosoftIpos/IWrapperImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

#include "TechnosoftIposBase.hpp"

using namespace roboticslab;
#include <algorithm> // std::find_if
#include <string>

#include <yarp/os/LogStream.h>

#include "LogComponent.hpp"

using namespace roboticslab;

// -----------------------------------------------------------------------------

bool TechnosoftIposBase::attach(yarp::dev::PolyDriver * driver)
{
if (auto it = std::find_if(disabledEncoderIds.begin(), disabledEncoderIds.end(),
[driver](int id) { return "ID" + std::to_string(id) == driver->id(); });
it != disabledEncoderIds.end())
{
yCIInfo(IPOS, id()) << "Skipping attach of disabled external encoder" << driver->id();
return true;
}

if (!driver->view(iEncodersTimedRawExternal))
{
yCIError(IPOS, id()) << "Unable to view IEncodersTimedRaw in" << driver->id();
Expand All @@ -24,7 +35,7 @@ bool TechnosoftIposBase::attach(yarp::dev::PolyDriver * driver)
return false;
}

return false;
return true;
}

// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions libraries/YarpPlugins/TechnosoftIpos/TechnosoftIposBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <bitset>
#include <memory>
#include <string>
#include <vector>

#include <yarp/conf/numeric.h>

Expand Down Expand Up @@ -592,6 +593,8 @@ class TechnosoftIposBase : public yarp::dev::DeviceDriver,

yarp::os::Timer * monitorThread {nullptr};
roboticslab::ICanSenderDelegate * sender {nullptr};

std::vector<int> disabledEncoderIds;
};

} // namespace roboticslab
Expand Down

0 comments on commit 32ec086

Please sign in to comment.