68 std::string anglePath, curvesPath, channelPath, curvesRatePath;
71 private_nh.
param(
"curves_path", curvesPath, std::string(
""));
72 private_nh.
param(
"angle_path", anglePath, std::string(
""));
73 private_nh.
param(
"channel_path", channelPath, std::string(
""));
74 private_nh.
param(
"curves_rate_path", curvesRatePath, std::string(
""));
81 private_nh.
param(
"model", model, std::string(
"RS16"));
86 else if (model ==
"RS32")
96 FILE* f_inten = fopen(curvesPath.c_str(),
"r");
106 fseek(f_inten, 0, SEEK_END);
107 int size = ftell(f_inten);
119 fseek(f_inten, 0, SEEK_SET);
120 while (!feof(f_inten))
125 if (loopi > loop_num)
129 int tmp = fscanf(f_inten,
"%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", &a[0], &a[1], &a[2], &a[3],
130 &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10], &a[11], &a[12], &a[13], &a[14], &a[15]);
134 int tmp = fscanf(f_inten,
"%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f," 136 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10], &a[11], &a[12],
137 &a[13], &a[14], &a[15], &a[16], &a[17], &a[18], &a[19], &a[20], &a[21], &a[22], &a[23], &a[24],
138 &a[25], &a[26], &a[27], &a[28], &a[29], &a[30], &a[31]);
159 FILE* f_angle = fopen(anglePath.c_str(),
"r");
169 while (!feof(f_angle))
171 int tmp = fscanf(f_angle,
"%f,%f\n", &b[loopk], &d[loopk]);
185 FILE* f_channel = fopen(channelPath.c_str(),
"r");
196 while (!feof(f_channel))
200 int tmp = fscanf(f_channel,
201 "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%" 202 "d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
203 &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12],
204 &c[13], &c[14], &c[15], &c[16], &c[17], &c[18], &c[19], &c[20], &c[21], &c[22], &c[23], &c[24],
205 &c[25], &c[26], &c[27], &c[28], &c[29], &c[30], &c[31], &c[32], &c[33], &c[34], &c[35], &c[36],
206 &c[37], &c[38], &c[39], &c[40]);
211 f_channel,
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%" 212 "d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
213 &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12], &c[13],
214 &c[14], &c[15], &c[16], &c[17], &c[18], &c[19], &c[20], &c[21], &c[22], &c[23], &c[24], &c[25], &c[26],
215 &c[27], &c[28], &c[29], &c[30], &c[31], &c[32], &c[33], &c[34], &c[35], &c[36], &c[37], &c[38], &c[39],
216 &c[40], &c[41], &c[42], &c[43], &c[44], &c[45], &c[46], &c[47], &c[48], &c[49], &c[50]);
237 FILE* f_curvesRate = fopen(curvesRatePath.c_str(),
"r");
241 for (
int i = 0; i < 32; ++i)
249 while (!feof(f_curvesRate))
251 int tmp = fscanf(f_curvesRate,
"%f\n", &
CurvesRate[loopk]);
256 fclose(f_curvesRate);
269 const uint8_t*
data = &difop_msg->data[0];
273 if ((data[41] == 0x00 && data[42] == 0x00 && data[43] == 0x00) ||
274 (data[41] == 0xff && data[42] == 0xff && data[43] == 0xff) ||
275 (data[41] == 0x55 && data[42] == 0xaa && data[43] == 0x5a))
278 std::cout <<
"The distance resolution is 1cm" << std::endl;
283 std::cout <<
"The distance resolution is 0.5cm" << std::endl;
291 if (data[0] == 0xa5 && data[1] == 0xff && data[2] == 0x00 && data[3] == 0x5a)
293 bool curve_flag =
true;
295 if ((data[50] == 0x00 || data[50] == 0xff) && (data[51] == 0x00 || data[51] == 0xff) &&
296 (data[52] == 0x00 || data[52] == 0xff) && (data[53] == 0x00 || data[53] == 0xff))
305 unsigned char checkbit;
310 checkbit = *(data + 50 + loopn * 15) ^ *(data + 50 + loopn * 15 + 1);
311 for (
int loopm = 1; loopm < 7; ++loopm)
313 checkbit = checkbit ^ (*(data + 50 + loopn * 15 + loopm * 2)) ^ (*(data + 50 + loopn * 15 + loopm * 2 + 1));
315 if (checkbit != *(data + 50 + loopn * 15 + 14))
323 bit1 =
static_cast<int>(*(data + 50 + loopn * 15));
324 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 1));
326 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 2));
327 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 3));
329 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 4));
330 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 5));
332 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 6));
333 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 7));
335 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 8));
336 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 9));
338 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 10));
339 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 11));
341 bit1 =
static_cast<int>(*(data + 50 + loopn * 15 + 12));
342 bit2 =
static_cast<int>(*(data + 50 + loopn * 15 + 13));
346 std::cout <<
"this->is_init_curve_ = " 347 <<
"true!" << std::endl;
351 if ((data[290] != 0x00) && (data[290] != 0xff))
357 if ((data[291] == 0x00) || (data[291] == 0xff) || (data[291] == 0xa1))
362 else if (data[291] == 0xb1)
373 if (data[0] == 0xa5 && data[1] == 0xff && data[2] == 0x00 && data[3] == 0x5a)
375 bool angle_flag =
true;
377 if ((data[1165] == 0x00 || data[1165] == 0xff) && (data[1166] == 0x00 || data[1166] == 0xff) &&
378 (data[1167] == 0x00 || data[1167] == 0xff) && (data[1168] == 0x00 || data[1168] == 0xff))
386 int bit1, bit2, bit3, symbolbit;
389 if (loopn < 8 && numOfLasers == 16)
397 bit1 =
static_cast<int>(*(data + 1165 + loopn * 3));
398 bit2 =
static_cast<int>(*(data + 1165 + loopn * 3 + 1));
399 bit3 =
static_cast<int>(*(data + 1165 + loopn * 3 + 2));
400 VERT_ANGLE[loopn] = (bit1 * 256 * 256 + bit2 * 256 + bit3) * symbolbit * 0.0001
f / 180 * M_PI;
406 std::cout <<
"this->is_init_angle_ = " 407 <<
"true!" << std::endl;
418 if (pixelValue <=
g_ChannelNum[passageway][indexTemper])
424 DistanceValue = (float)(pixelValue -
g_ChannelNum[passageway][indexTemper]);
426 return DistanceValue;
432 if (azimuth_f > 0.0 && azimuth_f < 3000.0)
434 azimuth_f = azimuth_f +
HORI_ANGLE[passageway] + 36000.0f;
438 azimuth_f = azimuth_f +
HORI_ANGLE[passageway];
440 azimuth = (int)azimuth_f;
457 float endOfSection1, endOfSection2;
461 realPwr = std::max((
float)(intensity / (1 + (temp -
TEMPERATURE_MIN) / 24.0
f)), 1.0
f);
467 if ((
int)realPwr < 126)
468 realPwr = realPwr * 4.0f;
469 else if ((
int)realPwr >= 126 && (
int)realPwr < 226)
470 realPwr = (realPwr - 125.0f) * 16.0
f + 500.0
f;
472 realPwr = (realPwr - 225.0f) * 256.0
f + 2100.0
f;
477 if ((
int)realPwr < 64)
479 else if ((
int)realPwr >= 64 && (int)realPwr < 176)
480 realPwr = (realPwr - 64.0f) * 4.0
f + 64.0
f;
482 realPwr = (realPwr - 176.0f) * 16.0
f + 512.0
f;
486 std::cout <<
"The intensity mode is not right" << std::endl;
493 sDist = (sDist < uplimitDist) ? sDist : uplimitDist;
498 float refPwr_temp = 0.0f;
500 endOfSection1 = 5.0f;
501 endOfSection2 = 40.0;
514 if (distance_f <= endOfSection1)
522 for (
int i = 0; i < order; i++)
524 refPwr_temp +=
aIntensityCal[i + 4][calIdx] * (pow(distance_f, order - 1 - i));
531 if (distance_f <= endOfSection1)
537 else if (distance_f > endOfSection1 && distance_f <= endOfSection2)
539 for (
int i = 0; i < order; i++)
541 refPwr_temp +=
aIntensityCal[i + 4][calIdx] * (pow(distance_f, order - 1 - i));
547 float refPwr_temp0 = 0.0f;
548 float refPwr_temp1 = 0.0f;
549 for (
int i = 0; i < order; i++)
551 refPwr_temp0 +=
aIntensityCal[i + 4][calIdx] * (pow(40.0
f, order - 1 - i));
552 refPwr_temp1 +=
aIntensityCal[i + 4][calIdx] * (pow(39.0
f, order - 1 - i));
554 refPwr_temp = 0.3f * (refPwr_temp0 - refPwr_temp1) * distance_f + refPwr_temp0;
559 std::cout <<
"Invalid intensity mode selected" << std::endl;
562 refPwr = std::max(std::min(refPwr_temp, 500.0
f), 4.0
f);
569 tempInten = (int)tempInten > 255 ? 255.0
f : tempInten;
585 realPwr = std::max((
float)(intensity / (1 + (temp -
TEMPERATURE_MIN) / 24.0
f)), 1.0
f);
588 if ((
int)realPwr < 126)
589 realPwr = realPwr * 4.0f;
590 else if ((
int)realPwr >= 126 && (
int)realPwr < 226)
591 realPwr = (realPwr - 125.0f) * 16.0
f + 500.0
f;
593 realPwr = (realPwr - 225.0f) * 256.0
f + 2100.0
f;
598 sDist = (sDist < uplimitDist) ? sDist : uplimitDist;
604 tempInten = (51 * refPwr) / realPwr;
609 tempInten = (int)tempInten > 255 ? 255.0
f : tempInten;
617 if ((distance & 32768) != 0)
632 float bitneg = bit2 & 128;
633 float highbit = bit2 & 127;
634 float lowbit = bit1 >> 3;
637 Temp = -1 * (highbit * 32 + lowbit) * 0.0625
f;
641 Temp = (highbit * 32 + lowbit) * 0.0625
f;
650 int temp = (int)floor(Temper + 0.5);
669 void RawData::unpack(
const rslidar_msgs::rslidarPacket& pkt, pcl::PointCloud<pcl::PointXYZI>::Ptr pointcloud)
679 float azimuth_corrected_f;
680 int azimuth_corrected;
692 if (tempPacketNum < 20000 && tempPacketNum > 0)
705 if (block < (BLOCKS_PER_PACKET - 1))
710 azimuth_diff = (float)((36000 + azi1 - azi2) % 36000);
713 if (azimuth_diff <= 0.0 || azimuth_diff > 75.0)
723 azimuth_diff = (float)((36000 + azi1 - azi2) % 36000);
726 if (azimuth_diff <= 0.0 || azimuth_diff > 75.0)
738 azimuth_corrected = ((int)round(azimuth_corrected_f)) % 36000;
762 float arg_horiz = (float)azimuth_corrected / 18000.0
f * M_PI;
764 pcl::PointXYZI point;
772 pointcloud->at(2 * this->
block_num + firing, dsr) = point;
781 point.y = -distance2 * cos(arg_vert) * sin(arg_horiz);
782 point.x = distance2 * cos(arg_vert) * cos(arg_horiz);
783 point.z = distance2 * sin(arg_vert);
784 point.intensity = intensity;
785 pointcloud->at(2 * this->
block_num + firing, dsr) = point;
792 void RawData::unpack_RS32(
const rslidar_msgs::rslidarPacket& pkt, pcl::PointCloud<pcl::PointXYZI>::Ptr pointcloud)
797 float azimuth_corrected_f;
798 int azimuth_corrected;
810 if (tempPacketNum < 20000 && tempPacketNum > 0)
823 if (block < (BLOCKS_PER_PACKET - 1))
828 azimuth_diff = (float)((36000 + azi1 - azi2) % 36000);
831 if (azimuth_diff <= 0.0 || azimuth_diff > 25.0)
841 azimuth_diff = (float)((36000 + azi1 - azi2) % 36000);
844 if (azimuth_diff <= 0.0 || azimuth_diff > 25.0)
872 intensity = (float)raw->
blocks[block].
data[k + 2];
878 float arg_horiz = (float)azimuth_corrected / 18000.0
f * M_PI;
880 pcl::PointXYZI point;
888 pointcloud->at(this->
block_num, dsr) = point;
897 point.y = -distance2 * cos(arg_vert) * sin(arg_horiz);
898 point.x = distance2 * cos(arg_vert) * cos(arg_horiz);
899 point.z = distance2 * sin(arg_vert);
900 point.intensity = intensity;
901 pointcloud->at(this->
block_num, dsr) = point;
917 if (ABflag == 1 && dsr < 16)
921 else if (ABflag == 1 && dsr >= 16)
949 intensity = (float)raw->
blocks[block].
data[index + 2];
955 float arg_horiz = (float)azimuth_corrected / 18000.0
f * M_PI;
957 pcl::PointXYZI point;
965 pointcloud->at(this->
block_num, dsr) = point;
974 point.y = -distance2 * cos(arg_vert) * sin(arg_horiz);
975 point.x = distance2 * cos(arg_vert) * cos(arg_horiz);
976 point.z = distance2 * sin(arg_vert);
977 point.intensity = intensity;
978 pointcloud->at(this->
block_num, dsr) = point;
Interfaces for interpreting raw packets from the Robosense 3D LIDAR.
static const int RAW_SCAN_SIZE
float computeTemperature(unsigned char bit1, unsigned char bit2)
static const float RS16_FIRING_TOFFSET
static const int RS16_SCANS_PER_FIRING
static const float DISTANCE_RESOLUTION_NEW
static const float RS32_BLOCK_TDURATION
float calibrateIntensity(float inten, int calIdx, int distance)
static const float DISTANCE_MAX_UNITS
uint16_t header
UPPER_BANK or LOWER_BANK.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int estimateTemperature(float Temper)
static const int RS32_SCANS_PER_FIRING
uint8_t data[BLOCK_DATA_SIZE]
combine rotation1 and rotation2 together to get 0-35999, divide by 100 to get degrees ...
void unpack(const rslidar_msgs::rslidarPacket &pkt, pcl::PointCloud< pcl::PointXYZI >::Ptr pointcloud)
convert raw packet to point cloud
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
static const float DISTANCE_RESOLUTION
static const int RS16_FIRINGS_PER_BLOCK
float aIntensityCal_old[1600][32]
int isABPacket(int distance)
float calibrateIntensity_old(float inten, int calIdx, int distance)
ros::Subscriber difop_sub_
float aIntensityCal[7][32]
static const int BLOCKS_PER_PACKET
static const float RS16_BLOCK_TDURATION
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void loadConfigFile(ros::NodeHandle node, ros::NodeHandle private_nh)
static const uint16_t UPPER_BANK
static const float RS16_DSR_TOFFSET
void processDifop(const rslidar_msgs::rslidarPacket::ConstPtr &difop_msg)
#define ROS_INFO_STREAM(args)
static const int TEMPERATURE_MIN
TFSIMD_FORCE_INLINE tfScalar distance2(const Vector3 &v) const
static const float RS32_DSR_TOFFSET
float pixelToDistance(int pixelValue, int passageway)
#define ROS_ERROR_STREAM(args)
static const int RS32_FIRINGS_PER_BLOCK
#define ROS_INFO_STREAM_THROTTLE(rate, args)
void unpack_RS32(const rslidar_msgs::rslidarPacket &pkt, pcl::PointCloud< pcl::PointXYZI >::Ptr pointcloud)
raw_block_t blocks[BLOCKS_PER_PACKET]
int correctAzimuth(float azimuth_f, int passageway)
RSLIDAR data conversion class.