37 isSubdeviceOwned(false),
38 subDeviceOwned(
nullptr)
56 if (!config.
check(
"period",
"refresh period of the broadcasted values in s"))
69 if (config.
check(
"forceInfoSync"))
71 forceInfoSync = config.
find(
"forceInfoSync").
asBool();
74 if(config.
check(
"subdevice")) {
75 isSubdeviceOwned=
true;
77 isSubdeviceOwned=
false;
80 setId(
"RGBDSensorWrapper for " + nodeName);
82 if(!initialize_ROS(config))
91 if(! openAndAttachSubDevice(config))
99 if (!openDeferredAttach(config)) {
107 bool RgbdSensor_nws_ros::openDeferredAttach(
Searchable& prop)
110 isSubdeviceOwned =
false;
114 bool RgbdSensor_nws_ros::openAndAttachSubDevice(
Searchable& prop)
120 p.setMonitor(prop.getMonitor(),
"subdevice");
126 subDeviceOwned->open(p);
128 if (!subDeviceOwned->isValid())
133 isSubdeviceOwned =
true;
134 if(!attach(subDeviceOwned)) {
151 delete subDeviceOwned;
152 subDeviceOwned=
nullptr;
156 isSubdeviceOwned =
false;
174 if (!params.
check(
"depth_topic_name")) {
178 std::string depth_topic_name = params.
find(
"depth_topic_name").
asString();
179 if(depth_topic_name[0] !=
'/'){
185 if (!params.
check(
"color_topic_name")) {
189 std::string color_topic_name = params.
find(
"color_topic_name").
asString();
190 if(color_topic_name[0] !=
'/'){
196 if (!params.
check(
"node_name")) {
200 std::string node_name = params.
find(
"node_name").
asString();
201 if(node_name[0] !=
'/'){
207 if (!params.
check(
"depth_frame_id")) {
211 m_depth_frame_id = params.
find(
"depth_frame_id").
asString();
214 if (!params.
check(
"color_frame_id")) {
218 m_color_frame_id = params.
find(
"color_frame_id").
asString();
224 if (!publisherPort_color.topic(color_topic_name))
226 yCError(
RGBDSENSORNWSROS) <<
"Unable to publish data on " << color_topic_name.c_str() <<
" topic, check your yarp-ROS network configuration";
230 if (!publisherPort_depth.topic(depth_topic_name))
232 yCError(
RGBDSENSORNWSROS) <<
"Unable to publish data on " << depth_topic_name.c_str() <<
" topic, check your yarp-ROS network configuration";
235 std::string rgb_info_topic_name = color_topic_name.substr(0,color_topic_name.rfind(
'/')) +
"/camera_info";
236 if (!publisherPort_colorCaminfo.topic(rgb_info_topic_name))
238 yCError(
RGBDSENSORNWSROS) <<
"Unable to publish data on " << rgb_info_topic_name.c_str() <<
" topic, check your yarp-ROS network configuration";
242 std::string depth_info_topic_name = depth_topic_name.substr(0,depth_topic_name.rfind(
'/')) +
"/camera_info";
243 if (!publisherPort_depthCaminfo.topic(depth_info_topic_name))
245 yCError(
RGBDSENSORNWSROS) <<
"Unable to publish data on " << depth_info_topic_name.c_str() <<
" topic, check your yarp-ROS network configuration";
272 if (isSubdeviceOwned) {
284 poly->
view(sensor_p);
288 if(sensor_p ==
nullptr)
294 if(fgCtrl ==
nullptr)
299 PeriodicThread::setPeriod(period);
300 return PeriodicThread::start();
330 std::string distModel;
331 std::string currentSensor;
334 std::vector<param<double> > parVector;
338 currentSensor = sensorType == COLOR_SENSOR ?
"Rgb" :
"Depth";
339 ok = sensorType == COLOR_SENSOR ? sensor_p->getRgbIntrinsicParam(camData) : sensor_p->getDepthIntrinsicParam(camData);
347 if(!camData.
check(
"distortionModel"))
354 if (distModel !=
"plumb_bob")
363 parVector.emplace_back(phyF,
"physFocalLength");
364 parVector.emplace_back(fx,
"focalLengthX");
365 parVector.emplace_back(fy,
"focalLengthY");
366 parVector.emplace_back(cx,
"principalPointX");
367 parVector.emplace_back(cy,
"principalPointY");
368 parVector.emplace_back(k1,
"k1");
369 parVector.emplace_back(k2,
"k2");
370 parVector.emplace_back(t1,
"t1");
371 parVector.emplace_back(t2,
"t2");
372 parVector.emplace_back(k3,
"k3");
373 parVector.emplace_back(stamp,
"stamp");
374 for(i = 0; i < parVector.size(); i++)
378 if(!camData.
check(par->parname))
389 cameraInfo.
width = sensorType == COLOR_SENSOR ? sensor_p->getRgbWidth() : sensor_p->getDepthWidth();
390 cameraInfo.
height = sensorType == COLOR_SENSOR ? sensor_p->getRgbHeight() : sensor_p->getDepthHeight();
393 cameraInfo.
D.resize(5);
394 cameraInfo.
D[0] = k1;
395 cameraInfo.
D[1] = k2;
396 cameraInfo.
D[2] = t1;
397 cameraInfo.
D[3] = t2;
398 cameraInfo.
D[4] = k3;
400 cameraInfo.
K.resize(9);
401 cameraInfo.
K[0] = fx; cameraInfo.
K[1] = 0; cameraInfo.
K[2] = cx;
402 cameraInfo.
K[3] = 0; cameraInfo.
K[4] = fy; cameraInfo.
K[5] = cy;
403 cameraInfo.
K[6] = 0; cameraInfo.
K[7] = 0; cameraInfo.
K[8] = 1;
414 cameraInfo.
R.assign(9, 0);
415 cameraInfo.
R.at(0) = cameraInfo.
R.at(4) = cameraInfo.
R.at(8) = 1;
417 cameraInfo.
P.resize(12);
418 cameraInfo.
P[0] = fx; cameraInfo.
P[1] = 0; cameraInfo.
P[2] = cx; cameraInfo.
P[3] = 0;
419 cameraInfo.
P[4] = 0; cameraInfo.
P[5] = fy; cameraInfo.
P[6] = cy; cameraInfo.
P[7] = 0;
420 cameraInfo.
P[8] = 0; cameraInfo.
P[9] = 0; cameraInfo.
P[10] = 1; cameraInfo.
P[11] = 0;
428 bool RgbdSensor_nws_ros::writeData()
435 if (!sensor_p->getImages(colorImage,
depthImage, &colorStamp, &depthStamp))
442 bool rgb_data_ok =
true;
443 bool depth_data_ok =
true;
445 if (((colorStamp.getTime() - oldColorStamp.
getTime()) > 0) ==
false)
450 else { oldColorStamp = colorStamp; }
452 if (((depthStamp.getTime() - oldDepthStamp.
getTime()) > 0) ==
false)
457 else { oldDepthStamp = depthStamp; }
466 publisherPort_color.setEnvelope(colorStamp);
467 publisherPort_color.write();
468 if (setCamInfo(camInfoC, m_color_frame_id, nodeSeq, COLOR_SENSOR))
472 publisherPort_colorCaminfo.setEnvelope(colorStamp);
473 publisherPort_colorCaminfo.
write();
486 publisherPort_depth.setEnvelope(depthStamp);
487 publisherPort_depth.write();
488 if (setCamInfo(camInfoD, m_depth_frame_id, nodeSeq, DEPTH_SENSOR))
492 publisherPort_depthCaminfo.setEnvelope(depthStamp);
493 publisherPort_depthCaminfo.
write();
508 if (sensor_p!=
nullptr)
511 sensorStatus = sensor_p->getSensorStatus();
512 switch (sensorStatus)
514 case(IRGBDSensor::RGBD_SENSOR_OK_IN_USE) :
522 case(IRGBDSensor::RGBD_SENSOR_NOT_READY):
constexpr double DEFAULT_THREAD_PERIOD
const yarp::os::LogComponent & RGBDSENSORNWSROS()
rgbdSensor_nws_ros: A Network grabber for kinect-like devices. This device will produce two streams o...
~RgbdSensor_nws_ros() override
bool close() override
Close the DeviceDriver.
void setId(const std::string &id)
void threadRelease() override
Release method.
bool attach(yarp::dev::PolyDriver *poly) override
Specify which sensor this thread has to read from.
bool open(yarp::os::Searchable ¶ms) override
Device driver interface.
bool threadInit() override
Initialization method.
void run() override
Loop function.
bool detach() override
WrapperSingle interface.
bool view(T *&x)
Get an interface to the device driver.
A generic interface for cameras that have both color camera as well as depth camera sensor,...
A container for a device driver.
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...
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.
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.
An abstraction for a time stamp and/or sequence number.
double getTime() const
Get the time stamp.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool asBool() const
Get boolean value.
virtual std::string asString() const
Get string value.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
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
yarp::rosmsg::std_msgs::Header header
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
void deepCopyImages(const yarp::sig::FlexImage &src, yarp::rosmsg::sensor_msgs::Image &dest, const std::string &frame_id, const yarp::rosmsg::TickTime &timeStamp, const unsigned int &seq)
An interface for the device drivers.
An interface to the operating system, including Port based communication.