v2

Dependencies:   BEAR_Protocol_Edited BufferedSerial Debug MaxSonar PID Process QEI UI iSerial mbed

Fork of clean_V1 by Betago

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rplidar.h Source File

rplidar.h

00001 /*
00002  * RoboPeak RPLIDAR Driver for Arduino
00003  * RoboPeak.com
00004  *
00005  * Copyright (c) 2014, RoboPeak
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without modification,
00009  * are permitted provided that the following conditions are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright notice,
00012  *    this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright notice,
00015  *    this list of conditions and the following disclaimer in the documentation
00016  *    and/or other materials provided with the distribution.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00019  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00021  * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00022  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00023  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00025  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  *
00028  */
00029 
00030 #pragma once
00031 #include "mbed.h"
00032 #include "inc/rptypes.h"
00033 #include "inc/rplidar_cmd.h"
00034 #include "../BufferedSerial/BufferedSerial.h"
00035 struct RPLidarMeasurement
00036 {
00037     float distance;
00038     float angle;
00039     uint8_t quality;
00040     bool  startBit;
00041 };
00042 
00043 class RPLidar
00044 {
00045 public:
00046     enum {
00047         RPLIDAR_SERIAL_BAUDRATE = 115200,
00048         RPLIDAR_DEFAULT_TIMEOUT = 500,
00049     };
00050 
00051     RPLidar();
00052     ~RPLidar();
00053 
00054     // open the given serial interface and try to connect to the RPLIDAR
00055     //bool begin(BufferedSerial &serialobj);
00056     void begin(BufferedSerial &serialobj);
00057     // close the currently opened serial interface
00058     void end();
00059 
00060     // check whether the serial interface is opened
00061   //  bool isOpen();
00062 
00063     // ask the RPLIDAR for its health info
00064     u_result getHealth(rplidar_response_device_health_t & healthinfo, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
00065 
00066     // ask the RPLIDAR for its device info like the serial number
00067     u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
00068 
00069     // stop the measurement operation
00070     u_result stop();
00071 
00072     // start the measurement operation
00073     u_result startScan(bool force = true, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT*2);
00074 
00075     // wait for one sample point to arrive
00076     u_result waitPoint(_u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
00077     u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
00078     // retrieve currently received sample point
00079     int Data[360];
00080     int ang,dis;
00081     int angMin,angMax;
00082     void setAngle(int min,int max);
00083     void get_lidar();
00084     const RPLidarMeasurement & getCurrentPoint()
00085     {
00086         return _currentMeasurement;
00087     }
00088 
00089 protected:
00090 //    u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
00091     u_result _waitResponseHeader(rplidar_ans_header_t * header, _u32 timeout);
00092 
00093 protected:
00094     BufferedSerial * _bined_serialdev;
00095     RPLidarMeasurement _currentMeasurement;
00096 };