before test

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

Fork of clean_V1 by Betago

Committer:
palmdotax
Date:
Tue May 24 10:25:10 2016 +0000
Revision:
2:f873deba2305
Child:
4:de5a65c17664
v1.1;

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 #ifndef RPLIDAR_H
palmdotax 2:f873deba2305 30 #define RPLIDAR_H
palmdotax 2:f873deba2305 31
palmdotax 2:f873deba2305 32 #pragma once
palmdotax 2:f873deba2305 33 #include "mbed.h"
palmdotax 2:f873deba2305 34 #include "rptypes.h"
palmdotax 2:f873deba2305 35 #include "rplidar_cmd.h"
palmdotax 2:f873deba2305 36 #include "../BufferedSerial/BufferedSerial.h"
palmdotax 2:f873deba2305 37 struct RPLidarMeasurement
palmdotax 2:f873deba2305 38 {
palmdotax 2:f873deba2305 39 float distance;
palmdotax 2:f873deba2305 40 float angle;
palmdotax 2:f873deba2305 41 uint8_t quality;
palmdotax 2:f873deba2305 42 bool startBit;
palmdotax 2:f873deba2305 43 };
palmdotax 2:f873deba2305 44
palmdotax 2:f873deba2305 45 class RPLidar
palmdotax 2:f873deba2305 46 {
palmdotax 2:f873deba2305 47 public:
palmdotax 2:f873deba2305 48 enum {
palmdotax 2:f873deba2305 49 RPLIDAR_SERIAL_BAUDRATE = 115200,
palmdotax 2:f873deba2305 50 RPLIDAR_DEFAULT_TIMEOUT = 500,
palmdotax 2:f873deba2305 51 };
palmdotax 2:f873deba2305 52
palmdotax 2:f873deba2305 53 RPLidar();
palmdotax 2:f873deba2305 54 ~RPLidar();
palmdotax 2:f873deba2305 55
palmdotax 2:f873deba2305 56 // open the given serial interface and try to connect to the RPLIDAR
palmdotax 2:f873deba2305 57 //bool begin(BufferedSerial &serialobj);
palmdotax 2:f873deba2305 58 void begin();
palmdotax 2:f873deba2305 59 // close the currently opened serial interface
palmdotax 2:f873deba2305 60 void end();
palmdotax 2:f873deba2305 61
palmdotax 2:f873deba2305 62 // check whether the serial interface is opened
palmdotax 2:f873deba2305 63 // bool isOpen();
palmdotax 2:f873deba2305 64
palmdotax 2:f873deba2305 65 // ask the RPLIDAR for its health info
palmdotax 2:f873deba2305 66 u_result getHealth(rplidar_response_device_health_t & healthinfo, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 2:f873deba2305 67
palmdotax 2:f873deba2305 68 // ask the RPLIDAR for its device info like the serial number
palmdotax 2:f873deba2305 69 u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 2:f873deba2305 70
palmdotax 2:f873deba2305 71 // stop the measurement operation
palmdotax 2:f873deba2305 72 u_result stop();
palmdotax 2:f873deba2305 73
palmdotax 2:f873deba2305 74 // start the measurement operation
palmdotax 2:f873deba2305 75 u_result startScan(bool force = true, _u32 timeout = RPLIDAR_DEFAULT_TIMEOUT*2);
palmdotax 2:f873deba2305 76
palmdotax 2:f873deba2305 77 // wait for one sample point to arrive
palmdotax 2:f873deba2305 78 u_result waitPoint(_u32 timeout = RPLIDAR_DEFAULT_TIMEOUT);
palmdotax 2:f873deba2305 79 u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
palmdotax 2:f873deba2305 80 // retrieve currently received sample point
palmdotax 2:f873deba2305 81
palmdotax 2:f873deba2305 82 const RPLidarMeasurement & getCurrentPoint()
palmdotax 2:f873deba2305 83 {
palmdotax 2:f873deba2305 84 return _currentMeasurement;
palmdotax 2:f873deba2305 85 }
palmdotax 2:f873deba2305 86
palmdotax 2:f873deba2305 87 protected:
palmdotax 2:f873deba2305 88 // u_result _sendCommand(_u8 cmd, const void * payload, size_t payloadsize);
palmdotax 2:f873deba2305 89 u_result _waitResponseHeader(rplidar_ans_header_t * header, _u32 timeout);
palmdotax 2:f873deba2305 90
palmdotax 2:f873deba2305 91 protected:
palmdotax 2:f873deba2305 92
palmdotax 2:f873deba2305 93 // BufferedSerial * _bined_serialdev;
palmdotax 2:f873deba2305 94
palmdotax 2:f873deba2305 95 RPLidarMeasurement _currentMeasurement;
palmdotax 2:f873deba2305 96 };
palmdotax 2:f873deba2305 97 #endif