Skip to content

Commit

Permalink
Fix behaviour of MultipleAnalogSensor get**Name methods in nested mod…
Browse files Browse the repository at this point in the history
…els (#633)
  • Loading branch information
traversaro authored Aug 29, 2022
1 parent 5c2ce84 commit 48f0da6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format of this document is based on [Keep a Changelog](https://keepachangelo

## [Unreleased]

### Fixed
- Fix behaviour of MultipleAnalogSensor `get**Name` methods in nested models (https://github.com/robotology/gazebo-yarp-plugins/pull/633).

## [4.5.0] - 2022-08-23

### Added
Expand Down
16 changes: 16 additions & 0 deletions libraries/common/include/GazeboYarpPlugins/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ namespace GazeboYarpPlugins {
return false;
}
}

/**
* \brief Get last part of string after separator
* \param[in] fullString the full string
* \param[in] separator separator string
* \return lastPart the last part of the string, or the fullString if the seperator is not found
*/
inline std::string lastPartOfStringAfterSeparator(std::string const &fullString, std::string const &separator)
{
auto pos = fullString.find_last_of(separator);
if (pos == std::string::npos) {
return fullString;
} else {
return fullString.substr(pos + separator.size() - 1);
}
}
}


Expand Down
3 changes: 2 additions & 1 deletion plugins/forcetorque/src/ForceTorqueDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ForceTorqueDriver.h"
#include <GazeboYarpPlugins/Handler.hh>
#include <GazeboYarpPlugins/common.h>

#include <boost/bind/bind.hpp>
#include <gazebo/sensors/ForceTorqueSensor.hh>
Expand Down Expand Up @@ -63,7 +64,7 @@ bool GazeboYarpForceTorqueDriver::open(yarp::os::Searchable& config)
//Get gazebo pointers
std::string sensorScopedName(config.find(YarpForceTorqueScopedName.c_str()).asString().c_str());

m_sensorName = config.find("sensor_name").asString();
m_sensorName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(config.find("sensor_name").asString(), "::");
m_frameName = m_sensorName;

m_parentSensor = dynamic_cast<gazebo::sensors::ForceTorqueSensor*>(GazeboYarpPlugins::Handler::getHandler()->getSensor(sensorScopedName));
Expand Down
4 changes: 2 additions & 2 deletions plugins/imu/src/IMUDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ bool GazeboYarpIMUDriver::open(yarp::os::Searchable& config)
std::string sensorScopedName(config.find(YarpIMUScopedName).asString());
std::string sensorName(config.find("sensor_name").asString());

m_sensorName=sensorName;
m_frameName=sensorName;
m_sensorName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(sensorName, "::");
m_frameName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(sensorName, "::");

m_parentSensor = dynamic_cast<gazebo::sensors::ImuSensor*>(GazeboYarpPlugins::Handler::getHandler()->getSensor(sensorScopedName));

Expand Down

0 comments on commit 48f0da6

Please sign in to comment.