Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New wrappers imported from iCub repository #90

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/libYARP_dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

project(YARP_dev)

option (NEW_WRAPPERS_WIP "under testing -> use newly imported wrappers from icub repository" FALSE)

set(YARP_dev_HDRS include/yarp/dev/all.h
include/yarp/dev/api.h
# include/yarp/dev/AnalogWrapper.h
include/yarp/dev/AudioGrabberInterfaces.h
include/yarp/dev/AudioVisualInterfaces.h
include/yarp/dev/CalibratorInterfaces.h
Expand All @@ -16,6 +19,7 @@ set(YARP_dev_HDRS include/yarp/dev/all.h
include/yarp/dev/ControlBoardInterfaces.h
include/yarp/dev/ControlBoardInterfacesImpl.h
include/yarp/dev/ControlBoardPid.h
# include/yarp/dev/ControlBoardWrapper.h
include/yarp/dev/DataSource.h
include/yarp/dev/DeviceDriver.h
include/yarp/dev/DeviceGroup.h
Expand Down Expand Up @@ -66,12 +70,15 @@ set(YARP_dev_HDRS include/yarp/dev/all.h
include/yarp/dev/ServiceInterfaces.h
include/yarp/dev/TestFrameGrabber.h
include/yarp/dev/TestMotor.h
# include/yarp/dev/VirtualAnalogWrapper.h
include/yarp/dev/Wrapper.h
include/yarp/dev/ControlBoardInterfacesImpl.inl)

set(YARP_dev_SRCS src/AnalogSensorClient.cpp
# src/AnalogWrapper.cpp
src/ControlBoardInterfacesImpl.cpp
src/ControlBoardPid.cpp
# src/ControlBoardWrapper.cpp
src/ControlCalibrationImpl.cpp
src/ControlModeImpl.cpp
src/DeviceDriver.cpp
Expand All @@ -96,7 +103,25 @@ set(YARP_dev_SRCS src/AnalogSensorClient.cpp
src/ServerControlBoard.cpp
src/ServerFrameGrabber.cpp
src/TestFrameGrabber.cpp
src/TorqueControlImpl.cpp)
src/TorqueControlImpl.cpp
# src/VirtualAnalogWrapper.cpp
)

# once this will be stable, remove the following 'IF' and uncomment corresponding files
# in the previous section.

IF (NEW_WRAPPERS_WIP)
add_definitions( -DUSE_NEW_WRAPPERS_WIP )
set(YARP_dev_HDRS ${YARP_dev_HDRS}
include/yarp/dev/ControlBoardWrapper.h
include/yarp/dev/AnalogWrapper.h
include/yarp/dev/VirtualAnalogWrapper.h)

set(YARP_dev_SRCS ${YARP_dev_SRCS}
src/AnalogWrapper.cpp
src/ControlBoardWrapper.cpp
src/VirtualAnalogWrapper.cpp)
ENDIF(NEW_WRAPPERS_WIP)

source_group("Source Files" FILES ${YARP_dev_SRCS})
source_group("Header Files" FILES ${YARP_dev_HDRS})
Expand Down
150 changes: 150 additions & 0 deletions src/libYARP_dev/include/yarp/dev/AnalogWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#ifndef ANALOG_SERVER_H_
#define ANALOG_SERVER_H_

//#include <list>
#include <vector>
#include <iostream>
#include <string>
#include <sstream>

#include <yarp/os/Network.h>
#include <yarp/os/Port.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/Time.h>
#include <yarp/os/Property.h>

#include <yarp/os/RateThread.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Stamp.h>

#include <yarp/sig/Vector.h>

#include <yarp/dev/IAnalogSensor.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/DeviceDriver.h>
#include <yarp/dev/Wrapper.h>

/* Using custom namespace to avoid name conflict while linking since helper
* class for the AnalogWrapper could been used also for other devices in other
* part of the code.
* Better would be use internal linkage, through unnamed namespace therefore
* enforcing internal linkage, but compiler correctly complains issuing a
* warning message, because th eclass is used as a member of another class
* outside the anonymous namespace.
* This is not a problem actually, but seeing a lot of warning messages is annoying.
*/

namespace analogWrapper_yarp_internal_namespace
{
class AnalogServerHandler;
class AnalogPortEntry;
}

namespace yarp{
namespace dev{
class AnalogWrapper;
}
}

namespace analogWrapper_yarp_internal_namespace {
/**
* Handler of the rpc port related to an analog sensor.
* Manage the calibration command received on the rpc port.
**/
class AnalogServerHandler: public yarp::os::PortReader
{
yarp::dev::IAnalogSensor* is; // analog sensor to calibrate, when required
yarp::os::Port rpcPort; // rpc port related to the analog sensor

public:
AnalogServerHandler(const char* n);
~AnalogServerHandler();

void setInterface(yarp::dev::IAnalogSensor *is);

bool _handleIAnalog(yarp::os::Bottle &cmd, yarp::os::Bottle &reply);

virtual bool read(yarp::os::ConnectionReader& connection);
};


/**
* A yarp port that output data read from an analog sensor.
* It contains information about which data of the analog sensor are sent
* on the port, i.e. an offset and a length.
*/
struct AnalogPortEntry
{
public:
yarp::os::BufferedPort<yarp::sig::Vector> port;
std::string port_name; // the complete name of the port
int offset; // an offset, the port is mapped starting from this taxel
int length; // length of the output vector of the port (-1 for max length)
AnalogPortEntry();
AnalogPortEntry(const AnalogPortEntry &alt);
AnalogPortEntry &operator =(const AnalogPortEntry &alt);
};

} // closing namespace analogWrapper_yarp_internal_namespace

/**
* It reads the data from an analog sensor and sends them on one or more ports.
* It creates one rpc port and its related handler for every output port.
*/
class yarp::dev::AnalogWrapper: public yarp::os::RateThread,
public yarp::dev::DeviceDriver,
public yarp::dev::IMultipleWrapper
{
private:
std::string rpcPortName;
std::string id;
yarp::dev::IAnalogSensor *analogSensor_p; // the analog sensor to read from
std::vector<analogWrapper_yarp_internal_namespace::AnalogPortEntry> analogPorts; // the list of output ports
std::vector<analogWrapper_yarp_internal_namespace::AnalogServerHandler*> handlers; // the list of rpc port handlers
yarp::os::Stamp lastStateStamp; // the last reading time stamp
int _rate;
void setHandlers();
void removeHandlers();

public:

// Constructor used by yarp factory
AnalogWrapper();

// Constructor used when there is only one output port -- obsolete, here for backward compatibility with skinwrapper
AnalogWrapper(const char* name, int rate=20);

// Contructor used when one or more output ports are specified -- obsolete, here for backward compatibility with skinwrapper
AnalogWrapper(const std::vector<analogWrapper_yarp_internal_namespace::AnalogPortEntry>& _analogPorts, int rate=20);

~AnalogWrapper();

bool open(yarp::os::Searchable &params);
bool close();
yarp::os::Bottle getOptions();

void setId(const std::string &i);
std::string getId();

/**
* Specify which analog sensor this thread has to read from.
*/
bool attachAll(const PolyDriverList &p);
bool detachAll();

void attach(yarp::dev::IAnalogSensor *s);
void detach();

bool threadInit();
void threadRelease();
void run();

private:
// Function used when there is only one output port
bool createPort(const char* name, int rate=20);
// Function used when one or more output ports are specified
bool createPorts(const std::vector<analogWrapper_yarp_internal_namespace::AnalogPortEntry>& _analogPorts, int rate=20);
};

#endif
Loading