Skip to content

Commit

Permalink
IJointCoupling: make all methods return bools
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicogene committed Oct 27, 2023
1 parent ccc9245 commit 882fa28
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
21 changes: 12 additions & 9 deletions src/libYARP_dev/src/yarp/dev/IJointCoupling.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,39 @@ class YARP_dev_API yarp::dev::IJointCoupling
/**
* @brief Return the vector of "physical joints indices" (i.e. numbers from 0 to n-1)
* that are related to actuated axis in a non-obvious way
*
* @return the vector of "physical joints indices"
* @param[out] coupPhysJointsIndexes the vector of "physical joints indices"
* @return true/false on success/failure
*/
virtual yarp::sig::VectorOf<size_t> getCoupledPhysicalJoints()=0;
virtual bool getCoupledPhysicalJoints(yarp::sig::VectorOf<size_t>& coupPhysJointsIndexes)=0;

/**
* @brief Return the vector of "actuator axis indices" (i.e. numbers from 0 to m-1)
* that are related to physical joints in a non-obvious way
*
* @return teh vector of "actuator axis indices"
* @param[out] coupActAxesIndexes the vector of "actuator axis indices"
* @return true/false on success/failure
*/
virtual yarp::sig::VectorOf<size_t> getCoupledActuatedAxes()=0;
virtual bool getCoupledActuatedAxes(yarp::sig::VectorOf<size_t>& coupActAxesIndexes)=0;

/**
* @brief Get the name of an actuated axis
*
* @param[in] actuatedAxisIndex the number from 0 to m-1 that identifies
* the location of a "actuated axis" in a actuated axis vector.
* @return the actuated axis name
* @param[out] actuatedAxisName the actuated axis name
* @return true/false on success/failure
*/
virtual std::string getActuatedAxisName(size_t actuatedAxisIndex)=0;
virtual bool getActuatedAxisName(size_t actuatedAxisIndex, std::string& actuatedAxisName)=0;

/**
* @brief Get the name of a physical joint
*
* @param[in] physicalJointIndex the number from 0 to n-1 that identifies
* the location of a "physical joint" in a physical joint vector
* @return the physical joint name
* @param[out] physicalJointName the physical joint name
* @return true/false on success/failure
*/
virtual std::string getPhysicalJointName(size_t physicalJointIndex)=0;
virtual bool getPhysicalJointName(size_t physicalJointIndex, std::string& physicalJointName)=0;

/**
* @brief Get the Physical Joint Limit object
Expand Down
32 changes: 19 additions & 13 deletions src/libYARP_dev/src/yarp/dev/ImplementJointCoupling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void ImplementJointCoupling::initialise(yarp::sig::VectorOf<size_t> physical_joi
for (std::size_t i = 0, j = 0; i < physical_joints.size(); i++)
{
const int physical_joint_index = physical_joints(i);
const std::string physical_joint_name = getPhysicalJointName(physical_joint_index);
std::string physical_joint_name {""};
auto ok = getPhysicalJointName(physical_joint_index, physical_joint_name);
if (physical_joint_name != "invalid" && physical_joint_name != "reserved")
{
m_physicalJointLimits[physical_joints[i]] = physical_joint_limits[j];
Expand All @@ -36,16 +37,17 @@ void ImplementJointCoupling::initialise(yarp::sig::VectorOf<size_t> physical_joi

}


yarp::sig::VectorOf<size_t> ImplementJointCoupling::getCoupledPhysicalJoints() {
return m_physicalJoints;
bool ImplementJointCoupling::getCoupledPhysicalJoints(yarp::sig::VectorOf<size_t>& coupPhysJointsIndexes) {
coupPhysJointsIndexes = m_physicalJoints;
return true;
}

yarp::sig::VectorOf<size_t> ImplementJointCoupling::getCoupledActuatedAxes() {
return m_actuatedAxes;
bool ImplementJointCoupling::getCoupledActuatedAxes(yarp::sig::VectorOf<size_t>& coupActAxesIndexes) {
coupActAxesIndexes = m_actuatedAxes;
return true;
}

std::string ImplementJointCoupling::getPhysicalJointName(size_t physicalJointIndex){
bool ImplementJointCoupling::getPhysicalJointName(size_t physicalJointIndex, std::string& physicalJointName){
int c_joint = -1;
// TODO refactor also here
for (size_t i = 0; i < m_physicalJoints.size(); ++i)
Expand All @@ -55,27 +57,31 @@ std::string ImplementJointCoupling::getPhysicalJointName(size_t physicalJointInd

if (c_joint >= 0 && static_cast<size_t>(c_joint) < m_physicalJoints.size())
{
return m_physicalJointNames[c_joint];
physicalJointName = m_physicalJointNames[c_joint];
return true;
}
else
{
return std::string("invalid");
physicalJointName = "invalid";
return false;
}
}

std::string ImplementJointCoupling::getActuatedAxisName(size_t actuatedAxisIndex){
bool ImplementJointCoupling::getActuatedAxisName(size_t actuatedAxisIndex, std::string& actuatedAxisName){
// TODO is it right?
return m_actuatedAxesNames[actuatedAxisIndex];
actuatedAxisName = m_actuatedAxesNames[actuatedAxisIndex];
return true;
}

bool ImplementJointCoupling::checkPhysicalJointIsCoupled(size_t physicalJointIndex){
return std::find(m_physicalJoints.begin(), m_physicalJoints.end(), physicalJointIndex) != m_physicalJoints.end();
}

bool ImplementJointCoupling::getPhysicalJointLimits(size_t physicalJointIndex, double& min, double& max){
const std::string physical_joint_name = getPhysicalJointName(physicalJointIndex);
std::string physical_joint_name{""};
auto ok = getPhysicalJointName(physicalJointIndex, physical_joint_name);

if (physical_joint_name != "reserved" && physical_joint_name != "gyp_invalid")
if (physical_joint_name != "reserved" && physical_joint_name != "invalid")
{
min = m_physicalJointLimits.at(physicalJointIndex).first;
max = m_physicalJointLimits.at(physicalJointIndex).second;
Expand Down
8 changes: 4 additions & 4 deletions src/libYARP_dev/src/yarp/dev/ImplementJointCoupling.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class YARP_dev_API yarp::dev::ImplementJointCoupling: public IJointCoupling
std::vector<std::string> actuated_axes_names,
std::vector<std::pair<double, double>> physical_joint_limits);

yarp::sig::VectorOf<size_t> getCoupledPhysicalJoints() override final;
yarp::sig::VectorOf<size_t> getCoupledActuatedAxes() override final;
std::string getPhysicalJointName(size_t physicalJointIndex) override final;
std::string getActuatedAxisName(size_t actuatedAxisIndex) override final;
bool getCoupledPhysicalJoints(yarp::sig::VectorOf<size_t>& coupPhysJointsIndexes) override final;
bool getCoupledActuatedAxes(yarp::sig::VectorOf<size_t>& coupActAxesIndexes) override final;
bool getPhysicalJointName(size_t physicalJointIndex, std::string& physicalJointName) override final;
bool getActuatedAxisName(size_t actuatedAxisIndex, std::string& actuatedAxisName) override final;

bool getPhysicalJointLimits(size_t physicalJointIndex, double& min, double& max) override final;
protected:
Expand Down

0 comments on commit 882fa28

Please sign in to comment.