Skip to content

Commit

Permalink
Update SDK to Version 0.12.0 (Slamtec#14)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
allenh1 authored Jul 11, 2020
1 parent 608ce9d commit b21f607
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 60 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_library(rplidar_composition_node SHARED
${RPLIDAR_SDK_SRC}
)
ament_target_dependencies(rplidar_composition_node ${req_deps})
rclcpp_components_register_nodes(rplidar_composition_node "rplidar_ros::rplidar_node")

# build direct ROS 1 port
ament_auto_add_executable(rplidarNode src/node.cpp ${RPLIDAR_SDK_SRC})
Expand Down
2 changes: 1 addition & 1 deletion sdk/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ This folder contains RPLIDAR SDK source code which is provided by RoboPeak.

RoboPeak Website: http://www.robopeak.com
SlamTec HomePage: http://www.slamtec.com
RPLIDAR_SDK_VERSION: 1.10.0
RPLIDAR_SDK_VERSION: 1.12.0
Note: The SDK version may not up-to-date.
rplidar product: http://www.slamtec.com/en/Lidar
2 changes: 1 addition & 1 deletion sdk/include/rplidar.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@

#include "rplidar_driver.h"

#define RPLIDAR_SDK_VERSION "1.10.0"
#define RPLIDAR_SDK_VERSION "1.12.0"
4 changes: 4 additions & 0 deletions sdk/include/rplidar_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ typedef struct _rplidar_payload_acc_board_flag_t {
_u32 reserved;
} __attribute__((packed)) rplidar_payload_acc_board_flag_t;

typedef struct _rplidar_payload_hq_spd_ctrl_t {
_u16 rpm;
} __attribute__((packed)) rplidar_payload_hq_spd_ctrl_t;

// Response
// ------------------------------------------
#define RPLIDAR_ANS_TYPE_DEVINFO 0x4
Expand Down
25 changes: 20 additions & 5 deletions sdk/include/rplidar_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,16 @@ class RPlidarDriver {
/// \param timeout The operation timeout value (in millisecond) for the serial port communication
DEPRECATED(virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT)) = 0;

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

/// Set the RPLIDAR's motor rpm, currently valid for tof lidar only.
///
/// \param rpm The motor rpm value would like to set
virtual u_result setLidarSpinSpeed(_u16 rpm, _u32 timeout = DEFAULT_TIMEOUT) = 0;

/// Start RPLIDAR's motor when using accessory board
virtual u_result startMotor() = 0;

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

/// Check if the device is Tof lidar.
/// Note: this API is effective if and only if getDeviceInfo has been called.
///
/// \param support Return the result.
/// \param timeout The operation timeout value (in millisecond) for the serial port communication.
virtual u_result checkIfTofLidar(bool & isTofLidar, _u32 timeout = DEFAULT_TIMEOUT) = 0;

/// Calculate RPLIDAR's current scanning frequency from the given scan data
/// DEPRECATED, please use getFrequency(RplidarScanMode, size_t)
///
Expand Down Expand Up @@ -302,13 +314,16 @@ class RPlidarDriver {
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
DEPRECATED(virtual u_result getScanDataWithInterval(rplidar_response_measurement_node_t * nodebuffer, size_t & count)) = 0;

/// Return received scan points even if it's not complete scan
/// Return received scan points even if it's not complete scan.
///
/// \param nodebuffer Buffer provided by the caller application to store the scan data
/// \param nodebuffer Buffer provided by the caller application to store the scan data. This buffer must be initialized by
/// the caller.
///
/// \param count Once the interface returns, this parameter will store the actual received data count.
/// \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).
/// Once the interface returns, this parameter will store the actual received data count.
///
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
/// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
/// The interface will return RESULT_REMAINING_DATA to indicate that the given buffer is full, but that there remains data to be read.
virtual u_result getScanDataWithIntervalHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count) = 0;

virtual ~RPlidarDriver() {}
Expand Down
27 changes: 12 additions & 15 deletions sdk/src/arch/macOS/net_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "arch/macOS/net_serial.h"
#include <termios.h>
#include <sys/select.h>
#include <IOKit/serial/ioss.h>

namespace rp{ namespace arch{ namespace net{

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

_u32 termbaud = getTermBaudBitmap(baudrate);
cfsetspeed(&options, B19200);

if (termbaud == (_u32)-1) {
fprintf(stderr, "Baudrate %d is not supported on macOS\r\n", baudrate);
close();
return false;
}
cfsetispeed(&options, termbaud);
cfsetospeed(&options, termbaud);

// enable rx and tx
options.c_cflag |= (CLOCAL | CREAD);

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

tcflush(serial_fd,TCIFLUSH);
/*
if (fcntl(serial_fd, F_SETFL, FNDELAY))

if (tcsetattr(serial_fd, TCSANOW, &options))
{
close();
return false;
}
*/
if (tcsetattr(serial_fd, TCSANOW, &options))
{

printf("Setting serial port baudrate...\n");

speed_t speed = (speed_t)baudrate;
if (ioctl(serial_fd, IOSSIOSPEED, &speed)== -1) {
printf("Error calling ioctl(..., IOSSIOSPEED, ...) %s - %s(%d).\n",
portname, strerror(errno), errno);
close();
return false;
}

_is_serial_opened = true;

//Clear the DTR bit to let the motor spin
Expand Down
1 change: 1 addition & 0 deletions sdk/src/hal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef uint32_t u_result;
#define RESULT_OK 0
#define RESULT_FAIL_BIT 0x80000000
#define RESULT_ALREADY_DONE 0x20
#define RESULT_REMAINING_DATA 0x21
#define RESULT_INVALID_DATA (0x8000 | RESULT_FAIL_BIT)
#define RESULT_OPERATION_FAIL (0x8001 | RESULT_FAIL_BIT)
#define RESULT_OPERATION_TIMEOUT (0x8002 | RESULT_FAIL_BIT)
Expand Down
Loading

0 comments on commit b21f607

Please sign in to comment.