Documentation ¶
Overview ¶
Package gorplidar provides a library to control the Slamtec RPLidar.
Protocol: https://www.robotshop.com/media/files/pdf2/rpk-02-communication-protocol.pdf
This package aims to satisfy the communication protocol specified in the document linked above.
Currently, not all protocols are supported. Configurability could also be improved, as many options are set by default on instantiation of the RPLidar structure.
Example usage:
package main import ( "fmt" "log" "github.com/gorplidar" ) func main() { lidar := gorplidar.NewRPLidar("/dev/ttyUSB0", 115200) lidar.Connect() status, errcode, err := lidar.Health() if err != nil { log.Fatal(err) } else if status == "Warning" { log.Printf("Lidar status: %v Error Code: %v\n", status, errcode) } else if status == "Error" { log.Fatalf("Lidar status: %v Error Code: %v\n", status, errcode) } lidar.StartMotor() scanResults, err := lidar.StartScan(3) if err != nil { log.Fatal(err) } for _, p := range scanResults { fmt.Printf("Quality: %v\tAngle: %.2f\tDistance: %.2f\n", p.Quality, p.Angle, p.Distance) } lidar.StopMotor() lidar.Disconnect() }
Index ¶
- type RPLidar
- func (rpl *RPLidar) Connect() error
- func (rpl *RPLidar) DeviceInfo() (*RPLidarInfo, error)
- func (rpl *RPLidar) Disconnect() error
- func (rpl *RPLidar) ExpressScan(scanCycles int) ([]*RPLidarPoint, error)
- func (rpl *RPLidar) Health() (string, int, error)
- func (rpl *RPLidar) PWM(pwm uint16) error
- func (rpl *RPLidar) Reset()
- func (rpl *RPLidar) SampleRate() (int, int, error)
- func (rpl *RPLidar) StartMotor() error
- func (rpl *RPLidar) StartScan(scanCycles int) ([]*RPLidarPoint, error)
- func (rpl *RPLidar) StopMotor() error
- func (rpl *RPLidar) StopScan()
- type RPLidarInfo
- type RPLidarPoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RPLidar ¶
type RPLidar struct { MotorActive bool Connected bool Scanning bool // contains filtered or unexported fields }
RPLidar holds information used to communicate through serial to the lidar.
func NewRPLidar ¶
NewRPLidar creates an instance of RPLidar. The portName refers to the name of the serial port. Baudrate is the rate at which data is transfered through the serial.
func (*RPLidar) Connect ¶
Connect establishes a serial communication channel with the lidar using the information provided form RPLidar.
func (*RPLidar) DeviceInfo ¶
func (rpl *RPLidar) DeviceInfo() (*RPLidarInfo, error)
DeviceInfo returns a struct containing information about the lidar.
func (*RPLidar) Disconnect ¶
Disconnect closes serial communication.
func (*RPLidar) ExpressScan ¶
func (rpl *RPLidar) ExpressScan(scanCycles int) ([]*RPLidarPoint, error)
ExpressScan performs a scan as fast as possible (A2 4khz). The A1 device should just use the StartScan function because of the same sampling rate (2khz).
func (*RPLidar) Health ¶
Health returns a string representing the status and an error code representing the health of the lidar.
func (*RPLidar) PWM ¶
PWM stands for Pulse Width Modulation. pwm can be zero or less than or equal to 1023.
func (*RPLidar) Reset ¶
func (rpl *RPLidar) Reset()
Reset forces the lidar to reset into a state similar to after powering up.
func (*RPLidar) SampleRate ¶
SampleRate returns a single measurement duration for standard and express scanning modes. This function seems to only be supported by the A2 model. The time is measured in micro seconds. The first int returned is the standard, the second is the express.
func (*RPLidar) StartMotor ¶
StartMotor toggles the motor into an active spinning state.
func (*RPLidar) StartScan ¶
func (rpl *RPLidar) StartScan(scanCycles int) ([]*RPLidarPoint, error)
StartScan begins a lidar scan for the amount of scan cycles desired. The scans parameter refers to how many scan cycles will occur.
type RPLidarInfo ¶
RPLidarInfo is returned by GetDeviceInfo.