demo_online.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*********************************************************************************************************************
  2. Copyright (c) 2020 RoboSense
  3. All rights reserved
  4. By downloading, copying, installing or using the software you agree to this license. If you do not agree to this
  5. license, do not download, install, copy or use the software.
  6. License Agreement
  7. For RoboSense LiDAR SDK Library
  8. (3-clause BSD License)
  9. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  10. following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  12. disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  14. disclaimer in the documentation and/or other materials provided with the distribution.
  15. 3. Neither the names of the RoboSense, nor Suteng Innovation Technology, nor the names of other contributors may be used
  16. to endorse or promote products derived from this software without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  18. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *********************************************************************************************************************/
  25. #include <rs_driver/api/lidar_driver.hpp>
  26. #ifdef ENABLE_PCL_POINTCLOUD
  27. #include <rs_driver/msg/pcl_point_cloud_msg.hpp>
  28. #else
  29. #include <rs_driver/msg/point_cloud_msg.hpp>
  30. #endif
  31. typedef PointXYZI PointT;
  32. typedef PointCloudT<PointT> PointCloudMsg;
  33. using namespace robosense::lidar;
  34. std::shared_ptr<PointCloudMsg> pointCloudGetCallback(void)
  35. {
  36. return std::make_shared<PointCloudMsg>();
  37. }
  38. /**
  39. * @brief The point cloud callback function. This function will be registered to lidar driver.
  40. * When the point cloud message is ready, driver can send out messages through this function.
  41. * @param msg The lidar point cloud message.
  42. */
  43. void pointCloudPutCallback(std::shared_ptr<PointCloudMsg> msg)
  44. {
  45. /* Note: Please do not put time-consuming operations in the callback function! */
  46. /* Make a copy of the message and process it in another thread is recommended*/
  47. RS_MSG << "msg: " << msg->seq << " point cloud size: " << msg->points.size() << RS_REND;
  48. }
  49. /**
  50. * @brief The exception callback function. This function will be registered to lidar driver.
  51. * @param code The error code struct.
  52. */
  53. void exceptionCallback(const Error& code)
  54. {
  55. /* Note: Please do not put time-consuming operations in the callback function! */
  56. /* Make a copy of the error message and process it in another thread is recommended*/
  57. RS_WARNING << code.toString() << RS_REND;
  58. }
  59. int main(int argc, char* argv[])
  60. {
  61. RS_TITLE << "------------------------------------------------------" << RS_REND;
  62. RS_TITLE << " RS_Driver Core Version: v" << getDriverVersion() << RS_REND;
  63. RS_TITLE << "------------------------------------------------------" << RS_REND;
  64. RSDriverParam param; ///< Create a parameter object
  65. param.input_type = InputType::ONLINE_LIDAR;
  66. param.input_param.msop_port = 6699; ///< Set the lidar msop port number, the default is 6699
  67. param.input_param.difop_port = 7788; ///< Set the lidar difop port number, the default is 7788
  68. param.lidar_type = LidarType::RSM1; ///< Set the lidar type. Make sure this type is correct
  69. param.print();
  70. LidarDriver<PointCloudMsg> driver;
  71. driver.regPointCloudCallback(pointCloudGetCallback, pointCloudPutCallback); ///< Register the point cloud callback function
  72. driver.regExceptionCallback(exceptionCallback); ///< Register the exception callback function
  73. if (!driver.init(param)) ///< Call the init function
  74. {
  75. RS_ERROR << "Driver Initialize Error..." << RS_REND;
  76. return -1;
  77. }
  78. driver.start(); ///< The driver thread will start
  79. RS_DEBUG << "RoboSense Lidar-Driver Linux online demo start......" << RS_REND;
  80. while (true)
  81. {
  82. std::this_thread::sleep_for(std::chrono::seconds(1));
  83. }
  84. return 0;
  85. }