Skip to content

Commit

Permalink
fixed regression issue in controlBoard_nws_yarp
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Feb 6, 2024
1 parent 994722a commit 64b8066
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
6 changes: 2 additions & 4 deletions src/devices/fake/fakeMotionControl/fakeMotionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ struct ImpedanceParameters
/**
* @ingroup dev_impl_fake dev_impl_motor
*
* \brief `fakeMotionControl`: Documentation to be added
*
* The aim of this device is to mimic the expected behavior of a
* \brief `fakeMotionControl`: The aim of this device is to mimic the expected behavior of a
* real motion control device to help testing the high level software.
*
* This device is implementing last version of interfaces and it is compatible
* with controlBoard_nws_yarp device.
*
* WIP - it is very basic now, not all interfaces are implemented yet.
* WIP - Some interfaces could be not implemented.
*/
class FakeMotionControl :
public yarp::dev::DeviceDriver,
Expand Down
10 changes: 2 additions & 8 deletions src/devices/fake/fakeMotionControlMicro/fakeMotionControlMicro.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@
/**
* @ingroup dev_impl_fake dev_impl_motor
*
* \brief `fakeMotionControlMicro`: Documentation to be added
* \brief `fakeMotionControlMicro`: This device implements a minimal subset of mandatory interfaces
* to run with controlBoard_nws_yarp. It is thus a smaller, limited version than fakeMotionControl.
*
* The aim of this device is to mimic the expected behavior of a
* real motion control device to help testing the high level software.
*
* This device is implementing last version of interfaces and it is compatible
* with controlBoard_nws_yarp device.
*
* WIP - it is very basic now, not all interfaces are implemented yet.
*/
class FakeMotionControlMicro :
public yarp::os::PeriodicThread,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ bool ControlBoard_nws_yarp::setDevice(yarp::dev::DeviceDriver* driver, bool owne
// yarp::dev::IPositionControl* iPositionControl{nullptr};
subdevice_ptr->view(iPositionControl);
if (!iPositionControl) {
yCError(CONTROLBOARD, "Part <%s>: IPositionControl interface was not found in subdevice. Quitting", partName.c_str());
return false;
yCWarning(CONTROLBOARD, "Part <%s>: IPositionControl interface was not found in subdevice.", partName.c_str());
}

// yarp::dev::IPositionDirect* iPositionDirect{nullptr};
Expand All @@ -196,15 +195,13 @@ bool ControlBoard_nws_yarp::setDevice(yarp::dev::DeviceDriver* driver, bool owne
// yarp::dev::IVelocityControl* iVelocityControl{nullptr};
subdevice_ptr->view(iVelocityControl);
if (!iVelocityControl) {
yCError(CONTROLBOARD, "Part <%s>: IVelocityControl interface was not found in subdevice. Quitting", partName.c_str());
return false;
yCWarning(CONTROLBOARD, "Part <%s>: IVelocityControl interface was not found in subdevice.", partName.c_str());
}

// yarp::dev::IEncodersTimed* iEncodersTimed{nullptr};
subdevice_ptr->view(iEncodersTimed);
if (!iEncodersTimed) {
yCError(CONTROLBOARD, "Part <%s>: IEncodersTimed interface was not found in subdevice. Quitting", partName.c_str());
return false;
yCWarning(CONTROLBOARD, "Part <%s>: IEncodersTimed interface was not found in subdevice.", partName.c_str());
}

// yarp::dev::IMotor* iMotor{nullptr};
Expand Down Expand Up @@ -291,13 +288,37 @@ bool ControlBoard_nws_yarp::setDevice(yarp::dev::DeviceDriver* driver, bool owne
yCWarning(CONTROLBOARD, "Part <%s>: ICurrentControl interface was not found in subdevice.", partName.c_str());
}


// Get the number of controlled joints
int tmp_axes;
if (!iPositionControl->getAxes(&tmp_axes)) {
yCError(CONTROLBOARD) << "Part <%s>: Failed to get axes number for subdevice " << partName.c_str();
return false;
int tmp_axes = 0;
if (iAxisInfo)
{
if (!iAxisInfo->getAxes(&tmp_axes)) {
yCError(CONTROLBOARD) << "Part <%s>: iAxisInfo->getAxes() failed for subdevice " << partName.c_str();
return false;
}
}
else if (iEncodersTimed)
{
if (!iEncodersTimed->getAxes(&tmp_axes)) {
yCError(CONTROLBOARD) << "Part <%s>: iEncodersTimed->getAxes() failed for subdevice " << partName.c_str();
return false;
}
}
else if (iPositionControl)
{
if (!iPositionControl->getAxes(&tmp_axes)) {
yCError(CONTROLBOARD) << "Part <%s>: iPositionControl->getAxes() failed for subdevice " << partName.c_str();
return false;
}
}
else if (iVelocityControl)
{
if (!iVelocityControl->getAxes(&tmp_axes)) {
yCError(CONTROLBOARD) << "Part <%s>: iVelocityControl->getAxes() failed for subdevice " << partName.c_str();
return false;
}
}

if (tmp_axes <= 0) {
yCError(CONTROLBOARD, "Part <%s>: attached device has an invalid number of joints (%d)", partName.c_str(), tmp_axes);
return false;
Expand Down Expand Up @@ -386,9 +407,8 @@ void ControlBoard_nws_yarp::run()
// check we are not overflowing with input messages
constexpr int reads_for_warning = 20;
if (inputStreamingPort.getPendingReads() >= reads_for_warning) {
yCWarning(CONTROLBOARD) << "Number of streaming input messages to be read is " << inputStreamingPort.getPendingReads() << " and can overflow";
yCIWarning(CONTROLBOARD, id()) << "Number of streaming input messages to be read is " << inputStreamingPort.getPendingReads() << " and can overflow";
}

// handle stateExt first
jointData& data = extendedOutputState_buffer.get();

Expand Down Expand Up @@ -462,8 +482,7 @@ void ControlBoard_nws_yarp::run()
{
if (std::abs(times[0] - tt) > 1.0)
{
yCError(CONTROLBOARD, "Encoder Timestamps are not consistent! Data will not be published.");
yarp::sig::Vector _data(subdevice_joints);
yCIErrorThrottle(CONTROLBOARD, id(), 1.0) << "Encoder timestamps are not consistent! Data will not be published.";
return;
}
}
Expand Down

0 comments on commit 64b8066

Please sign in to comment.