50 std::string nodeName) :
52 nh_private_(nh_private),
94 printf(
"done: %d \n", status);
111 usValue = (uint32_t)it;
112 status = BTAsetIntegrationTime(
handle_, usValue);
113 if (status != BTA_StatusOk)
114 ROS_WARN_STREAM(
"Error setting IntegrationTime:: " << status <<
"---------------");
116 status = BTAgetIntegrationTime(
handle_, &usValue);
117 if (status != BTA_StatusOk)
118 ROS_WARN_STREAM(
"Error reading IntegrationTime: " << status <<
"---------------");
125 status = BTAsetFrameRate(
handle_, fr);
126 if (status != BTA_StatusOk)
127 ROS_WARN_STREAM(
"Error setting FrameRate: " << status <<
"---------------");
130 status = BTAgetFrameRate(
handle_, &fr_f);
132 if (status != BTA_StatusOk)
133 ROS_WARN_STREAM(
"Error reading FrameRate: " << status <<
"---------------");
144 if(it != config_.Integration_Time) {
145 usValue = (uint32_t)config_.Integration_Time;
146 status = BTAsetIntegrationTime(
handle_, usValue);
147 if (status != BTA_StatusOk)
148 ROS_WARN_STREAM(
"Error setting IntegrationTime: " << status <<
"---------------");
154 if(fr != config_.Frame_rate) {
155 usValue = (uint32_t)config_.Frame_rate;
156 status = BTAsetFrameRate(
handle_, usValue);
157 if (status != BTA_StatusOk)
158 ROS_WARN_STREAM(
"Error setting FrameRate: " << status <<
"---------------");
163 if(config_.Read_reg) {
165 std::stringstream ss;
166 it = strtoul(config_.Reg_addr.c_str(), NULL, 0);
167 status = BTAreadRegister(
handle_, it, &usValue, 0);
168 if (status != BTA_StatusOk) {
169 ROS_WARN_STREAM(
"Could not read reg: " << config_.Reg_addr <<
". Status: " << status);
172 ss <<
"0x"<< std::hex << usValue;
173 ss >> config_.Reg_val;
174 ROS_INFO_STREAM(
"Read register: " << config_.Reg_addr <<
". Value: " << ss.str());
175 }
catch(
const boost::bad_lexical_cast &) {
178 config_.Read_reg =
false;
180 if(config_.Write_reg) {
182 it = strtoul(config_.Reg_addr.c_str(), NULL, 0);
183 usValue = strtoul(config_.Reg_val.c_str(), NULL, 0);
185 status = BTAwriteRegister(
handle_, it, &usValue, 0);
186 if (status != BTA_StatusOk) {
191 ". Status: " << status);
193 ROS_INFO_STREAM(
"Written register: " << config_.Reg_addr <<
". Value: " << config_.Reg_val);
194 BTAgetIntegrationTime(
handle_, &usValue);
195 config_.Integration_Time = usValue;
197 config_.Frame_rate = fr;
198 config_.Write_reg =
false;
205 switch (dataFormat) {
206 case BTA_DataFormatUInt16:
207 return sizeof(uint16_t);
209 case BTA_DataFormatSInt16:
210 return sizeof(int16_t);
212 case BTA_DataFormatFloat32:
213 return sizeof(float);
219 switch (dataFormat) {
220 case BTA_DataFormatUInt16:
223 case BTA_DataFormatSInt16:
226 case BTA_DataFormatFloat32:
238 case BTA_UnitMillimeter:
258 status = BTAgetFrame(
handle_, &frame, 3000);
259 if (status != BTA_StatusOk) {
263 ROS_DEBUG(
" frameArrived FrameCounter %d", frame->frameCounter);
265 BTA_DataFormat dataFormat;
269 ci_tof->header.frame_id =
nodeName_+
"/tof_camera";
273 status = BTAgetDistances(frame, &distances, &dataFormat, &unit, &xRes, &yRes);
274 if (status == BTA_StatusOk) {
275 sensor_msgs::ImagePtr dis (
new sensor_msgs::Image);
276 dis->header.seq = frame->frameCounter;
277 dis->header.stamp.sec = frame->timeStamp;
282 dis->data.resize(xRes*yRes*
getDataSize(dataFormat));
283 memcpy ( &dis->data[0], distances, xRes*yRes*getDataSize(dataFormat) );
285 dis->header.frame_id =
"distances";
291 BTA_DataFormat amDataFormat;
292 status = BTAgetAmplitudes(frame, &litudes,
293 &amDataFormat, &unit, &xRes, &yRes);
294 if (status == BTA_StatusOk) {
295 sensor_msgs::ImagePtr amp (
new sensor_msgs::Image);
296 amp->header.seq = frame->frameCounter;
297 amp->header.stamp.sec = frame->timeStamp;
302 amp->data.resize(xRes*yRes*
getDataSize(amDataFormat));
303 memcpy ( &->data[0], amplitudes, xRes*yRes*getDataSize(amDataFormat) );
305 amp->header.frame_id =
"amplitudes";
310 void *xCoordinates, *yCoordinates, *zCoordinates;
311 status = BTAgetXYZcoordinates(frame, &xCoordinates, &yCoordinates, &zCoordinates, &dataFormat, &unit, &xRes, &yRes);
312 if (status == BTA_StatusOk) {
313 if (
_xyz->width != xRes ||
_xyz->height != yRes ||
_xyz->fields.size() != 4) {
318 "y", 1, sensor_msgs::PointField::FLOAT32,
319 "z", 1, sensor_msgs::PointField::FLOAT32,
320 "intensity", 1, sensor_msgs::PointField::UINT16);
322 _xyz->header.frame_id =
"cloud";
323 _xyz->is_dense =
true;
337 if (dataFormat == BTA_DataFormatSInt16) {
342 for (
size_t i = 0; i < yRes*xRes; i++, ++_x, ++_y, ++_z, ++_i) {
343 *_x =
static_cast<short *
>(xCoordinates)[i]*conv;
344 *_y =
static_cast<short *
>(yCoordinates)[i]*conv;
345 *_z =
static_cast<short *
>(zCoordinates)[i]*conv;
347 if(amDataFormat == BTA_DataFormatUInt16) {
348 *_i =
static_cast<unsigned short *
>(amplitudes)[i];
349 }
else if(amDataFormat == BTA_DataFormatFloat32) {
350 *_i =
static_cast<float *
>(amplitudes)[i];
355 }
else if (dataFormat == BTA_DataFormatFloat32) {
356 for (
size_t i = 0; i < yRes*xRes; i++, ++_x, ++_y, ++_z, ++_i) {
357 *_x =
static_cast<float *
>(xCoordinates)[i]*conv;
358 *_y =
static_cast<float *
>(yCoordinates)[i]*conv;
359 *_z =
static_cast<float *
>(zCoordinates)[i]*conv;
361 if(amDataFormat == BTA_DataFormatUInt16) {
362 *_i =
static_cast<unsigned short *
>(amplitudes)[i];
363 }
else if(amDataFormat == BTA_DataFormatFloat32) {
364 *_i =
static_cast<float *
>(amplitudes)[i];
375 _xyz->header.seq = frame->frameCounter;
376 _xyz->header.stamp.sec = frame->timeStamp;
413 BTAfreeFrame(&frame);
437 config_.udpDataIpAddrLen = (uint8_t)iusValue;
442 for (
int i = 1; i <=
config_.udpDataIpAddrLen; i++) {
443 std::ostringstream to_string;
445 to_string <<
nodeName_ <<
"/udpDataIpAddr/n" << i;
453 config_.udpDataPort = (uint16_t)iusValue;
458 config_.udpControlOutIpAddrLen = (uint8_t)iusValue;
463 for (
int i = 1; i <=
config_.udpControlOutIpAddrLen; i++) {
464 std::ostringstream to_string;
466 to_string <<
nodeName_ <<
"/udpControlOutIpAddr/n" << i;
474 config_.udpControlPort = (uint16_t)iusValue;
479 config_.udpControlInIpAddrLen = (uint8_t)iusValue;
485 for (
int i = 1; i <=
config_.udpControlInIpAddrLen; i++) {
486 std::ostringstream to_string;
488 to_string <<
nodeName_ <<
"/udpControlInIpAddr/n" << i;
496 config_.udpControlCallbackPort = (uint16_t)iusValue;
501 config_.tcpDeviceIpAddrLen = (uint8_t)iusValue;
506 for (
int i = 1; i <=
config_.tcpDeviceIpAddrLen; i++) {
507 std::ostringstream to_string;
509 to_string <<
nodeName_ <<
"/tcpDeviceIpAddr/n" << i;
517 config_.tcpControlPort = (uint16_t)iusValue;
522 config_.tcpDataPort = (uint16_t)iusValue;
528 config_.uartBaudRate = (uint32_t)iusValue;
530 config_.uartDataBits = (uint8_t)iusValue;
532 config_.uartStopBits = (uint8_t)iusValue;
534 config_.uartParity = (uint8_t)iusValue;
536 config_.uartTransmitterAddress = (uint8_t)iusValue;
538 config_.uartReceiverAddress = (uint8_t)iusValue;
540 config_.serialNumber = (uint32_t)iusValue;
547 config_.frameMode = (BTA_FrameMode)frameMode;
550 config_.verbosity = (uint8_t)iusValue;
553 config_.frameQueueLength = (uint16_t)iusValue;
555 int32_t frameQueueMode;
557 config_.frameQueueMode = (BTA_QueueMode)frameQueueMode;
559 #if !defined(BTA_ETH) || !defined(BTA_P100) 562 config_.deviceType = (BTA_DeviceType)deviceType;
573 BTA_DeviceInfo *deviceInfo;
577 status = (BTA_Status)-1;
578 for (
int i=0; i<10; i++) {
581 if (status != BTA_StatusOk) {
584 ROS_WARN_STREAM(
"Could not connect to the camera. status: " << status);
589 if (!BTAisConnected(
handle_)) {
595 status = BTAgetDeviceInfo(
handle_, &deviceInfo);
596 if (status != BTA_StatusOk) {
602 <<
"deviceType: " << deviceInfo->deviceType <<
"\n" 603 <<
"serialNumber: " << deviceInfo->serialNumber <<
"\n" 604 <<
"firmwareVersionMajor: " << deviceInfo->firmwareVersionMajor <<
"\n" 605 <<
"firmwareVersionMinor: " << deviceInfo->firmwareVersionMinor <<
"\n" 606 <<
"firmwareVersionNonFunc: " << deviceInfo->firmwareVersionNonFunc
612 BTAfreeDeviceInfo(deviceInfo);
641 ROS_DEBUG(
"Waiting for dynamic reconfigure configuration.");
642 boost::this_thread::sleep(boost::posix_time::seconds(0.1));
644 ROS_DEBUG(
"Dynamic reconfigure configuration received.");
653 "package://bta_tof_driver/calib.yml")) {
656 "package://bta_tof_driver/calib.yml" );
659 "package://bta_tof_driver/calib.yml" <<
660 " not found. Using an uncalibrated config_.");
672 if (!BTAisConnected(
handle_)) {
std::string calibFileName_
image_transport::CameraPublisher pub_amp_
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void close()
Closes the connection to the device.
sensor_msgs::CameraInfo getCameraInfo(void)
uint8_t tcpDeviceIpAddr_[6]
void publish(const boost::shared_ptr< M > &message) const
camera_info_manager::CameraInfoManager cim_tof_
bool loadCameraInfo(const std::string &url)
uint32_t getNumSubscribers() const
static void BTA_CALLCONV infoEventCb(BTA_EventId eventId, int8_t *msg)
ros::NodeHandle nh_private_
uint8_t udpControlOutIpAddr_[6]
geometry_msgs::TransformStamped transformStamped
boost::shared_ptr< ReconfigureServer > reconfigure_server_
image_transport::CameraPublisher pub_dis_
void setPointCloud2Fields(int n_fields,...)
sensor_msgs::PointCloud2Ptr _xyz
uint8_t udpDataIpAddr_[6]
virtual ~BtaRos()
Class destructor.
int connectCamera()
Helper for connect to the device.
bool validateURL(const std::string &url)
size_t getDataSize(BTA_DataFormat dataFormat)
Returns the size of the data based in BTA_DataFormat.
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
void publishData()
Publish the data based on set up parameters.
const std::string TYPE_32FC1
const std::string TYPE_16UC1
ROSCPP_DECL bool isShuttingDown()
dynamic_reconfigure::Server< Config > ReconfigureServer
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void parseConfig()
Reads configuration from the server parameters.
image_transport::ImageTransport it_
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
tf2_ros::StaticTransformBroadcaster pub_tf
bool getParam(const std::string &key, std::string &s) const
float getUnit2Meters(BTA_Unit unit)
Gives the conversion value to meters from the BTA_Unit.
bool hasParam(const std::string &key) const
ROSCPP_DECL void spinOnce()
BtaRos(ros::NodeHandle nh_camera, ros::NodeHandle nh_private, std::string nodeName)
Class constructor.
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
std::string uartPortName_
uint8_t udpControlInIpAddr_[6]
bool setCameraName(const std::string &cname)
void callback(bta_tof_driver::bta_tof_driverConfig &config, uint32_t level)
Callback for rqt_reconfigure. It is called any time we change a parameter in the visual interface...
const std::string TYPE_16SC1
std::string getDataType(BTA_DataFormat dataFormat)
Returns the data encoding flat based in BTA_DataFormat.
int initialize()
Initializes the device and parameters.