Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit a3b765d

Browse files
authored
Merge pull request #279 from robotology/streamImprovedFT
added feature to open ports to stream the filteredFT sensor values af…
2 parents 001ae92 + df16229 commit a3b765d

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

src/devices/wholeBodyDynamics/WholeBodyDynamicsDevice.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const double wholeBodyDynamics_sensorTimeoutInSeconds = 2.0;
2727

2828
WholeBodyDynamicsDevice::WholeBodyDynamicsDevice(): RateThread(10),
2929
portPrefix("/wholeBodyDynamics"),
30+
streamFilteredFT(false),
3031
correctlyConfigured(false),
3132
sensorReadCorrectly(false),
3233
estimationWentWell(false),
@@ -116,6 +117,19 @@ bool WholeBodyDynamicsDevice::closeExternalWrenchesPorts()
116117
return true;
117118
}
118119

120+
bool WholeBodyDynamicsDevice::closeFilteredFTPorts()
121+
{
122+
for(unsigned int i = 0; i < outputFTPorts.size(); i++ )
123+
{
124+
if( outputFTPorts[i] )
125+
{
126+
outputFTPorts[i]->close();
127+
outputFTPorts[i].reset();
128+
}
129+
}
130+
return true;
131+
}
132+
119133

120134

121135
void addVectorOfStringToProperty(yarp::os::Property& prop, std::string key, std::vector<std::string> & list)
@@ -508,6 +522,33 @@ bool WholeBodyDynamicsDevice::openExternalWrenchesPorts(os::Searchable& config)
508522
return ok;
509523
}
510524

525+
bool WholeBodyDynamicsDevice::openFilteredFTPorts(os::Searchable& config)
526+
{
527+
bool ok = true;
528+
// create port names
529+
530+
std::string sensorName;
531+
std::string portName;
532+
outputFTPorts.resize(estimator.sensors().getNrOfSensors(iDynTree::SIX_AXIS_FORCE_TORQUE));
533+
for(int ft=0; ft < estimator.sensors().getNrOfSensors(iDynTree::SIX_AXIS_FORCE_TORQUE); ft++ )
534+
{
535+
sensorName= estimator.sensors().getSensor(iDynTree::SIX_AXIS_FORCE_TORQUE,ft)->getName() ;
536+
537+
yInfo() << "wholeBodyDynamics: creating port name and opening port for " << sensorName;
538+
539+
portName=(portPrefix+"/filteredFT/"+sensorName);
540+
outputFTPorts[ft]=std::make_unique<yarp::os::BufferedPort<yarp::sig::Vector> >();
541+
ok = ok && outputFTPorts[ft]->open(portName);
542+
}
543+
544+
if( !ok )
545+
{
546+
yError() << "wholeBodyDynamics impossible to open port for publishing filtered ft wrenches";
547+
return false;
548+
}
549+
return ok;
550+
}
551+
511552

512553
void WholeBodyDynamicsDevice::resizeBuffers()
513554
{
@@ -638,6 +679,14 @@ bool WholeBodyDynamicsDevice::loadSettingsFromConfig(os::Searchable& config)
638679
portPrefix = prop.find("portPrefix").asString();
639680
}
640681

682+
// Enable or disable ft streaming. The default value is false;
683+
// is set in the device constructor
684+
if( prop.check("streamFilteredFT") &&
685+
prop.find("streamFilteredFT").isBool())
686+
{
687+
streamFilteredFT = prop.find("streamFilteredFT").asBool();
688+
}
689+
641690
std::string useJointVelocityOptionName = "useJointVelocity";
642691
if( !(prop.check(useJointVelocityOptionName.c_str()) && prop.find(useJointVelocityOptionName.c_str()).isBool()) )
643692
{
@@ -904,6 +953,15 @@ bool WholeBodyDynamicsDevice::open(os::Searchable& config)
904953
return false;
905954
}
906955

956+
// Open the ports related to publishing filtered ft wrenches
957+
if (streamFilteredFT){
958+
ok = this->openFilteredFTPorts(config);
959+
if( !ok )
960+
{
961+
yError() << "wholeBodyDynamics: Problem in opening filtered ft ports.";
962+
return false;
963+
}
964+
}
907965

908966
return true;
909967
}
@@ -1601,7 +1659,9 @@ void WholeBodyDynamicsDevice::publishEstimatedQuantities()
16011659
//publishFilteredInertialForGravityCompensator();
16021660

16031661
//Send filtered force torque sensor measurment, if requested
1604-
//publishFilteredFTWithoutOffset();
1662+
if( streamFilteredFT){
1663+
publishFilteredFTWithoutOffset();
1664+
}
16051665
}
16061666
}
16071667
}
@@ -1736,6 +1796,23 @@ void WholeBodyDynamicsDevice::publishExternalWrenches()
17361796
}
17371797
}
17381798

1799+
void WholeBodyDynamicsDevice::publishFilteredFTWithoutOffset()
1800+
{
1801+
1802+
iDynTree::Wrench filteredFTMeasure;
1803+
yarp::sig::Vector filteredFT;
1804+
// Get filtered wrenches and publish it on the port
1805+
for(int ft=0; ft <outputFTPorts.size(); ft++ )
1806+
{
1807+
filteredSensorMeasurements.getMeasurement(iDynTree::SIX_AXIS_FORCE_TORQUE,ft,filteredFTMeasure);
1808+
iDynTree::toYarp(filteredFTMeasure,filteredFT);
1809+
broadcastData<yarp::sig::Vector>(filteredFT,
1810+
*(outputFTPorts[ft]));
1811+
1812+
}
1813+
1814+
}
1815+
17391816
void WholeBodyDynamicsDevice::run()
17401817
{
17411818
yarp::os::LockGuard guard(this->deviceMutex);
@@ -1786,6 +1863,7 @@ bool WholeBodyDynamicsDevice::detachAll()
17861863
this->remappedControlBoardInterfaces.multwrap->detachAll();
17871864
this->remappedVirtualAnalogSensorsInterfaces.multwrap->detachAll();
17881865

1866+
closeFilteredFTPorts();
17891867
closeExternalWrenchesPorts();
17901868
closeRPCPort();
17911869
closeSettingsPort();

src/devices/wholeBodyDynamics/WholeBodyDynamicsDevice.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class wholeBodyDynamicsDeviceFilters
131131
* | defaultContactFrames | - | vector of strings | - | - | Yes | If not data is read from the skin, specify the location of the default contacts | For each submodel induced by the FT sensor, the first not used frame that belongs to that submodel is selected from the list. An error is raised if not suitable frame is found for a submodel. |
132132
* | useJointVelocity | - | bool | - | true | No | Select if the measured joint velocities (read from the getEncoderSpeeds method) are used for estimation, or if they should be forced to 0.0 . | The default value of true is deprecated, and in the future the parameter will be required. |
133133
* | useJointAcceleration | - | bool | - | true | No | Select if the measured joint accelerations (read from the getEncoderAccelerations method) are used for estimation, or if they should be forced to 0.0 . | The default value of true is deprecated, and in the future the parameter will be required. |
134+
* | streamFilteredFT | - | bool | - | false | No | Select if the filtered and offset removed forces will be streamed or not. The name of the ports have the following syntax: portname=(portPrefix+"/filteredFT/"+sensorName). Example: "myPrefix/filteredFT/l_leg_ft_sensor" | The value streamed by this ports is affected by the secondary calibration matrix, the estimated offset and temperature coefficients ( if any ). |
134135
* | IDYNTREE_SKINDYNLIB_LINKS | - | group | - | - | Yes | Group describing the mapping between link names and skinDynLib identifiers. | |
135136
* | | linkName_1 | string (name of a link in the model) | - | - | Yes | Bottle of three elements describing how the link with linkName is described in skinDynLib: the first element is the name of the frame in which the contact info is expressed in skinDynLib (tipically DH frames), the second a integer describing the skinDynLib BodyPart , and the third a integer describing the skinDynLib LinkIndex | |
136137
* | | ... | string (name of a link in the model) | - | - | Yes | Bottle of three elements describing how the link with linkName is described in skinDynLib: the first element is the name of the frame in which the contact info is expressed in skinDynLib (tipically DH frames), the second a integer describing the skinDynLib BodyPart , and the third a integer describing the skinDynLib LinkIndex | |
@@ -314,6 +315,12 @@ class WholeBodyDynamicsDevice : public yarp::dev::DeviceDriver,
314315
*/
315316
double lastReadingSkinContactListStamp;
316317

318+
/**
319+
* Flag set to false at the beginning, and true depending on configuration flag
320+
* If true it will stream the filtered ft sensor values
321+
*/
322+
bool streamFilteredFT;
323+
317324
/**
318325
* Names of the axis (joint with at least a degree of freedom) used in estimation.
319326
*/
@@ -376,7 +383,8 @@ class WholeBodyDynamicsDevice : public yarp::dev::DeviceDriver,
376383
bool openEstimator(os::Searchable& config);
377384
bool openDefaultContactFrames(os::Searchable& config);
378385
bool openSkinContactListPorts(os::Searchable& config);
379-
bool openExternalWrenchesPorts(os::Searchable& config);
386+
bool openExternalWrenchesPorts(os::Searchable& config);
387+
bool openFilteredFTPorts(os::Searchable& config);
380388

381389
/**
382390
* Close-related methods
@@ -385,6 +393,7 @@ class WholeBodyDynamicsDevice : public yarp::dev::DeviceDriver,
385393
bool closeRPCPort();
386394
bool closeSkinContactListsPorts();
387395
bool closeExternalWrenchesPorts();
396+
bool closeFilteredFTPorts();
388397

389398
/**
390399
* Attach-related methods
@@ -457,6 +466,7 @@ class WholeBodyDynamicsDevice : public yarp::dev::DeviceDriver,
457466
void publishExternalWrenches();
458467
void publishEstimatedQuantities();
459468
void publishGravityCompensation();
469+
void publishFilteredFTWithoutOffset();
460470

461471
/**
462472
* Load settings from config.
@@ -736,6 +746,11 @@ class WholeBodyDynamicsDevice : public yarp::dev::DeviceDriver,
736746
// informations on individual ports)
737747
std::vector< outputWrenchPortInformation > outputWrenchPorts;
738748

749+
/**
750+
* Ports for streaming fitelerd ft data without offset
751+
*/
752+
std::vector< std::unique_ptr <yarp::os::BufferedPort <yarp::sig::Vector> > > outputFTPorts;
753+
739754
// Buffer for external forces
740755
/**
741756
* The element netExternalWrenchesExertedByTheEnviroment[i] is the

0 commit comments

Comments
 (0)