Skip to content

Commit

Permalink
ControlBoard: cache the coupled joints
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicogene committed Dec 16, 2024
1 parent 4955965 commit 995128f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion plugins/controlboard/include/ControlBoardData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ public:
std::mutex mutex;
std::vector<PhysicalJointProperties> physicalJoints;
std::vector<ActuatedAxisProperties> actuatedAxes;
yarp::sig::VectorOf<size_t> coupledActuatedAxes, coupledPhysicalJoints;
yarp::os::Stamp simTime;
yarp::dev::IJointCoupling* ijointcoupling{nullptr};
// TODO (xela95): read this value from configuration file
std::chrono::milliseconds controlUpdatePeriod = std::chrono::milliseconds(1);


bool initCoupledJoints();
bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode);
bool setControlMode(int j, int mode);
};
Expand Down
8 changes: 7 additions & 1 deletion plugins/controlboard/src/ControlBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,14 @@ bool ControlBoard::setJointProperties(EntityComponentManager& _ecm)

yInfo() << "Joint " << jointFromConfigName << " added to the control board data.";
}
if (!m_controlBoardData.initCoupledJoints())
{
yError() << "Error while initializing coupled joints";
return false;
}

// Let's initialize all the buffers/vectors
if(!configureBuffers()) {
if (!configureBuffers()) {
yError() << "Error while configuring buffers";
return false;
}
Expand Down
16 changes: 10 additions & 6 deletions plugins/controlboard/src/ControlBoardData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@

namespace gzyarp
{


bool ControlBoardData::initCoupledJoints() {
if (this->ijointcoupling) {
bool ok = this->ijointcoupling->getCoupledActuatedAxes(coupledActuatedAxes);
ok = ok & this->ijointcoupling->getCoupledPhysicalJoints(coupledPhysicalJoints);
return ok;
}
return true;
}
bool ControlBoardData::setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode)
{
yarp::sig::VectorOf<size_t> coupledActuatedAxes, coupledPhysicalJoints;
try
{
// If there is coupling let's check if we have to change the interaction mode for all the coupled joints
if (this->ijointcoupling)
{
this->ijointcoupling->getCoupledActuatedAxes(coupledActuatedAxes);
this->ijointcoupling->getCoupledPhysicalJoints(coupledPhysicalJoints);
// If the joint is coupled, we have to change the interaction mode for all the coupled joints
if(std::find(coupledActuatedAxes.begin(), coupledActuatedAxes.end(), axis) != coupledActuatedAxes.end())
{
Expand Down Expand Up @@ -79,12 +86,9 @@ bool ControlBoardData::setControlMode(int j, int mode) {
desired_mode = VOCAB_CM_IDLE;
}

yarp::sig::VectorOf<size_t> coupledActuatedAxes, coupledPhysicalJoints;
// If there is coupling let's check if we have to change the interaction mode for all the coupled joints
if (this->ijointcoupling)
{
this->ijointcoupling->getCoupledActuatedAxes(coupledActuatedAxes);
this->ijointcoupling->getCoupledPhysicalJoints(coupledPhysicalJoints);
// If the joint is coupled, we have to change the interaction mode for all the coupled joints
if(std::find(coupledActuatedAxes.begin(), coupledActuatedAxes.end(), j) != coupledActuatedAxes.end())
{
Expand Down

0 comments on commit 995128f

Please sign in to comment.