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 ci_tof->header.seq = frame->frameCounter;
277 ci_tof->header.stamp.sec = frame->timeStamp;
278 ci_tof->header.frame_id =
"distances";
279 dis->header.seq = frame->frameCounter;
280 dis->header.stamp.sec = frame->timeStamp;
285 dis->data.resize(xRes*yRes*
getDataSize(dataFormat));
286 memcpy ( &dis->data[0], distances, xRes*yRes*getDataSize(dataFormat) );
288 dis->header.frame_id =
"distances";
294 BTA_DataFormat amDataFormat;
295 status = BTAgetAmplitudes(frame, &litudes,
296 &amDataFormat, &unit, &xRes, &yRes);
297 if (status == BTA_StatusOk) {
298 sensor_msgs::ImagePtr amp (
new sensor_msgs::Image);
299 ci_tof->header.seq = frame->frameCounter;
300 ci_tof->header.stamp.sec = frame->timeStamp;
301 amp->header.seq = frame->frameCounter;
302 amp->header.stamp.sec = frame->timeStamp;
303 ci_tof->header.frame_id =
"amplitudes";
308 amp->data.resize(xRes*yRes*
getDataSize(amDataFormat));
309 memcpy ( &->data[0], amplitudes, xRes*yRes*getDataSize(amDataFormat) );
311 amp->header.frame_id =
"amplitudes";
316 void *xCoordinates, *yCoordinates, *zCoordinates;
317 status = BTAgetXYZcoordinates(frame, &xCoordinates, &yCoordinates, &zCoordinates, &dataFormat, &unit, &xRes, &yRes);
318 if (status == BTA_StatusOk) {
319 if (
_xyz->width != xRes ||
_xyz->height != yRes ||
_xyz->fields.size() != 4) {
324 "y", 1, sensor_msgs::PointField::FLOAT32,
325 "z", 1, sensor_msgs::PointField::FLOAT32,
326 "intensity", 1, sensor_msgs::PointField::UINT16);
328 _xyz->header.frame_id =
"cloud";
329 _xyz->is_dense =
true;
343 if (dataFormat == BTA_DataFormatSInt16) {
348 for (
size_t i = 0; i < yRes*xRes; i++, ++_x, ++_y, ++_z, ++_i) {
349 *_x =
static_cast<short *
>(xCoordinates)[i]*conv;
350 *_y =
static_cast<short *
>(yCoordinates)[i]*conv;
351 *_z =
static_cast<short *
>(zCoordinates)[i]*conv;
353 if(amDataFormat == BTA_DataFormatUInt16) {
354 *_i =
static_cast<unsigned short *
>(amplitudes)[i];
355 }
else if(amDataFormat == BTA_DataFormatFloat32) {
356 *_i =
static_cast<float *
>(amplitudes)[i];
361 }
else if (dataFormat == BTA_DataFormatFloat32) {
362 for (
size_t i = 0; i < yRes*xRes; i++, ++_x, ++_y, ++_z, ++_i) {
363 *_x =
static_cast<float *
>(xCoordinates)[i]*conv;
364 *_y =
static_cast<float *
>(yCoordinates)[i]*conv;
365 *_z =
static_cast<float *
>(zCoordinates)[i]*conv;
367 if(amDataFormat == BTA_DataFormatUInt16) {
368 *_i =
static_cast<unsigned short *
>(amplitudes)[i];
369 }
else if(amDataFormat == BTA_DataFormatFloat32) {
370 *_i =
static_cast<float *
>(amplitudes)[i];
381 _xyz->header.seq = frame->frameCounter;
382 _xyz->header.stamp.sec = frame->timeStamp;
419 BTAfreeFrame(&frame);
443 config_.udpDataIpAddrLen = (uint8_t)iusValue;
448 for (
int i = 1; i <=
config_.udpDataIpAddrLen; i++) {
449 std::ostringstream to_string;
451 to_string <<
nodeName_ <<
"/udpDataIpAddr/n" << i;
459 config_.udpDataPort = (uint16_t)iusValue;
464 config_.udpControlOutIpAddrLen = (uint8_t)iusValue;
469 for (
int i = 1; i <=
config_.udpControlOutIpAddrLen; i++) {
470 std::ostringstream to_string;
472 to_string <<
nodeName_ <<
"/udpControlOutIpAddr/n" << i;
480 config_.udpControlPort = (uint16_t)iusValue;
485 config_.udpControlInIpAddrLen = (uint8_t)iusValue;
491 for (
int i = 1; i <=
config_.udpControlInIpAddrLen; i++) {
492 std::ostringstream to_string;
494 to_string <<
nodeName_ <<
"/udpControlInIpAddr/n" << i;
502 config_.udpControlCallbackPort = (uint16_t)iusValue;
507 config_.tcpDeviceIpAddrLen = (uint8_t)iusValue;
512 for (
int i = 1; i <=
config_.tcpDeviceIpAddrLen; i++) {
513 std::ostringstream to_string;
515 to_string <<
nodeName_ <<
"/tcpDeviceIpAddr/n" << i;
523 config_.tcpControlPort = (uint16_t)iusValue;
528 config_.tcpDataPort = (uint16_t)iusValue;
534 config_.uartBaudRate = (uint32_t)iusValue;
536 config_.uartDataBits = (uint8_t)iusValue;
538 config_.uartStopBits = (uint8_t)iusValue;
540 config_.uartParity = (uint8_t)iusValue;
542 config_.uartTransmitterAddress = (uint8_t)iusValue;
544 config_.uartReceiverAddress = (uint8_t)iusValue;
546 config_.serialNumber = (uint32_t)iusValue;
553 config_.frameMode = (BTA_FrameMode)frameMode;
556 config_.verbosity = (uint8_t)iusValue;
559 config_.frameQueueLength = (uint16_t)iusValue;
561 int32_t frameQueueMode;
563 config_.frameQueueMode = (BTA_QueueMode)frameQueueMode;
565 #if !defined(BTA_ETH) || !defined(BTA_P100) 568 config_.deviceType = (BTA_DeviceType)deviceType;
579 BTA_DeviceInfo *deviceInfo;
583 status = (BTA_Status)-1;
584 for (
int i=0; i<10; i++) {
587 if (status != BTA_StatusOk) {
590 ROS_WARN_STREAM(
"Could not connect to the camera. status: " << status);
595 if (!BTAisConnected(
handle_)) {
601 status = BTAgetDeviceInfo(
handle_, &deviceInfo);
602 if (status != BTA_StatusOk) {
608 <<
"deviceType: " << deviceInfo->deviceType <<
"\n" 609 <<
"serialNumber: " << deviceInfo->serialNumber <<
"\n" 610 <<
"firmwareVersionMajor: " << deviceInfo->firmwareVersionMajor <<
"\n" 611 <<
"firmwareVersionMinor: " << deviceInfo->firmwareVersionMinor <<
"\n" 612 <<
"firmwareVersionNonFunc: " << deviceInfo->firmwareVersionNonFunc
618 BTAfreeDeviceInfo(deviceInfo);
647 ROS_DEBUG(
"Waiting for dynamic reconfigure configuration.");
648 boost::this_thread::sleep(boost::posix_time::seconds(0.1));
650 ROS_DEBUG(
"Dynamic reconfigure configuration received.");
659 "package://bta_tof_driver/calib.yml")) {
662 "package://bta_tof_driver/calib.yml" );
665 "package://bta_tof_driver/calib.yml" <<
666 " not found. Using an uncalibrated config_.");
678 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.