22 PeriodicThread(s_default_period)
43 publisherPort_image.
close();
46 publisherPort_cameraInfo.
close();
48 if (node !=
nullptr) {
61 yCError(FRAMEGRABBER_NWS_ROS,
"Device is already opened");
66 if (config.
check(
"period",
"refresh period(in s) of the broadcasted values through yarp ports") && config.
find(
"period").isFloat64()) {
67 m_period = config.
find(
"period").asFloat64();
69 yCInfo(FRAMEGRABBER_NWS_ROS)
70 <<
"Period parameter not found, using default of"
74 PeriodicThread::setPeriod(m_period);
77 if (!config.
check(
"node_name"))
79 yCError(FRAMEGRABBER_NWS_ROS) <<
"Missing node_name parameter";
82 std::string nodeName = config.
find(
"node_name").asString();
83 if (nodeName.c_str()[0] !=
'/') {
84 yCError(FRAMEGRABBER_NWS_ROS) <<
"Missing '/' in node_name parameter";
91 if (!config.
check(
"topic_name"))
93 yCError(FRAMEGRABBER_NWS_ROS) <<
"Missing topic_name parameter";
96 std::string topicName = config.
find(
"topic_name").asString();
97 if (topicName.c_str()[0] !=
'/') {
98 yCError(FRAMEGRABBER_NWS_ROS) <<
"Missing '/' in topic_name parameter";
103 if (!publisherPort_image.
topic(topicName)) {
104 yCError(FRAMEGRABBER_NWS_ROS) <<
"Unable to publish data on " << topicName <<
" topic, check your yarp-ROS network configuration";
111 std::string cameraInfoTopicName = topicName.substr(0,topicName.rfind(
'/')) +
"/camera_info";
112 if (!publisherPort_cameraInfo.
topic(cameraInfoTopicName)) {
113 yCError(FRAMEGRABBER_NWS_ROS) <<
"Unable to publish data on" << cameraInfoTopicName <<
"topic, check your yarp-ROS network configuration";
118 if (!config.
check(
"frame_id"))
120 yCError(FRAMEGRABBER_NWS_ROS) <<
"Missing frame_id parameter";
123 m_frameId = config.
find(
"frame_id").asString();
125 yCInfo(FRAMEGRABBER_NWS_ROS) <<
"Running, waiting for attach...";
135 yCError(FRAMEGRABBER_NWS_ROS) <<
"Device " << poly <<
" to attach to is not valid ... cannot proceed";
139 poly->
view(iRgbVisualParams);
140 poly->
view(iFrameGrabberImage);
141 poly->
view(iPreciselyTimed);
143 if (iFrameGrabberImage ==
nullptr) {
144 yCError(FRAMEGRABBER_NWS_ROS) <<
"IFrameGrabberImage interface is not available on the device";
148 if (iRgbVisualParams ==
nullptr) {
149 yCWarning(FRAMEGRABBER_NWS_ROS) <<
"IRgbVisualParams interface is not available on the device";
152 return PeriodicThread::start();
162 iRgbVisualParams =
nullptr;
163 iFrameGrabberImage =
nullptr;
164 iPreciselyTimed =
nullptr;
190 if (iPreciselyTimed) {
196 if (iFrameGrabberImage && publisherPort_image.
getOutputCount() > 0) {
198 auto& image = publisherPort_image.
prepare();
201 image.width = img->
width();
202 image.height = img->
height();
205 image.header.frame_id = m_frameId;
206 image.header.stamp = m_stamp.
getTime();
207 image.header.seq = m_stamp.
getCount();
208 image.is_bigendian = 0;
213 publisherPort_image.
write();
216 if (iRgbVisualParams && publisherPort_cameraInfo.
getOutputCount() > 0) {
217 auto& cameraInfo = publisherPort_cameraInfo.
prepare();
219 if (setCamInfo(cameraInfo)) {
221 publisherPort_cameraInfo.
write();
232 param(T& inVar, std::string inName) :
234 parname(
std::move(inName))
242bool FrameGrabber_nws_ros::setCamInfo(yarp::rosmsg::sensor_msgs::CameraInfo& cameraInfo)
244 yCAssert(FRAMEGRABBER_NWS_ROS, iRgbVisualParams);
248 yCErrorThreadOnce(FRAMEGRABBER_NWS_ROS) <<
"Unable to get intrinsic param from rgb sensor!";
252 if (!camData.
check(
"distortionModel")) {
253 yCWarning(FRAMEGRABBER_NWS_ROS) <<
"Missing distortion model";
257 std::string distModel = camData.
find(
"distortionModel").
asString();
258 if (distModel !=
"plumb_bob") {
259 yCError(FRAMEGRABBER_NWS_ROS) <<
"Distortion model not supported";
274 std::vector<param<double>> parVector;
275 parVector.emplace_back(phyF,
"physFocalLength");
276 parVector.emplace_back(fx,
"focalLengthX");
277 parVector.emplace_back(fy,
"focalLengthY");
278 parVector.emplace_back(cx,
"principalPointX");
279 parVector.emplace_back(cy,
"principalPointY");
280 parVector.emplace_back(k1,
"k1");
281 parVector.emplace_back(k2,
"k2");
282 parVector.emplace_back(t1,
"t1");
283 parVector.emplace_back(t2,
"t2");
284 parVector.emplace_back(k3,
"k3");
286 for(
auto& par : parVector) {
287 if(!camData.
check(par.parname)) {
288 yCWarning(FRAMEGRABBER_NWS_ROS) <<
"Driver has not the param:" << par.parname;
294 cameraInfo.header.frame_id = m_frameId;
295 cameraInfo.header.seq = m_stamp.
getCount();
296 cameraInfo.header.stamp = m_stamp.
getTime();
297 cameraInfo.width = iRgbVisualParams->
getRgbWidth();
299 cameraInfo.distortion_model = distModel;
301 cameraInfo.D.resize(5);
302 cameraInfo.D[0] = k1;
303 cameraInfo.D[1] = k2;
304 cameraInfo.D[2] = t1;
305 cameraInfo.D[3] = t2;
306 cameraInfo.D[4] = k3;
308 cameraInfo.K.resize(9);
309 cameraInfo.K[0] = fx; cameraInfo.K[1] = 0; cameraInfo.K[2] = cx;
310 cameraInfo.K[3] = 0; cameraInfo.K[4] = fy; cameraInfo.K[5] = cy;
311 cameraInfo.K[6] = 0; cameraInfo.K[7] = 0; cameraInfo.K[8] = 1;
322 cameraInfo.R.assign(9, 0);
323 cameraInfo.R.at(0) = cameraInfo.R.at(4) = cameraInfo.R.at(8) = 1;
325 cameraInfo.P.resize(12);
326 cameraInfo.P[0] = fx; cameraInfo.P[1] = 0; cameraInfo.P[2] = cx; cameraInfo.P[3] = 0;
327 cameraInfo.P[4] = 0; cameraInfo.P[5] = fy; cameraInfo.P[6] = cy; cameraInfo.P[7] = 0;
328 cameraInfo.P[8] = 0; cameraInfo.P[9] = 0; cameraInfo.P[10] = 1; cameraInfo.P[11] = 0;
330 cameraInfo.binning_x = cameraInfo.binning_y = 0;
331 cameraInfo.roi.height = cameraInfo.roi.width = cameraInfo.roi.x_offset = cameraInfo.roi.y_offset = 0;
332 cameraInfo.roi.do_rectify =
false;
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
void run() override
Loop function.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool detach() override
Detach the object (you must have first called attach).
bool close() override
Close the DeviceDriver.
~FrameGrabber_nws_ros() override
bool threadInit() override
Initialization method.
void threadRelease() override
Release method.
bool view(T *&x)
Get an interface to the device driver.
virtual bool getImage(ImageType &image)=0
Get an image from the frame grabber.
virtual yarp::os::Stamp getLastInputStamp()=0
Return the time stamp relative to the last acquisition.
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)=0
Get the intrinsic parameters of the rgb camera.
virtual int getRgbHeight()=0
Return the height of each frame.
virtual int getRgbWidth()=0
Return the width of each frame.
A container for a device driver.
bool isValid() const
Check if device is valid.
void interrupt()
interrupt delegates the call to the Node port interrupt.
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.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void close() override
Stop port activity.
bool topic(const std::string &name)
Set topic to publish to.
bool unprepare()
Give the last prepared object back to YARP without writing it.
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 Publisher::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
double getTime() const
Get the time stamp.
int getCount() const
Get the sequence number.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
int getPixelCode() const override
Gets pixel type identifier.
size_t width() const
Gets width of image in pixels.
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 height() const
Gets height of image in pixels.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCErrorThreadOnce(component,...)
std::string yarp2RosPixelCode(int code)
double now()
Return the current time in seconds, relative to an arbitrary starting point.