26 #define RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR 1
27 #define RGBD_INTERFACE_PROTOCOL_VERSION_MINOR 0
40 iRGBDSensor = interface;
41 ret = rgbParser.configure(interface);
42 ret &= depthParser.configure(interface);
48 bool ret = rgbParser.configure(rgbInterface);
49 ret &= depthParser.configure(depthInterface);
55 return fgCtrlParsers.configure(_fgCtrl);
69 ret = rgbParser.respond(cmd, response);
76 ret = depthParser.respond(cmd, response);
83 ret = fgCtrlParsers.respond(cmd, response);
98 ret = iRGBDSensor->getExtrinsicParam(params);
105 ret &= Property::copyPortable(params, params_b);
106 response.
append(params_b);
118 response.
addString(iRGBDSensor->getLastErrorMsg());
138 response.
addInt32(iRGBDSensor->getSensorStatus());
165 return DeviceResponder::respond(cmd,response);
185 isSubdeviceOwned(false),
186 subDeviceOwned(nullptr)
214 setId(
"RGBDSensorWrapper for " + depthFrame_StreamingPort_Name);
216 if(use_YARP && !initialize_YARP(config))
222 if(use_ROS && !initialize_ROS(config))
232 if(! openAndAttachSubDevice(config))
240 if(!openDeferredAttach(config))
249 if (!config.
check(
"period",
"refresh period of the broadcasted values in ms"))
261 yCInfo(
RGBDSENSORWRAPPER) <<
"RGBDSensorWrapper: ROS configuration parameters are not set, skipping ROS topic initialization.";
272 if (!rosGroup.
check(
"use_ROS"))
280 if (confUseRos ==
"true" || confUseRos ==
"only")
283 use_YARP = confUseRos ==
"true" ? true :
false;
288 if (verbose >= 3 && confUseRos !=
"false")
299 std::vector<param<string> > rosStringParam;
309 for (i = 0; i < rosStringParam.size(); i++)
311 prm = &rosStringParam[i];
312 if (!rosGroup.
check(prm->parname))
324 if (rosGroup.
check(
"forceInfoSync"))
326 forceInfoSync = rosGroup.
find(
"forceInfoSync").
asBool();
332 std::string rootName;
333 rootName = config.
check(
"name",
Value(
"/"),
"starting '/' if needed.").asString();
335 if (!config.
check(
"name",
"Prefix name of the ports opened by the RGBD wrapper."))
337 yCError(
RGBDSENSORWRAPPER) <<
"RGBDSensorWrapper: missing 'name' parameter. Check you configuration file; it must be like:";
344 rpcPort_Name = rootName +
"/rpc:i";
345 colorFrame_StreamingPort_Name = rootName +
"/rgbImage:o";
346 depthFrame_StreamingPort_Name = rootName +
"/depthImage:o";
350 if(config.
check(
"subdevice"))
351 isSubdeviceOwned=
true;
353 isSubdeviceOwned=
false;
358 bool RGBDSensorWrapper::openDeferredAttach(
Searchable& prop)
361 isSubdeviceOwned =
false;
365 bool RGBDSensorWrapper::openAndAttachSubDevice(
Searchable& prop)
371 p.setMonitor(prop.getMonitor(),
"subdevice");
377 subDeviceOwned->
open(p);
379 if (!subDeviceOwned->
isValid())
384 isSubdeviceOwned =
true;
385 if(!
attach(subDeviceOwned))
401 delete subDeviceOwned;
402 subDeviceOwned=
nullptr;
406 isSubdeviceOwned =
false;
417 colorFrame_StreamingPort.
close();
418 depthFrame_StreamingPort.
close();
444 if(!rpcPort.
open(rpcPort_Name))
451 if(!colorFrame_StreamingPort.
open(colorFrame_StreamingPort_Name))
453 yCError(
RGBDSENSORWRAPPER) <<
"RGBDSensorWrapper: unable to open color streaming Port" << colorFrame_StreamingPort_Name.c_str();
456 if(!depthFrame_StreamingPort.
open(depthFrame_StreamingPort_Name))
458 yCError(
RGBDSENSORWRAPPER) <<
"RGBDSensorWrapper: unable to open depth streaming Port" << depthFrame_StreamingPort_Name.c_str();
470 if (!rosPublisherPort_color.
topic(colorTopicName))
472 yCError(
RGBDSENSORWRAPPER) <<
" Unable to publish data on " << colorTopicName.c_str() <<
" topic, check your yarp-ROS network configuration";
475 if (!rosPublisherPort_depth.
topic(depthTopicName))
477 yCError(
RGBDSENSORWRAPPER) <<
" Unable to publish data on " << depthTopicName.c_str() <<
" topic, check your yarp-ROS network configuration";
480 if (!rosPublisherPort_colorCaminfo.
topic(cInfoTopicName))
482 yCError(
RGBDSENSORWRAPPER) <<
" Unable to publish data on " << cInfoTopicName.c_str() <<
" topic, check your yarp-ROS network configuration";
485 if (!rosPublisherPort_depthCaminfo.
topic(dInfoTopicName))
487 yCError(
RGBDSENSORWRAPPER) <<
" Unable to publish data on " << dInfoTopicName.c_str() <<
" topic, check your yarp-ROS network configuration";
512 if (device2attach.
size() != 1)
519 if(device2attach[0]->key ==
"IRGBDSensor")
528 if (!Idevice2attach->
isValid())
530 yCError(
RGBDSENSORWRAPPER) <<
"RGBDSensorWrapper: Device " << device2attach[0]->key <<
" to attach to is not valid ... cannot proceed";
534 Idevice2attach->
view(sensor_p);
535 Idevice2attach->
view(fgCtrl);
539 PeriodicThread::setPeriod(period);
540 return PeriodicThread::start();
549 if (isSubdeviceOwned)
578 PeriodicThread::setPeriod(period);
579 return PeriodicThread::start();
586 poly->
view(sensor_p);
590 if(sensor_p ==
nullptr)
607 PeriodicThread::setPeriod(period);
608 return PeriodicThread::start();
630 string RGBDSensorWrapper::yarp2RosPixelCode(
int code)
686 const string& frame_id,
702 void RGBDSensorWrapper::deepCopyImages(
const DepthImage& src,
704 const string& frame_id,
708 dest.
data.resize(src.getRawImageSize());
710 dest.
width = src.width();
711 dest.
height = src.height();
713 memcpy(dest.
data.data(), src.getRawImage(), src.getRawImageSize());
715 dest.
encoding = yarp2RosPixelCode(src.getPixelCode());
716 dest.
step = src.getRowSize();
737 string distModel, currentSensor;
740 vector<param<double> > parVector;
744 currentSensor = sensorType == COLOR_SENSOR ?
"Rgb" :
"Depth";
753 if(!camData.
check(
"distortionModel"))
760 if (distModel !=
"plumb_bob")
769 parVector.emplace_back(phyF,
"physFocalLength");
770 parVector.emplace_back(fx,
"focalLengthX");
771 parVector.emplace_back(fy,
"focalLengthY");
772 parVector.emplace_back(cx,
"principalPointX");
773 parVector.emplace_back(cy,
"principalPointY");
774 parVector.emplace_back(k1,
"k1");
775 parVector.emplace_back(k2,
"k2");
776 parVector.emplace_back(t1,
"t1");
777 parVector.emplace_back(t2,
"t2");
778 parVector.emplace_back(k3,
"k3");
779 parVector.emplace_back(stamp,
"stamp");
780 for(i = 0; i < parVector.size(); i++)
784 if(!camData.
check(par->parname))
799 cameraInfo.
D.resize(5);
800 cameraInfo.
D[0] = k1;
801 cameraInfo.
D[1] = k2;
802 cameraInfo.
D[2] = t1;
803 cameraInfo.
D[3] = t2;
804 cameraInfo.
D[4] = k3;
806 cameraInfo.
K.resize(9);
807 cameraInfo.
K[0] = fx; cameraInfo.
K[1] = 0; cameraInfo.
K[2] = cx;
808 cameraInfo.
K[3] = 0; cameraInfo.
K[4] = fy; cameraInfo.
K[5] = cy;
809 cameraInfo.
K[6] = 0; cameraInfo.
K[7] = 0; cameraInfo.
K[8] = 1;
820 cameraInfo.
R.assign(9, 0);
821 cameraInfo.
R.at(0) = cameraInfo.
R.at(4) = cameraInfo.
R.at(8) = 1;
823 cameraInfo.
P.resize(12);
824 cameraInfo.
P[0] = fx; cameraInfo.
P[1] = 0; cameraInfo.
P[2] = cx; cameraInfo.
P[3] = 0;
825 cameraInfo.
P[4] = 0; cameraInfo.
P[5] = fy; cameraInfo.
P[6] = cy; cameraInfo.
P[7] = 0;
826 cameraInfo.
P[8] = 0; cameraInfo.
P[9] = 0; cameraInfo.
P[10] = 1; cameraInfo.
P[11] = 0;
834 bool RGBDSensorWrapper::writeData()
842 if (!sensor_p->
getImages(colorImage, depthImage, &colorStamp, &depthStamp))
850 if (((colorStamp.
getTime() - oldColorStamp.
getTime()) > 0) ==
false)
855 if (((depthStamp.
getTime() - oldDepthStamp.
getTime()) > 0) ==
false)
860 oldDepthStamp = depthStamp;
861 oldColorStamp = colorStamp;
868 shallowCopyImages(colorImage, yColorImage);
869 shallowCopyImages(depthImage, yDepthImage);
873 colorFrame_StreamingPort.
write();
876 depthFrame_StreamingPort.
write();
887 cRosStamp = colorStamp.
getTime();
888 dRosStamp = depthStamp.
getTime();
890 deepCopyImages(colorImage, rColorImage, rosFrameId, cRosStamp, nodeSeq);
891 deepCopyImages(depthImage, rDepthImage, rosFrameId, dRosStamp, nodeSeq);
895 rosPublisherPort_color.
write();
898 rosPublisherPort_depth.
write();
900 if (setCamInfo(camInfoC, rosFrameId, nodeSeq, COLOR_SENSOR))
904 rosPublisherPort_colorCaminfo.
setEnvelope(colorStamp);
905 rosPublisherPort_colorCaminfo.
write();
911 if (setCamInfo(camInfoD, rosFrameId, nodeSeq, DEPTH_SENSOR))
915 rosPublisherPort_depthCaminfo.
setEnvelope(depthStamp);
916 rosPublisherPort_depthCaminfo.
write();
930 if (sensor_p!=
nullptr)
934 switch (sensorStatus)
936 case(IRGBDSensor::RGBD_SENSOR_OK_IN_USE) :
943 case(IRGBDSensor::RGBD_SENSOR_NOT_READY):
#define DEFAULT_THREAD_PERIOD
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_CONTROL
constexpr yarp::conf::vocab32_t VOCAB_IS
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_SET
constexpr yarp::conf::vocab32_t VOCAB_RGBD_SENSOR
constexpr yarp::conf::vocab32_t VOCAB_EXTRINSIC_PARAM
constexpr yarp::conf::vocab32_t VOCAB_RGBD_PROTOCOL_VERSION
constexpr yarp::conf::vocab32_t VOCAB_STATUS
constexpr yarp::conf::vocab32_t VOCAB_ERROR_MSG
constexpr yarp::conf::vocab32_t VOCAB_DEPTH_VISUAL_PARAMS
constexpr yarp::conf::vocab32_t VOCAB_RGB_VISUAL_PARAMS
const yarp::os::LogComponent & RGBDSENSORWRAPPER()
#define RGBD_INTERFACE_PROTOCOL_VERSION_MINOR
#define RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR
bool configure(yarp::dev::IRGBDSensor *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
bool detach() override
Detach the object (you must have first called attach).
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
~RGBDSensorWrapper() override
bool close() override
Close the DeviceDriver.
bool fromConfig(yarp::os::Searchable ¶ms)
void run() override
Loop function.
bool threadInit() override
Initialization method.
bool open(yarp::os::Searchable ¶ms) override
Device driver interface.
void setId(const std::string &id)
void threadRelease() override
Release method.
bool detachAll() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool view(T *&x)
Get an interface to the device driver.
An interface for retrieving intrinsic parameter from a depth camera.
Control interface for frame grabber devices.
A generic interface for cameras that have both color camera as well as depth camera sensor,...
int getRgbWidth() override=0
Return the width of each frame.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override=0
Get the intrinsic parameters of the rgb camera.
virtual bool getImages(yarp::sig::FlexImage &colorFrame, yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthFrame, yarp::os::Stamp *colorStamp=NULL, yarp::os::Stamp *depthStamp=NULL)=0
Get the both the color and depth frame in a single call.
int getDepthWidth() override=0
Return the height of each frame.
int getRgbHeight() override=0
Return the height of each frame.
virtual RGBDSensor_status getSensorStatus()=0
Get the surrent status of the sensor, using enum type.
int getDepthHeight() override=0
Return the height of each frame.
bool getDepthIntrinsicParam(yarp::os::Property &intrinsic) override=0
Get the intrinsic parameters of the depth camera.
An interface for retrieving intrinsic parameter from a rgb camera.
A container for a device driver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
bool isNull() const override
Checks if the object is invalid.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void close() override
Stop port activity.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
void interrupt()
interrupt delegates the call to the Node port interrupt.
An abstraction for a periodic thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
void setReader(PortReader &reader) override
Set an external reader for port data.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
bool topic(const std::string &name)
Set topic to publish to.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
An abstraction for a time stamp and/or sequence number.
double getTime() const
Get the time stamp.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool asBool() const
Get boolean value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
virtual std::string asString() const
Get string value.
std::string distortion_model
std::vector< yarp::conf::float64_t > R
std::vector< yarp::conf::float64_t > K
yarp::rosmsg::sensor_msgs::RegionOfInterest roi
std::vector< yarp::conf::float64_t > P
yarp::rosmsg::std_msgs::Header header
std::vector< yarp::conf::float64_t > D
std::vector< std::uint8_t > data
yarp::rosmsg::std_msgs::Header header
std::uint8_t is_bigendian
Image class with user control of representation details.
void setQuantum(size_t imgQuantum)
void setPixelCode(int imgPixelCode)
void setQuantum(size_t imgQuantum)
size_t width() const
Gets width of image in pixels.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
size_t getRowSize() const
Size of the underlying image buffer rows.
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
size_t height() const
Gets height of image in pixels.
virtual int getPixelCode() const
Gets pixel type identifier.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB8
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG16
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG16
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB16
const std::string depthInfoTopicName_param
const std::string depthTopicName_param
const std::string colorTopicName_param
const std::string nodeName_param
const std::string frameId_param
const std::string colorInfoTopicName_param
An interface for the device drivers.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
An interface to the operating system, including Port based communication.