Slamtec RPLIDAR A1 User manual

www.slamtec.com
Shanghai Slamtec.Co.,Ltd
RPLIDAR
Low Cost 360 Degree Laser Range Scanner
Interface Protocol and Application Notes
Applied to RPLIDAR A1 & A2
2018-03-08 rev.1.1

CONTENTS ...................................................................................................................................................1
OVERVIEW ...................................................................................................................................................3
SDK AND DEMO PROGRAM .............................................................................................................................. 3
PROTOCOL BASICS ....................................................................................................................................4
BASIC COMMUNICATION MODE........................................................................................................................ 4
REQUEST PACKETS’FORMAT........................................................................................................................... 6
RESPONSE PACKETS’FORMAT......................................................................................................................... 7
WORKING STATE AND MECHANISM................................................................................................. 10
MAJOR WORKING STATES AND TRANSITION CONDITIONS ............................................................................ 10
SCANNING STATUS........................................................................................................................................... 11
REQUEST AND RESPONSE DATA......................................................................................................... 12
REQUESTS OVERVIEW....................................................................................................................................... 12
STOP REQUEST................................................................................................................................................ 12
RPLIDAR CORE RESET(RESET) REQUEST ...................................................................................................... 13
START SCAN(SCAN)REQUEST AND RESPONSE......................................................................................... 13
EXPRESS SCAN(EXPRESS_SCAN) REQUEST AND RESPONSE ........................................................................ 17
FORCE SCAN(FORCE_SCAN) REQUEST AND RESPONSE............................................................................... 23
GET DEVICE INFO (GET_INFO) REQUEST AND RESPONSE ............................................................................. 24
GET DEVICE HEALTH STATUS (GET_HEALTH) REQUEST AND RESPONSE ..................................................... 26
GET SAMPLE RATE(GET_SAMPLERATE) REQUEST........................................................................................ 27
APPLICATION NOTES ............................................................................................................................. 28
RETRIEVING SCANNING DATA FROM AN RPLIDAR ......................................................................................... 28
CALCULATE RPLIDAR SCANNING SPEED........................................................................................................ 29
REVISION HISTORY ................................................................................................................................. 31
APPENDIX .................................................................................................................................................. 32
IMAGE AND TABLE INDEX ................................................................................................................................. 32
Contents

3/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
The host system communicates with RPLIDAR core system via the TTL UART serial
interface. Based on the communication protocol defined in this document, the host
system can retrieve the scan data, the device status, the health information etc. and
manipulate RPLIDAR’s working mode.
Figure 1-1 The Communication Between RPLIDAR and Host System
Please refer to the RPLIDAR datasheet for information about the bottom layer
communication protocol and the electrical level definition of the serial signals used
to communicate with RPLIDAR. The communication protocol based on UART serial
port and the data transmission format will be introduced in this document.
SDK and Demo Program
SLAMTEC provides open-sourced SDK and demo program for customers to
integrate RPLIDAR into their systems quickly. The SDK implements all the
communication stacks, driver logics and related data structures described in this
document
The SDK supports multiple platforms including Windows, Linux, MacOS and even
bare systems without an OS.
Please refer to the SDK manual for details.
Overview
TX
RX
GND
Host System

4/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Basic Communication Mode
The RPLIDAR uses a non-textual binary data packet based protocol to communicate
with host systems. And all the packets transmitted on the interface channel share
uniform packet formats.
A communication session is always initialized by a host system, i.e. a MCU, a PC, etc.
RPLIDAR itself won’t send any data out automatically after powering up.
If a data packet is sent from host systems to RPLIDARs, such a packet is called a
Request. Once an RPLIAR receives a request, it will reply the host system with a data
packet called a Response.
RPLIDAR will only start performing related operations required by a host system
once after it receives a request. If RPLIDAR should reply to the host system, it will
send one or more required response packets.
In order to let an RPLIDAR start scanning operation and send out data, a host system
is required to send a pre-defined Start Scan request packet to RPLIDAR. RPLIDAR
will start scanning operation once after it receives the request and the scan result
data is sent out to the host system continuously.
There are three different request/response modes based on the related request
types:
Request/Response Modes
Figure 2-1 RPLIDAR Request/Response Modes
Protocol Basics
RPLIDAR
Host System
Send a Request Packet
Perform
Some
Operation
Reply a Response Packet
Waiting for
Response
Another Request

5/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Host system should prevent sending extra request packets if the RPLIDAR is busy
with handing the current request and hasn’t replied to the host system yet.
Otherwise,
these extra request packets will be discarded by the RPLIDAR’s protocol stack and
the RPLIDAR will not have any chance to handle it.
Single Request-Multiple Response Modes
This mode is used when the RPLIAR is asked to perform the scan operation. After a
host system sending a Start Scan request, RPLIDAR will take distance scan
measurement continuously. Once a scan measurement sample is retrieved, its
related result data (distance, angle value) will be sent out as individual response
packets.
Host systems are only required to send a single request packet with this mode but
will receive a continuous response packet stream with multiple response packets.
Figure 2-2 RPLIDAR Single Request - Multiple Response Mode
The host system can interrupt RPLIDAR and let it leave the multiple responses mode
by sending a STOP request or any request packet. After leaving the multiple
RPLIDAR
Host System
Send a Start Scan
Request
Initialization
Reply a response descriptor
Waiting for
response
Prepare for
receiving
Scan
Operation
Measurement Sample1
Measurement Sample2
Receiving data
…
Measurement Samplen
Another response
Exit the scan
operation
Handle other
responses

6/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
responses mode, the RPLIDAR will continue to handle the request which has
interrupted it.
The request packets sent by the host system during the multiple responses mode
will be cached by the RPLIDAR’s protocol stack. After leaving the multiple responses
mode, RPLIDAR will handle the cached request.
Single Request-No Response
For requests like STOP, RESET Core, RPLIDAR uses the single request –no response
mode since there is no need to reply to the host system.
Host systems should wait for a period of time before sending another request since
RPLIDAR needs time to process the request operation. Otherwise, the request may
be discarded by the RPLIDAR’s protocol stack.
Figure 2-3 RPLIDAR Single Request-No Response Mode
Request Packets’ Format
All request packets sent by a host system share the following common format. Little
endian byte order is used.
Figure 2-4 RPLIDAR Request Packets’ Format
RPLIDAR
Host System
Send a Request Packet
Perform
some
Operation
Waiting for
response
Another request
Start Flag
Command
Payload Size
Payload Data
Checksum
1byte
(0xA5)
1byte
1byte
0-255 bytes
1byte
Optional Section
Transmission Order
≤5 seconds

7/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
A fixed 0xA5 byte is used for each request packet, RPLIDAR uses this byte as the
identification of a new request packet. An 8bit (1byte) command field must follow
the start flag byte.
If the current request carries extra payload data, an 8bit (1byte) payload size field is
required to be transmitted after sending the command field and then follows the
payload data. After the payload data has been transmitted, an 8bit (1byte) checksum
field calculated from the previous sent data should be transmitted.
The checksum value can be calculated using the following equation:
Note: Timing Consideration
All bytes within a request packet must be transmitted to RPLIDAR within 5 seconds.
Otherwise, the communication stack of RPLIDAR will discard the current request
packet.
Response Packets’ Format
All the response packets are divided into two classes: response descriptors and
data responses. If the current request received by RPLIDAR requires a response,
RPLDAR will always send a response descriptor packet first and then send one or
more data response packets based on the type of requests. Only one response
descriptor packet will be sent out during a request/response session. The response
descriptors carry the information of the incoming data responses. All the response
descriptors share a same format.

8/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Figure 2-5 Response Packets Sent during a Single Request-Single Response Mode
Figure 2-6 Response Packets Sent during a Single Request-Multiple Response Mode
The format of response descriptors is depicted in the following figure.
Figure 2-7 RPLIDAR Response Descriptors’ Format
RPLIDAR
Host System
Request #1
Response Descriptor
Data Response
Request #2
2
…
RPLIDAR
Host System
Request #1
Response Descriptor
Data Response
Request #2
2
…
Data Response
Data Response
…
Start Flag1
Start Flag2
Data Response Length
Send Mode
Data Type
1byte (0xA5)
1byte (0x5A)
30bits
2bits
1byte
Transmission Order

9/ 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
A response descriptor uses fixed two bytes’ pattern 0xA5 0x5A for the host system
to identify the start of a response descriptor. The 30bit Data Response Length field
records the size of a single incoming data response packet in bytes. (All the
incoming data response packets within a request/response session should have the
same format and length). The 2bits Send Mode field describes the request/response
mode of the current session. Its values are listed below:
Figure 2-8 RPLIDAR Data Response Packets Value
The 1byte Data Type describes the type of the incoming data response packets. It
is related to the type of the request RPLIDAR just received. Host systems can choose
different data receiving and handling policy based on this field.
Different from response descriptors, there is no common format used among
response data packets. Each type of response data has its own data format and
packet length based on its type.
Send Mode
Description
0x0
Single Request –Single Response mode, RPLIDAR will send only one data
response packet in the current session.
0x1
Single Request –Multiple Response mode, RPLIDAR will continuously send
out data response packets with the same format in the current session.
0x2
Reserved for future use
0x3
Reserved for future use

10 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Major Working States and Transition Conditions
RPLIDAR has the following 4 major states: Idle, Scanning, Request Processing and
the Protection Stop state.
The translation conditions are depicted in the following figure:
Figure 3-1 RPLIDAR’s Major Status Translation
The Idle state is the default state of RPLIDAR which will be entered automatically
after powering up or reset. Both the laser diode and the measurement system are
disabled in this state, and the whole system is in power saving mode. Once RPLIDAR
enters the Scanning state, the laser diode and the measurement system will be
enabled and RPLIDAR will start measuring distance and sending the result out
continuously.
RPLIDAR will enter the Request Processing state once it receives request packets
from the host system. During processing the request, RPLIDAR won’t perform the
scan operation and won’t send any data out. It will only send out response data for
request needing a response after the required operation has been finished. After
the request has been processed, RPLIDAR will enter other status specified by the
request.
Once RPLIDAR detects something wrong with the device hardware, it will stop the
current operation and enter the Protection Stop state. A host system can still
communicate with an RPLIDAR in the Protection Stop state to query its working
Working State and Mechanism
Idle
Scanning
Request
Processing
Protection
Stop
Reset the core system
No Request
No
Request
No failure
System Power Up
Request comes
Partial Requests
Start Scan Request
Request comes
Failure detected
Failure detected

11 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
status. But the host system cannot ask the RPLIDAR to perform scan operations
unless the host system send a Reset request to reboot the RPLIDAR core system.
Scanning Status
RPLIDAR always checks the motor rotation status when working in the scanning
state. Only when the motor rotation speed becomes stable, RPLIDAR will start taking
distance measurement and sending out the result data to the host system.
Figure 3-2 RPLIDAR’s Working Mode during Scanning
Output
data
Waiting
rotation
stable
Scan Request
Rotation
stable
Rotation stable
Rotation unstable
Incoming Requests
Failure detected
Rotation
unstable

12 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Requests Overview
All the available requests are listed in the below table. Their detailed descriptions
are given in the following sections.
Request Name
Value
Paylo
ad
Response
Mode
RPLIDAR Operation
Supported
Firmware
Version
STOP
0x25
N/A
No response
Exit the current state
and enter the idle state
1.0
RESET
0x40
N/A
Reset(reboot) the
RPLIDAR core
1.0
SCAN
0x20
N/A
Multiple
response
Enter the scanning
state
1.0
EXPRESS_SCAN
0x82
YES
Enter the scanning
state and working at the
highest speed
1.17
FORCE_SCAN
0x21
N/A
Enter the scanning
state and force data
output without checking
rotation speed
1.0
GET_INFO
0x50
N/A
Single
response
Send out the device info
(e.g. serial number)
1.0
GET_HEALTH
0x52
N/A
Send out the device
health info
1.0
GET_SAMPLERATE
0x59
N/A
Send out single
sampling time
1.17
Figure 4-1 The Available Requests of RPLIDAR
STOP Request
RPLIDAR will exit the current scanning state once it receives the Stop (0x25) Request
sent by a host system. The laser diode and the measurement system will be disabled
and the Idle state will be entered. This request will be ignored when RPLIDAR is in
the Idle or Protection Stop state.
Since RPLIDAR won’t send response packet for this request, host systems should
wait for at least 1 millisecond (ms) before sending another request.
Request and Response Data
A5
25
Request Packet:

13 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Figure 4-2 The Timing Sequence of a STOP Request
RPLIDAR Core Reset(RESET) Request
Host systems can make RPLIDAR core to reset (reboot) itself by sending this request.
A reset operation will make RPLIDAR revert to a similar state as it has just been
powered up. This request is useful when RPLIDAR has entered the Protection Stop
state. After a core reset, RPLIDAR will return to the idle state which will accept the
start scan request again.
Since RPLIDAR won’t send response packet for this request, host systems should
wait for at least 2 milliseconds (ms) before sending another request.
Figure 4-3 The Timing Sequence of a RESET Request
Start Scan(SCAN)Request and Response
Note: RPLIDAR A2 and other device models support 4khz sampling rate will lower the
sampling rate when processing this request. Please use EXPRESS_SCAN for the best
performance.
RPLIDAR
Host System
A5
25
A5
…
≥1m
s
Next request
A5
40
Request Packet:
RPLIDAR
Host System
统
A5
40
A5
…
≥2m
s
Next Request

14 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
RPLIDAR, except for the RPLIDAR that is in the Protection Stop State, will enter the
scanning state once it receives this request from a host system. Each measurement
sample result will be sent out using an individual data response packet. If the
RPLIDAR has been in scanning state already, it will stop the current measurement
sampling and start a new round of scanning. This request will be ignored when
RPLIDAR is in the Protection Stop state.
The related response descriptor will be sent out by RPLIDAR immediately once it
receives the request and accepts it. The data response packets related to every
measurement sample results will be sent out continuously only after the motor
rotation becomes stable. RPLIDAR will leave the Scanning state once it receives a
new request from the host system or it detects something is wrong.
Format of the Data Response Packets:
Figure 4-4 Format of a RPLIDAR Measurement Result Data Response Packet
A5
20
Request Packet:
A5
5A
Response Descriptor:
05
00
00
40
81
Response Mode:
Multiple
Data Response Length:
5 bytes
Quality
S
8
2
1
0
angle_q6[6:0]
C
8
1
0
angle_q6[14:7]
8
0
distance_q2[7:0]
8
0
distance_q2[15:8]
8
0
+0
+1
+2
+3
+4
Byte Offset

15 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
RPLIDAR encapsulates each measurement sample into a data response packet with
the format showed in the above figure and send the packet out. The descriptions of
every field within the packet are listed in the following table:
Figure 4-5 Field Definition of a RPLIDAR Measurement Result Data Response Packet
The geometric definition of the included angle and distance value is shown as below:
Figure 4-6 Angle and Distance Value Geometric Definition for RPLIDAR A1 series
Field Name
Description
Examples / Notes
S
Start flag bit of a new scan
When S is set to 1, the current and
incoming packets belong to a new
360o scan.
Inversed start flag bit, always has
Can be used as a data check bit.
C
Check bit, constantly set to 1
Can be used as a data check bit.
quality
Quality of the current measurement
sample
Related the reflected laser pulse
strength.
angle_q6
The measurement heading angle
related to RPLIDAR’s heading. In
degree unit, [0-360)
Stored using fix point number.
Refer to the below figure for
details.
Actual heading =
angle_q6/64.0 Degree
distance_q2
Measured object distance related to
RPLIDAR’s rotation center.
In millimeter (mm) unit.
Represents using fix point. Set to 0
when the measurement is invalid.
Refer to the below figure for
details.
Actual Distance =
distance_q2/4.0 mm

16 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Figure 4-7 Angle and Distance Value Geometric Definition for RPLIDAR A2 series
Figure 4-8 The Communication Status after Host System Sending a SCAN Request
Interface Lead
RPLIDAR
Host System
A5
20
A5
…
a new request
Data transmission order:
…
…
S=1
360oscan
a new scan
A5
5A
05
00
00
40
81

17 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Express Scan(EXPRESS_SCAN) Request and Response
RPLIDAR will enter the measurement sampling mode once it receives the express
scan(EXPRESS_SCAN) request. Different from the scan(SCAN) request, this request
will make RPLIDAR work at the sampling rate as high as it can be. For RPLIDAR A2
and the device models support 4khz sampling rate, the host system is required to
send this request to let the RPLIDAR work at 4khz sampling rate and output
measurement sample data accordingly; for the device models with the 2khz sample
rate (such as RPLIDAR A1 series), this request will implement the same sampling rate
as the scan(SCAN) request.
The host system can send the get sample rate(GET_SAMPLERATE) request to get
the information about the single measurement sampling time in SCAN mode and
EXPRESS_SCAN mode.
RPLIDAR uses the same state machine and processing logic for this request as the
one of the scan(SCAN) request, but uses the different response format.
This command request is not supported in working mode with sampling rate more
than 4khz or ranging distance longer than 16 meters. For command request,
response data format and decoding method applying to the above working mode,
please check the RPLIDAR SDK source code on SLAMTEC official website for details
and call its startScan or startScanExpress function with mode selection parameter to
get related scan data.
Format of the request packets:
The express scan(EXPRESS_SCAN) request is required to carry the 5 bytes payload
data and the data structure is shown as following. This payload data cannot be
omitted.
A5
82
A5
5A
54
00
00
40
82
84 bytes
05
00
00
00
00
00
22
Request Packet:
Response Descriptor:
Response Mode:
Multiple
Data Response Length:

18 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Figure 4-9 Format of a RPLIDAR Express Scan Data Request Packet
The descriptions of every field within the above data are listed in the following table:
Figure 4-10 Field Definition of RPLIDAR Express Scan Data Request Packet
Field Name
Description
Examples/Notes
working_mode
The other parameters in the scan
mode of RPLIDAR, set to 0.
The field only supports for
standard scan mode currently,
set to 0.
Reserved
Reserved field, set to 0.
Reserved for future use, set to 0.
working_mode
8
0
Reserved
8
0
Reserved
8
0
Reserved
8
0
Reserved
8
0
+0
+1
+2
+3
+4
Byte Offset

19 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
Format of the data response packets:
RPLIDAR uses the following data response packet structure for responding the
EXPRESS_SCAN request.
Figure 4-11 Format of a RPLIDAR Express Scan Data Response Packet
When working in express scan mode,RPLIDAR will send the above data packet
cyclically to output the measurement data to host system. The packet contains 16
group of substructures called Cabin in the same format. Each Cabin is a 5-byte data
body with specific structure corresponding with the angle and distance value of two
measurement sampling data sets. Therefore, an express scan data response packet
carries 32 measurement sampling data points.
ChkSum[7:4]
sync1
ChkSum[3:0]
8
3
0
start_angle_q6[7:0]
8
0
start_angle_q6[14:8]
8
0
cabin[0]
40
0
+0
+1
+2
+3
+4
Byte
offset
sync2
8
3
0
S
7
cabin[1]
40
0
+9
cabin[15]
40
0
+79
…
8
2
0
+0
+1
+2
+3
distance1[13:6]
8
0
[3:0]
8
0
+4
distance1[5:0]
8
2
0
distance2 [13:6]
8
0
distance2[5:0]
[3:0]
4
Cabin

20 / 32
Copyright (c) 2009-2013 RoboPeak Team
Copyright (c) 2013-2017 Shanghai Slamtec Co., Ltd.
The descriptions of every field within the above packet are listed in the following
table:
Figure 4-12 Field Definition of RPLIDAR Express Scan Data Response Packet
Field Name
Description
Examples/Notes
sync1
Data packet start sync flag1.
Always be 0xA
It is used by host system for
identifying the start of a new
response packet.
sync2
Data packet start sync flag2.
Always be 0x5
It is used by host system for
identifying the start of a new
response packet.
start_angle_q6
The reference value for the angle
data in the current response
packet.
Stored with fix point number in q6
format and the unit is degree.
Range [0-360)
Please refer to the following
sections for information about the
calculated method of the angle
value.
It adopts the same coordinate
system definition with standard
SCAN request.
Actual angle
=start_angle_q6/64.0 Deg
S
Start flag bit of a new scan
When S is set to 1, the current and
incoming packets belong to a new
360o scan.
ChkSum
Obtained by calculating the
response data packet using XOR
operation to each packet data byte
and accumulating them together.
It is used for checking the validity of
s response data packet.
cabin
a 5-byte data body with the angle
and distance value of two
measurement sampling data sets.
A data response packet contains
16 group of cabin data.
Please refer to the following table
for detailed definition.
Other manuals for RPLIDAR A1
1
This manual suits for next models
1
Table of contents
Other Slamtec Robotics manuals

Slamtec
Slamtec SDP Mini User manual

Slamtec
Slamtec Slamware SDP User manual

Slamtec
Slamtec N5M32-R2 User manual

Slamtec
Slamtec P3Pro User manual

Slamtec
Slamtec APOLLO A4M31 User manual

Slamtec
Slamtec Mercury H2 User manual

Slamtec
Slamtec Athena 2.0 User manual

Slamtec
Slamtec SDP Mini User manual

Slamtec
Slamtec APOLLO User manual

Slamtec
Slamtec ATHENA N4M11 User manual