Skip to content

Commit

Permalink
maissensor: Expose data via yarp::dev::IEncoderArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Sep 18, 2024
1 parent b15a049 commit eded4bb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/maissensor/include/yarp/dev/MaisSensorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <yarp/dev/ControlBoardInterfacesImpl.h>
#include <yarp/dev/ControlBoardInterfaces.h>
#include <yarp/dev/IAnalogSensor.h>
#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
#include <yarp/sig/Vector.h>
#include <yarp/os/Time.h>
#include <yarp/os/Stamp.h>
Expand Down Expand Up @@ -61,7 +62,8 @@ namespace gazebo {
class yarp::dev::GazeboYarpMaisSensorDriver:
public DeviceDriver,
public DeviceResponder,
public IAnalogSensor
public IAnalogSensor,
public IEncoderArrays
{
public:

Expand All @@ -83,6 +85,12 @@ class yarp::dev::GazeboYarpMaisSensorDriver:
virtual bool open(yarp::os::Searchable& config);
virtual bool close();

// yarp::dev::IEncoderArrays
virtual size_t getNrOfEncoderArrays() const override;
virtual yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const override;
virtual bool getEncoderArrayName(size_t sens_index, std::string &name) const override;
virtual bool getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
virtual size_t getEncoderArraySize(size_t sens_index) const override;

private:

Expand Down Expand Up @@ -114,7 +122,7 @@ class yarp::dev::GazeboYarpMaisSensorDriver:

yarp::os::Stamp m_lastTimestamp; /**< timestamp, updated with simulation time at each onUpdate call */

std::mutex m_mutex;
mutable std::mutex m_mutex;
yarp::sig::VectorOf<JointType> m_jointTypes;

int m_channels_num;
Expand Down
59 changes: 59 additions & 0 deletions plugins/maissensor/src/MaisSensorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ double * GazeboYarpMaisSensorDriver::convertUserToGazebo(double *values)
return values;
}

// start yarp::dev::IAnalogSensor methods

int GazeboYarpMaisSensorDriver::read(yarp::sig::Vector &out)
{
Expand Down Expand Up @@ -327,3 +328,61 @@ int GazeboYarpMaisSensorDriver::calibrateChannel(int ch, double value)
// not implemented
return 0;
}

// end yarp::dev::IAnalogSensor methods

// start yarp::dev::IEncoderArrays methods

size_t GazeboYarpMaisSensorDriver::getNrOfEncoderArrays() const
{
return 1;
}

yarp::dev::MAS_status GazeboYarpMaisSensorDriver::getEncoderArrayStatus(size_t sens_index) const
{
if (sens_index >= 1)
{
return yarp::dev::MAS_UNKNOWN;
}

return yarp::dev::MAS_OK;
}

bool GazeboYarpMaisSensorDriver::getEncoderArrayName(size_t sens_index, std::string &name) const
{
if (sens_index >= 1)
{
return false;
}

// TODO(traversaro): we need to understand which name to return
name = "";
return false;
}

bool GazeboYarpMaisSensorDriver::getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const
{
if (sens_index >= 1)
{
return false;
}

std::lock_guard<std::mutex> lock(m_mutex);
timestamp = m_lastTimestamp.getTime();
out.resize(m_positions.size());
out = m_positions;
return true;
}

size_t GazeboYarpMaisSensorDriver::getEncoderArraySize(size_t sens_index) const
{
if (sens_index >= 1)
{
return 0;
}

std::lock_guard<std::mutex> lock(m_mutex);
return m_positions.size();
}

// end yarp::dev::IEncoderArrays methods

0 comments on commit eded4bb

Please sign in to comment.