Skip to content

Commit

Permalink
Merge pull request #3011 from randaz81/subdevice_removed
Browse files Browse the repository at this point in the history
Removed subdevice parameter in device wrappers implementations
  • Loading branch information
randaz81 authored Feb 7, 2024
2 parents 55d8319 + e3aa409 commit 0bf49fb
Show file tree
Hide file tree
Showing 29 changed files with 37 additions and 581 deletions.
6 changes: 3 additions & 3 deletions src/devices/controlBoardRemapper/ControlBoardRemapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ bool ControlBoardRemapper::attachAllUsingAxesNames(const PolyDriverList& polylis
if( !iencs ||
!iaxinfos )
{
yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required IAxisInfo or IEncoders interfaces";
yCError(CONTROLBOARDREMAPPER) << "sub-device" << deviceKey << "does not implemented the required IAxisInfo or IEncoders interfaces";
return false;
}

Expand All @@ -317,7 +317,7 @@ bool ControlBoardRemapper::attachAllUsingAxesNames(const PolyDriverList& polylis

if( !ok )
{
yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required getAxes method";
yCError(CONTROLBOARDREMAPPER) << "sub-device" << deviceKey << "does not implemented the required getAxes method";
return false;
}

Expand All @@ -330,7 +330,7 @@ bool ControlBoardRemapper::attachAllUsingAxesNames(const PolyDriverList& polylis

if( !ok )
{
yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required getAxisName method";
yCError(CONTROLBOARDREMAPPER) << "sub-device" << deviceKey << "does not implemented the required getAxisName method";
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -28,7 +28,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -26,7 +26,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -39,7 +39,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -51,7 +51,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -26,7 +26,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -51,7 +51,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -65,7 +65,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand All @@ -26,7 +26,7 @@
<param name="period"> 0.01 </param>
<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="subdevice"> lidarmotor </elem>
<elem name="subdev"> lidarmotor </elem>
</paramlist>
</action>
<action phase="shutdown" level="5" type="detach" />
Expand Down
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
26 changes: 0 additions & 26 deletions src/devices/frameGrabberCropper/frameGrabberCropper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,12 @@ bool FrameGrabberCropper::open(yarp::os::Searchable& config)
forwardRgbVisualParams = true;
}

if (config.check("subdevice")) {
yarp::os::Property p;
subdevice = new yarp::dev::PolyDriver;
p.fromString(config.toString());
p.unput("device");
p.put("device", config.find("subdevice").asString()); // subdevice was already checked before

// if errors occurred during open, quit here.
if (!subdevice->open(p) || !(subdevice->isValid())) {
yCError(FRAMEGRABBERCROPPER, "Could not open subdevice");
return false;
}

if (!attach(subdevice)) {
yCError(FRAMEGRABBERCROPPER, "Could not attach subdevice");
subdevice->close();
return false;
}
subdeviceOwned = true;
}

return true;
}


bool FrameGrabberCropper::close()
{
if (subdeviceOwned) {
subdevice->close();
delete subdevice;
subdevice = nullptr;
}
return true;
}

Expand Down
3 changes: 0 additions & 3 deletions src/devices/frameGrabberCropper/frameGrabberCropper.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class FrameGrabberCropper :
public yarp::dev::IRgbVisualParams,
public yarp::dev::IPreciselyTimed
{
yarp::dev::PolyDriver* subdevice{nullptr};
bool subdeviceOwned{false};

yarp::dev::IFrameGrabberControls* iFrameGrabberControls{nullptr};
yarp::dev::IFrameGrabberControlsDC1394* iFrameGrabberControlsDC1394{nullptr};
yarp::dev::IRgbVisualParams* iRgbVisualParams{nullptr};
Expand Down
88 changes: 0 additions & 88 deletions src/devices/networkWrappers/AnalogWrapper/AnalogWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,69 +247,12 @@ void AnalogWrapper::removeHandlers()
handlers.clear();
}

bool AnalogWrapper::openAndAttachSubDevice(Searchable &prop)
{
Property p;
subDeviceOwned = new PolyDriver;
p.fromString(prop.toString());

// p.setMonitor(prop.getMonitor(), "subdevice"); // pass on any monitoring
p.unput("device");
p.put("device", prop.find("subdevice").asString()); // subdevice was already checked before

// if errors occurred during open, quit here.
yCDebug(ANALOGWRAPPER, "opening AnalogWrapper subdevice...");
subDeviceOwned->open(p);

if (!subDeviceOwned->isValid())
{
yCError(ANALOGWRAPPER, "opening AnalogWrapper subdevice... FAILED\n");
return false;
}

subDeviceOwned->view(analogSensor_p);

if (analogSensor_p == nullptr)
{
yCError(ANALOGWRAPPER, "Opening IAnalogSensor interface of AnalogWrapper subdevice... FAILED\n");
return false;
}

int chNum = analogSensor_p->getChannels();

if (chNum <= 0)
{
yCError(ANALOGWRAPPER, "Calling analog sensor has invalid channels number %d.\n", chNum);
return false;
}

attach(analogSensor_p);
PeriodicThread::setPeriod(_rate / 1000.0);
return PeriodicThread::start();
}


bool AnalogWrapper::openDeferredAttach(yarp::os::Searchable &prop)
{
// nothing to do here?
if ((subDeviceOwned != nullptr) || (ownDevices == true)) {
yCError(ANALOGWRAPPER) << "AnalogWrapper: something wrong with the initialization.";
}
return true;
}


/**
* Specify which analog sensor this thread has to read from.
*/

bool AnalogWrapper::attachAll(const PolyDriverList &analog2attach)
{
//check if we already instantiated a subdevice previously
if (ownDevices) {
return false;
}

if (analog2attach.size() != 1)
{
yCError(ANALOGWRAPPER, "AnalogWrapper: cannot attach more than one device");
Expand All @@ -335,11 +278,6 @@ bool AnalogWrapper::attachAll(const PolyDriverList &analog2attach)

bool AnalogWrapper::detachAll()
{
//check if we already instantiated a subdevice previously
if (ownDevices) {
return false;
}

analogSensor_p = nullptr;
for(unsigned int i=0; i<analogPorts.size(); i++)
{
Expand Down Expand Up @@ -433,25 +371,6 @@ bool AnalogWrapper::open(yarp::os::Searchable &config)
return false;
}

// check if we need to create subdevice or if they are
// passed later on thorugh attachAll()
if(config.check("subdevice"))
{
ownDevices=true;
if(! openAndAttachSubDevice(config))
{
yCError(ANALOGWRAPPER, "AnalogWrapper: error while opening subdevice\n");
return false;
}
}
else
{
ownDevices=false;
if (!openDeferredAttach(config)) {
return false;
}
}

return true;
}

Expand Down Expand Up @@ -623,12 +542,5 @@ bool AnalogWrapper::close()
detachAll();
removeHandlers();

if(subDeviceOwned)
{
subDeviceOwned->close();
delete subDeviceOwned;
subDeviceOwned = nullptr;
}

return true;
}
10 changes: 0 additions & 10 deletions src/devices/networkWrappers/AnalogWrapper/AnalogWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class AnalogPortEntry;
* |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:-----------------------------------------------------------------:|:-----:|
* | name | - | string | - | - | Yes | full name of the port opened by the device, like /robotName/part/ | MUST start with a '/' character |
* | period | - | int | ms | 20 | No | refresh period of the broadcasted values in ms | optional, default 20ms |
* | subdevice | - | string | - | - | alternative to netwok group | name of the subdevice to instantiate | when used, parameters for the subdevice must be provided as well |
* | ports | - | group | - | - | alternative to subdevice | this is expected to be a group parameter in xml format, a list in .ini file format. SubParameter are mandatory if this is used| - |
* | - | portName_1 | 4 * int | channel number | - | if ports is used | describe how to match subdevice_1 channels with the wrapper channels. First 2 numbers indicate first/last wrapper channel, last 2 numbers are subdevice first/last channel | The channels are intended to be consequent |
* | - | ... | 4 * int | channel number | - | if ports is used | same as above | The channels are intended to be consequent |
Expand Down Expand Up @@ -162,15 +161,6 @@ class AnalogWrapper :
int _rate{DEFAULT_THREAD_PERIOD};
std::string sensorId;

bool ownDevices{false};
// Open the wrapper only, the attach method needs to be called before using it
bool openDeferredAttach(yarp::os::Searchable &prop);

// For the simulator, if a subdevice parameter is given to the wrapper, it will
// open it and attach to it immediately.
yarp::dev::PolyDriver *subDeviceOwned{nullptr};
bool openAndAttachSubDevice(yarp::os::Searchable &prop);

bool initialize_YARP(yarp::os::Searchable &config);
void setHandlers();
void removeHandlers();
Expand Down
Loading

0 comments on commit 0bf49fb

Please sign in to comment.