v1

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

Fork of CleaningMachine_Betago by palm and chin

Committer:
palmdotax
Date:
Tue Jun 07 03:26:08 2016 +0000
Revision:
5:fe76f3dae81e
Parent:
4:de5a65c17664
v2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
palmdotax 2:f873deba2305 1 /*
palmdotax 2:f873deba2305 2 * RoboPeak RPLIDAR Driver for Arduino
palmdotax 2:f873deba2305 3 * RoboPeak.com
palmdotax 2:f873deba2305 4 *
palmdotax 2:f873deba2305 5 * Copyright (c) 2014, RoboPeak
palmdotax 2:f873deba2305 6 * All rights reserved.
palmdotax 2:f873deba2305 7 *
palmdotax 2:f873deba2305 8 * Redistribution and use in source and binary forms, with or without modification,
palmdotax 2:f873deba2305 9 * are permitted provided that the following conditions are met:
palmdotax 2:f873deba2305 10 *
palmdotax 2:f873deba2305 11 * 1. Redistributions of source code must retain the above copyright notice,
palmdotax 2:f873deba2305 12 * this list of conditions and the following disclaimer.
palmdotax 2:f873deba2305 13 *
palmdotax 2:f873deba2305 14 * 2. Redistributions in binary form must reproduce the above copyright notice,
palmdotax 2:f873deba2305 15 * this list of conditions and the following disclaimer in the documentation
palmdotax 2:f873deba2305 16 * and/or other materials provided with the distribution.
palmdotax 2:f873deba2305 17 *
palmdotax 2:f873deba2305 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
palmdotax 2:f873deba2305 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
palmdotax 2:f873deba2305 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
palmdotax 2:f873deba2305 21 * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
palmdotax 2:f873deba2305 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
palmdotax 2:f873deba2305 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
palmdotax 2:f873deba2305 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
palmdotax 2:f873deba2305 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
palmdotax 2:f873deba2305 26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
palmdotax 2:f873deba2305 27 *
palmdotax 2:f873deba2305 28 */
palmdotax 2:f873deba2305 29
palmdotax 2:f873deba2305 30 #pragma once
palmdotax 2:f873deba2305 31 #include "mbed.h"
palmdotax 5:fe76f3dae81e 32 #include "inc/rptypes.h"
palmdotax 5:fe76f3dae81e 33 #include "inc/rplidar_cmd.h"
palmdotax 2:f873deba2305 34 #include "../BufferedSerial/BufferedSerial.h"
palmdotax 2:f873deba2305 35 struct RPLidarMeasurement
palmdotax 2:f873deba2305 36 {
palmdotax 2:f873deba2305 37 float distance;
palmdotax 2:f873deba2305 38 float angle;
palmdotax 2:f873deba2305 39 uint8_t quality;
palmdotax 2:f873deba2305 40 bool startBit;
palmdotax 2:f873deba2305 41 };
palmdotax 2:f873deba2305 42
palmdotax 2:f873deba2305 43 class RPLidar
palmdotax 2:f873deba2305 44 {
palmdotax 2:f873deba2305 45 public:
palmdotax 2:f873deba2305 46 enum {
palmdotax 2:f873deba2305 47 RPLIDAR_SERIAL_BAUDRATE = 115200,
palmdotax 2:f873deba2305 48 RPLIDAR_DEFAULT_TIMEOUT = 500,
palmdotax 2:f873deba2305 49 };
palmdotax 2:f873deba2305 50
palmdotax 2:f873deba2305 51 RPLidar();
palmdotax 2:f873deba2305 52 ~RPLidar();
palmdotax 2:f873deba2305 53
palmdotax 2:f873deba2305 54 // open the given serial interface and try to connect to the RPLIDAR
palmdotax 2:f873deba2305 55 //bool begin(BufferedSerial &serialobj);
palmdotax 5:fe76f3dae81e 56 void begin(BufferedSerial &serialobj);
palmdotax 2:f873deba2305 57 // close the currently opened serial interface
palmdotax 2:f873deba2305 58 void end();
palmdotax 2:f873deba2305 59
palmdotax 2:f873deba2305 60 // check whether the serial interface is opened
palmdotax 2:f873deba2305 61 // bool isOpen();
palmdotax 2:f873deba2305 62
palmdotax 2:f873deba2305 63 // ask the RPLIDAR for its health info
palmdotax 2:f873deba2305 64 u_result getHealth(rplidar_response_device_health_t & healthinfo, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 2:f873deba2305 65
palmdotax 2:f873deba2305 66 // ask the RPLIDAR for its device info like the serial number
palmdotax 2:f873deba2305 67 u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 2:f873deba2305 68
palmdotax 2:f873deba2305 69 // stop the measurement operation
palmdotax 2:f873deba2305 70 u_result stop();
palmdotax 2:f873deba2305 71
palmdotax 2:f873deba2305 72 // start the measurement operation
palmdotax 2:f873deba2305 73 u_result startScan(bool force = true, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT*2);
palmdotax 2:f873deba2305 74
palmdotax 2:f873deba2305 75 // wait for one sample point to arrive
palmdotax 2:f873deba2305 76 u_result waitPoint(_u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 5:fe76f3dae81e 77 u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
palmdotax 2:f873deba2305 78 // retrieve currently received sample point
palmdotax 4:de5a65c17664 79 int Data[360];
palmdotax 4:de5a65c17664 80 int ang,dis;
palmdotax 4:de5a65c17664 81 int angMin,angMax;
palmdotax 4:de5a65c17664 82 void setAngle(int min,int max);
palmdotax 5:fe76f3dae81e 83 void get_lidar();
palmdotax 2:f873deba2305 84 const RPLidarMeasurement & getCurrentPoint()
palmdotax 2:f873deba2305 85 {
palmdotax 2:f873deba2305 86 return _currentMeasurement;
palmdotax 2:f873deba2305 87 }
palmdotax 2:f873deba2305 88
palmdotax 2:f873deba2305 89 protected:
palmdotax 2:f873deba2305 90 // u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
palmdotax 2:f873deba2305 91 u_result _waitResponseHeader(rplidar_ans_header_t * header, _u32 timeout);
palmdotax 2:f873deba2305 92
palmdotax 2:f873deba2305 93 protected:
palmdotax 5:fe76f3dae81e 94 BufferedSerial * _bined_serialdev;
palmdotax 2:f873deba2305 95 RPLidarMeasurement _currentMeasurement;
palmdotax 2:f873deba2305 96 };