Skip to content

Commit b21f607

Browse files
authored
Update SDK to Version 0.12.0 (Slamtec#14)
* Register the rclcpp component Signed-off-by: Hunter L. Allen <[email protected]> * Update RPLIDAR SDK to version 1.12.0 Signed-off-by: Hunter L. Allen <[email protected]>
1 parent 608ce9d commit b21f607

File tree

9 files changed

+157
-60
lines changed

9 files changed

+157
-60
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_library(rplidar_composition_node SHARED
4141
${RPLIDAR_SDK_SRC}
4242
)
4343
ament_target_dependencies(rplidar_composition_node ${req_deps})
44+
rclcpp_components_register_nodes(rplidar_composition_node "rplidar_ros::rplidar_node")
4445

4546
# build direct ROS 1 port
4647
ament_auto_add_executable(rplidarNode src/node.cpp ${RPLIDAR_SDK_SRC})

sdk/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ This folder contains RPLIDAR SDK source code which is provided by RoboPeak.
2929

3030
RoboPeak Website: http://www.robopeak.com
3131
SlamTec HomePage: http://www.slamtec.com
32-
RPLIDAR_SDK_VERSION: 1.10.0
32+
RPLIDAR_SDK_VERSION: 1.12.0
3333
Note: The SDK version may not up-to-date.
3434
rplidar product: http://www.slamtec.com/en/Lidar

sdk/include/rplidar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141

4242
#include "rplidar_driver.h"
4343

44-
#define RPLIDAR_SDK_VERSION "1.10.0"
44+
#define RPLIDAR_SDK_VERSION "1.12.0"

sdk/include/rplidar_cmd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ typedef struct _rplidar_payload_acc_board_flag_t {
109109
_u32 reserved;
110110
} __attribute__((packed)) rplidar_payload_acc_board_flag_t;
111111

112+
typedef struct _rplidar_payload_hq_spd_ctrl_t {
113+
_u16 rpm;
114+
} __attribute__((packed)) rplidar_payload_hq_spd_ctrl_t;
115+
112116
// Response
113117
// ------------------------------------------
114118
#define RPLIDAR_ANS_TYPE_DEVINFO 0x4

sdk/include/rplidar_driver.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,16 @@ class RPlidarDriver {
177177
/// \param timeout The operation timeout value (in millisecond) for the serial port communication
178178
DEPRECATED(virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT)) = 0;
179179

180-
/// Set the RPLIDAR's motor pwm when using accessory board, currently valid for A2 only.
180+
/// Set the RPLIDAR's motor pwm when using accessory board, currently valid for A2 and A3 only.
181181
///
182182
/// \param pwm The motor pwm value would like to set
183183
virtual u_result setMotorPWM(_u16 pwm) = 0;
184184

185+
/// Set the RPLIDAR's motor rpm, currently valid for tof lidar only.
186+
///
187+
/// \param rpm The motor rpm value would like to set
188+
virtual u_result setLidarSpinSpeed(_u16 rpm, _u32 timeout = DEFAULT_TIMEOUT) = 0;
189+
185190
/// Start RPLIDAR's motor when using accessory board
186191
virtual u_result startMotor() = 0;
187192

@@ -195,6 +200,13 @@ class RPlidarDriver {
195200
/// \param timeout The operation timeout value (in millisecond) for the serial port communication.
196201
virtual u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
197202

203+
/// Check if the device is Tof lidar.
204+
/// Note: this API is effective if and only if getDeviceInfo has been called.
205+
///
206+
/// \param support Return the result.
207+
/// \param timeout The operation timeout value (in millisecond) for the serial port communication.
208+
virtual u_result checkIfTofLidar(bool & isTofLidar, _u32 timeout = DEFAULT_TIMEOUT) = 0;
209+
198210
/// Calculate RPLIDAR's current scanning frequency from the given scan data
199211
/// DEPRECATED, please use getFrequency(RplidarScanMode, size_t)
200212
///
@@ -302,13 +314,16 @@ class RPlidarDriver {
302314
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
303315
DEPRECATED(virtual u_result getScanDataWithInterval(rplidar_response_measurement_node_t * nodebuffer, size_t & count)) = 0;
304316

305-
/// Return received scan points even if it's not complete scan
317+
/// Return received scan points even if it's not complete scan.
306318
///
307-
/// \param nodebuffer Buffer provided by the caller application to store the scan data
319+
/// \param nodebuffer Buffer provided by the caller application to store the scan data. This buffer must be initialized by
320+
/// the caller.
308321
///
309-
/// \param count Once the interface returns, this parameter will store the actual received data count.
322+
/// \param count The caller must initialize this parameter to set the max data count of the provided buffer (in unit of rplidar_response_measurement_node_t).
323+
/// Once the interface returns, this parameter will store the actual received data count.
310324
///
311-
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
325+
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
326+
/// The interface will return RESULT_REMAINING_DATA to indicate that the given buffer is full, but that there remains data to be read.
312327
virtual u_result getScanDataWithIntervalHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count) = 0;
313328

314329
virtual ~RPlidarDriver() {}

sdk/src/arch/macOS/net_serial.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "arch/macOS/net_serial.h"
3737
#include <termios.h>
3838
#include <sys/select.h>
39+
#include <IOKit/serial/ioss.h>
3940

4041
namespace rp{ namespace arch{ namespace net{
4142

@@ -79,16 +80,8 @@ bool raw_serial::open(const char * portname, uint32_t baudrate, uint32_t flags)
7980
tcgetattr(serial_fd, &oldopt);
8081
bzero(&options,sizeof(struct termios));
8182

82-
_u32 termbaud = getTermBaudBitmap(baudrate);
83+
cfsetspeed(&options, B19200);
8384

84-
if (termbaud == (_u32)-1) {
85-
fprintf(stderr, "Baudrate %d is not supported on macOS\r\n", baudrate);
86-
close();
87-
return false;
88-
}
89-
cfsetispeed(&options, termbaud);
90-
cfsetospeed(&options, termbaud);
91-
9285
// enable rx and tx
9386
options.c_cflag |= (CLOCAL | CREAD);
9487

@@ -111,19 +104,23 @@ bool raw_serial::open(const char * portname, uint32_t baudrate, uint32_t flags)
111104
options.c_oflag &= ~OPOST;
112105

113106
tcflush(serial_fd,TCIFLUSH);
114-
/*
115-
if (fcntl(serial_fd, F_SETFL, FNDELAY))
107+
108+
if (tcsetattr(serial_fd, TCSANOW, &options))
116109
{
117110
close();
118111
return false;
119112
}
120-
*/
121-
if (tcsetattr(serial_fd, TCSANOW, &options))
122-
{
113+
114+
printf("Setting serial port baudrate...\n");
115+
116+
speed_t speed = (speed_t)baudrate;
117+
if (ioctl(serial_fd, IOSSIOSPEED, &speed)== -1) {
118+
printf("Error calling ioctl(..., IOSSIOSPEED, ...) %s - %s(%d).\n",
119+
portname, strerror(errno), errno);
123120
close();
124121
return false;
125122
}
126-
123+
127124
_is_serial_opened = true;
128125

129126
//Clear the DTR bit to let the motor spin

sdk/src/hal/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef uint32_t u_result;
8888
#define RESULT_OK 0
8989
#define RESULT_FAIL_BIT 0x80000000
9090
#define RESULT_ALREADY_DONE 0x20
91+
#define RESULT_REMAINING_DATA 0x21
9192
#define RESULT_INVALID_DATA (0x8000 | RESULT_FAIL_BIT)
9293
#define RESULT_OPERATION_FAIL (0x8001 | RESULT_FAIL_BIT)
9394
#define RESULT_OPERATION_TIMEOUT (0x8002 | RESULT_FAIL_BIT)

0 commit comments

Comments
 (0)