17 #if __ROS_VERSION == 1
18 std::string ros_api_cloud_topic =
"api_cloud";
19 std::string ros_api_cloud_polar_topic =
"api_cloud_polar";
20 std::string ros_api_visualizationmarker_topic =
"marker";
33 #if __ROS_VERSION != 1
38 fwrite(&oneByte, 1, 1,
foutJpg);
45 int field_offset_x = -1, field_offset_y = -1, field_offset_z = -1, field_offset_intensity = -1;
46 for(
int n = 0; n <
msg.fields.size; n++)
49 field_offset_x = msg_fields_buffer[n].offset;
51 field_offset_y = msg_fields_buffer[n].offset;
53 field_offset_z = msg_fields_buffer[n].offset;
55 field_offset_intensity = msg_fields_buffer[n].offset;
57 assert(field_offset_x >= 0 && field_offset_y >= 0 && field_offset_z >= 0);
59 int img_width = 250 * 4, img_height = 250 * 4;
60 uint8_t* img_pixel = (uint8_t*)calloc(3 * img_width * img_height,
sizeof(uint8_t));
62 for (
int row_idx = 0; row_idx < (int)
msg.height; row_idx++)
64 for (
int col_idx = 0; col_idx < (int)
msg.width; col_idx++)
67 int polar_point_offset = row_idx *
msg.row_step + col_idx *
msg.point_step;
68 float point_x = *((
float*)(
msg.data.buffer + polar_point_offset + field_offset_x));
69 float point_y = *((
float*)(
msg.data.buffer + polar_point_offset + field_offset_y));
70 float point_z = *((
float*)(
msg.data.buffer + polar_point_offset + field_offset_z));
71 float point_intensity = 0;
72 if (field_offset_intensity >= 0)
73 point_intensity = *((
float*)(
msg.data.buffer + polar_point_offset + field_offset_intensity));
75 int img_x = (int)(250.0
f * (-point_y + 2.0
f));
76 int img_y = (int)(250.0
f * (-point_x + 2.0
f));
77 if (img_x >= 0 && img_x < img_width && img_y >= 0 && img_y < img_height)
79 img_pixel[3 * img_y * img_width + 3 * img_x + 0] = 255;
80 img_pixel[3 * img_y * img_width + 3 * img_x + 1] = 255;
81 img_pixel[3 * img_y * img_width + 3 * img_x + 2] = 255;
86 std::string jpeg_filename = jpegfilepath;
88 std::replace(jpeg_filename.begin(), jpeg_filename.end(),
'/',
'\\');
90 std::replace(jpeg_filename.begin(), jpeg_filename.end(),
'\\',
'/');
92 std::string jpeg_filename_tmp = jpeg_filename +
"_tmp";
93 foutJpg = fopen(jpeg_filename_tmp.c_str(),
"wb");
99 _unlink(jpegfilepath.c_str());
100 rename(jpeg_filename_tmp.c_str(), jpegfilepath.c_str());
102 rename(jpeg_filename_tmp.c_str(), jpegfilepath.c_str());
112 printf(
"## ERROR sick_scan_xd_api_test: %s, error code %d\n",
msg, error_code);
119 printf(
"[Info]: apiTestCartesianPointCloudMsgCallback(apiHandle:%p): %dx%d pointcloud callback...\n", apiHandle,
msg->width,
msg->height);
120 #if __ROS_VERSION == 1
122 ros_api_cloud_publisher.
publish(pointcloud);
123 ROS_INFO_STREAM(
"apiTestCartesianPointCloudMsgCallback(apiHandle:" << apiHandle <<
"): published " << pointcloud.
width <<
"x" << pointcloud.
height <<
" pointcloud on topic \"" << ros_api_cloud_topic <<
"\"");
133 printf(
"[Info]: apiTestPolarPointCloudMsgCallback(apiHandle:%p): %dx%d pointcloud callback...\n", apiHandle,
msg->width,
msg->height);
134 #if __ROS_VERSION == 1
136 ros_api_cloud_polar_publisher.
publish(pointcloud);
137 ROS_INFO_STREAM(
"apiTestPolarPointCloudMsgCallback(apiHandle:" << apiHandle <<
"): published " << pointcloud.
width <<
"x" << pointcloud.
height <<
" pointcloud on topic \"" << ros_api_cloud_polar_topic <<
"\"");
144 printf(
"[Info]: apiTestImuMsgCallback(apiHandle:%p): Imu message, orientation=(%.6f,%.6f,%.6f,%.6f), angular_velocity=(%.6f,%.6f,%.6f), linear_acceleration=(%.6f,%.6f,%.6f)\n",
145 apiHandle,
msg->orientation.x,
msg->orientation.y,
msg->orientation.z,
msg->orientation.w,
146 msg->angular_velocity.x,
msg->angular_velocity.y,
msg->angular_velocity.y,
147 msg->linear_acceleration.x,
msg->linear_acceleration.y,
msg->linear_acceleration.z);
148 #if __ROS_VERSION == 1
157 printf(
"[Info]: apiTestLFErecMsgCallback(apiHandle:%p): LFErec message, %d fields\n", apiHandle, (
int)
msg->fields_number);
158 #if __ROS_VERSION == 1
167 printf(
"[Info]: apiTestLIDoutputstateMsgCallback(apiHandle:%p): LIDoutputstate message, state=(%d,%d,%d,%d,%d,%d,%d,%d), count=(%d,%d,%d,%d,%d,%d,%d,%d)\n", apiHandle,
168 (
int)
msg->output_state[0], (
int)
msg->output_state[1], (
int)
msg->output_state[2], (
int)
msg->output_state[3], (
int)
msg->output_state[4], (
int)
msg->output_state[5], (
int)
msg->output_state[6], (
int)
msg->output_state[7],
169 (
int)
msg->output_state[0], (
int)
msg->output_count[1], (
int)
msg->output_count[2], (
int)
msg->output_count[3], (
int)
msg->output_count[4], (
int)
msg->output_count[5], (
int)
msg->output_count[6], (
int)
msg->output_count[7]);
170 #if __ROS_VERSION == 1
179 printf(
"[Info]: apiTestRadarScanMsgCallback(apiHandle:%p): RadarScan message, %d targets, %d objects\n", apiHandle, (
int)(
msg->targets.width *
msg->targets.height), (
int)
msg->objects.size);
180 #if __ROS_VERSION == 1
185 if (ros_pointcloud.
width * ros_pointcloud.
height > 0)
186 ros_api_cloud_polar_publisher.
publish(ros_pointcloud);
194 printf(
"[Info]: apiTestLdmrsObjectArrayCallback(apiHandle:%p): LdmrsObjectArray message, %d objects\n", apiHandle, (
int)
msg->objects.size);
195 #if __ROS_VERSION == 1
204 printf(
"[Info]: apiTestVisualizationMarkerMsgCallback(apiHandle:%p): VisualizationMarker message, %d objects\n", apiHandle, (
int)
msg->markers.size);
205 #if __ROS_VERSION == 1
208 if (ros_msg.
markers.size() > 0)
209 ros_api_visualizationmarker_publisher.
publish(ros_msg);
216 printf(
"[Info]: apiTestNavPoseLandmarkMsgCallback(apiHandle:%p): pose_x=%f, pose_y=%f, yaw=%f, %d reflectors\n", apiHandle,
msg->pose_x,
msg->pose_y,
msg->pose_yaw, (
int)
msg->reflectors.size);
222 if (
msg->status_code == 1)
223 printf(
"[WARN]: apiTestDiagnosticMsgCallback(apiHandle:%p): status_code = %d (WARNING), status_message = \"%s\"\n", apiHandle,
msg->status_code,
msg->status_message);
224 else if (
msg->status_code == 2)
225 printf(
"[ERROR]: apiTestDiagnosticMsgCallback(apiHandle:%p): status_code = %d (ERROR), status_message = \"%s\"\n", apiHandle,
msg->status_code,
msg->status_message);
227 printf(
"[Info]: apiTestDiagnosticMsgCallback(apiHandle:%p): status_code = %d, status_message = \"%s\"\n", apiHandle,
msg->status_code,
msg->status_message);
228 int32_t status_code = -1;
229 char message_buffer[1024] =
"";
232 printf(
"[Info]: SickScanApiGetStatus(apiHandle:%p): status_code = %d, message = \"%s\"\n", apiHandle, status_code, message_buffer);
236 printf(
"[ERROR]: SickScanApiGetStatus(apiHandle:%p) failed\n", apiHandle);
243 if (
msg->log_level == 2)
244 printf(
"[WARN]: apiTestLogMsgCallback(apiHandle:%p): log_level = %d (WARNING), log_message = %s\n", apiHandle,
msg->log_level,
msg->log_message);
245 else if (
msg->log_level >= 3)
246 printf(
"[ERROR]: apiTestLogMsgCallback(apiHandle:%p): log_level = %d (ERROR), log_message = %s\n", apiHandle,
msg->log_level,
msg->log_message);
248 printf(
"[Info]: apiTestLogMsgCallback(apiHandle:%p): log_level = %d, log_message = %s\n", apiHandle,
msg->log_level,
msg->log_message);
254 double wait_next_message_timeout = 0.1;
264 odom_msg.
vel_x = +1.0f;
265 odom_msg.
vel_y = -1.0f;
266 odom_msg.
omega = 0.5f;
270 navodom_msg.
vel_x = +1.0f;
271 navodom_msg.
vel_y = -1.0f;
272 navodom_msg.
omega = 0.5f;
275 while(run_flag && *run_flag)
282 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextCartesianPointCloudMsg failed\n");
290 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextPolarPointCloudMsg failed\n");
298 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextImuMsg failed\n");
306 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextLFErecMsg failed\n");
314 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextLIDoutputstateMsg failed\n");
322 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextRadarScanMsg failed\n");
330 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextLdmrsObjectArrayMsg failed\n");
338 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextVisualizationMarkerMsg failed\n");
346 printf(
"## ERROR sick_scan_xd_api_test: SickScanApiWaitNextNavPoseLandmarkMsg failed\n");
365 #if __ROS_VERSION == 1
367 exitOnError(
"SickScanApiInitByLaunchfile failed", ret);
374 std::thread* run_polling_thread = 0;
383 exitOnError(
"SickScanApiRegisterCartesianPointCloudMsg failed", ret);
385 exitOnError(
"SickScanApiRegisterCartesianPointCloudMsg failed", ret);
389 exitOnError(
"SickScanApiRegisterImuMsg failed", ret);
393 exitOnError(
"SickScanApiRegisterLFErecMsg failed", ret);
397 exitOnError(
"SickScanApiRegisterLIDoutputstateMsg failed", ret);
401 exitOnError(
"SickScanApiRegisterRadarScanMsg failed", ret);
405 exitOnError(
"SickScanApiRegisterLdmrsObjectArrayMsg failed", ret);
409 exitOnError(
"SickScanApiRegisterVisualizationMarkerMsg failed", ret);
413 exitOnError(
"SickScanApiRegisterVisualizationSickScanApiRegisterNavPoseLandmarkMsgMarkerMsg failed", ret);
417 exitOnError(
"SickScanApiRegisterDiagnosticMsg failed", ret);
421 exitOnError(
"SickScanApiRegisterLogMsg failed", ret);
427 char sopas_response_buffer[1024] = { 0 };
430 #if __ROS_VERSION == 1
432 #elif __ROS_VERSION == 0 && defined _MSC_VER
433 while (_kbhit() == 0)
436 printf(
"sick_scan_xd_api_test running. Press ENTER to exit or r for re-initialization\n");
443 printf(
"sick_scan_xd_api_test: user_key = '%c' (%d)\n", (
char)
user_key,
user_key);
444 const char* sopas_request = 0;
446 sopas_request =
"sRN SCdevicestate";
452 printf(
"## WARNING sick_scan_xd_api_test: SickScanApiSendSOPAS(\"%s\") failed\n", sopas_request);
454 printf(
"sick_scan_xd_api_test: SickScanApiSendSOPAS(\"%s\") succeeded: response = \"%s\"\n\n", sopas_request, sopas_response_buffer);
463 printf(
"sick_scan_xd_api_test finishing...\n");
469 if (run_polling_thread->joinable())
470 run_polling_thread->join();
471 delete run_polling_thread;
472 run_polling_thread = 0;
500 int main(
int argc,
char** argv)
503 std::string sick_scan_args;
506 #if __ROS_VERSION == 1
507 sick_scan_args =
"./src/sick_scan_xd/launch/sick_tim_7xx.launch";
508 for (
int n = 0; n < argc; n++)
510 printf(
"%s%s", (n > 0 ?
" " :
""), argv[n]);
511 if (strncmp(argv[n],
"_sick_scan_args:=", 17) == 0)
512 sick_scan_args = argv[n] + 17;
513 if (strncmp(argv[n],
"_polling:=", 10) == 0 && atoi(argv[n] + 10) > 0)
516 ros::init(argc, argv,
"sick_scan_xd_api_test");
522 printf(
"\nsick_scan_xd_api_test started\n");
525 std::string sick_scan_api_lib =
"sick_scan_xd_shared_lib.dll";
526 std::vector<std::string> search_library_path = {
"",
"build/Debug/",
"build_win64/Debug/",
"src/build/Debug/",
"src/build_win64/Debug/",
"src/sick_scan_xd/build/Debug/",
"src/sick_scan_xd/build_win64/Debug/",
"./",
"../" };
528 std::string sick_scan_api_lib =
"libsick_scan_xd_shared_lib.so";
529 std::vector<std::string> search_library_path = {
"",
"build/",
"build_linux/",
"src/build/",
"src/build_linux/",
"src/sick_scan_xd/build/",
"src/sick_scan_xd/build_linux/",
"./",
"../" };
532 for(
int search_library_cnt = 0; search_library_cnt < search_library_path.size(); search_library_cnt++)
534 std::string libfilepath = search_library_path[search_library_cnt] + sick_scan_api_lib;
537 printf(
"sick_scan_xd library \"%s\" loaded successfully\n", libfilepath.c_str());
538 sick_scan_api_lib = libfilepath;
551 printf(
"sick_scan_xd_api_test finished with user key '%c' (%d), re-initialize and repeat sick_scan_xd_api_test ...\n", (
char)
user_key,
user_key);
555 printf(
"sick_scan_xd_api_test finishing...\n");
557 exitOnError(
"SickScanApiUnloadLibrary failed", ret);
558 printf(
"sick_scan_xd_api_test finished successfully\n");
562 printf(
"\nsick_scan_xd_api_test: reload %s\n", sick_scan_api_lib.c_str());
565 printf(
"\nsick_scan_xd_api_test: restart\n");
571 printf(
"sick_scan_xd_api_test finished with user key '%c' (%d), re-initialize and repeat sick_scan_xd_api_test ...\n", (
char)
user_key,
user_key);
573 printf(
"sick_scan_xd_api_test finishing...\n");
575 exitOnError(
"SickScanApiUnloadLibrary failed", ret);
576 printf(
"sick_scan_xd_api_test finished successfully\n");