rplidar_driver_serial.h
Go to the documentation of this file.
00001 /*
00002  *  RPLIDAR SDK
00003  *
00004  *  Copyright (c) 2009 - 2014 RoboPeak Team
00005  *  http://www.robopeak.com
00006  *  Copyright (c) 2014 - 2016 Shanghai Slamtec Co., Ltd.
00007  *  http://www.slamtec.com
00008  *
00009  */
00010 /*
00011  * Redistribution and use in source and binary forms, with or without 
00012  * modification, are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice, 
00015  *    this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00018  *    this list of conditions and the following disclaimer in the documentation 
00019  *    and/or other materials provided with the distribution.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00023  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00024  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00028  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00029  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00030  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00031  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  */
00034 
00035 #pragma once
00036 
00037 namespace rp { namespace standalone{ namespace rplidar {
00038 
00039 class RPlidarDriverSerialImpl : public RPlidarDriver
00040 {
00041 public:
00042 
00043     enum {
00044         MAX_SCAN_NODES = 2048,
00045     };
00046 
00047     enum {
00048         LEGACY_SAMPLE_DURATION = 476,
00049     };
00050 
00051     RPlidarDriverSerialImpl();
00052     virtual ~RPlidarDriverSerialImpl();
00053 
00054 public:
00055     virtual u_result connect(const char * port_path, _u32 baudrate, _u32 flag);
00056     virtual void disconnect();
00057     virtual bool isConnected();
00058 
00059     virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT);
00060 
00061     virtual u_result getHealth(rplidar_response_device_health_t &, _u32 timeout = DEFAULT_TIMEOUT);
00062     virtual u_result getDeviceInfo(rplidar_response_device_info_t &, _u32 timeout = DEFAULT_TIMEOUT);
00063     virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT);
00064 
00065     virtual u_result setMotorPWM(_u16 pwm);
00066     virtual u_result startMotor();
00067     virtual u_result stopMotor();
00068     virtual u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT);
00069         virtual u_result getFrequency(bool inExpressMode, size_t count, float & frequency, bool & is4kmode);
00070 
00071     virtual u_result startScan(bool force = false, bool autoExpressMode = true);
00072     virtual u_result startScanNormal(bool force, _u32 timeout = DEFAULT_TIMEOUT);
00073     virtual u_result startScanExpress(bool fixedAngle, _u32 timeout = DEFAULT_TIMEOUT);
00074     virtual u_result checkExpressScanSupported(bool & support, _u32 timeout = DEFAULT_TIMEOUT);
00075 
00076     virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT);
00077     virtual u_result grabScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
00078     virtual u_result ascendScanData(rplidar_response_measurement_node_t * nodebuffer, size_t count);
00079 
00080 protected:
00081     u_result _waitNode(rplidar_response_measurement_node_t * node, _u32 timeout = DEFAULT_TIMEOUT);
00082     u_result _waitScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
00083         u_result _cacheScanData();
00084     void     _capsuleToNormal(const rplidar_response_capsule_measurement_nodes_t & capsule, rplidar_response_measurement_node_t *nodebuffer, size_t &nodeCount);
00085     u_result _waitCapsuledNode(rplidar_response_capsule_measurement_nodes_t & node, _u32 timeout = DEFAULT_TIMEOUT);
00086     u_result  _cacheCapsuledScanData();
00087     u_result _sendCommand(_u8 cmd, const void * payload = NULL, size_t payloadsize = 0);
00088     u_result _waitResponseHeader(rplidar_ans_header_t * header, _u32 timeout = DEFAULT_TIMEOUT);
00089     u_result _waitSampleRate(rplidar_response_sample_rate_t * res, _u32 timeout = DEFAULT_TIMEOUT);
00090 
00091     void     _disableDataGrabbing();
00092 
00093     bool     _isConnected;
00094     bool     _isScanning;
00095     bool     _isSupportingMotorCtrl;
00096 
00097         rp::hal::Locker         _lock;
00098     rp::hal::Event          _dataEvt;
00099     rp::hal::serial_rxtx  * _rxtx;
00100     rplidar_response_measurement_node_t      _cached_scan_node_buf[2048];
00101     size_t                                   _cached_scan_node_count;
00102 
00103     _u16                    _cached_sampleduration_std;
00104     _u16                    _cached_sampleduration_express;
00105 
00106     rplidar_response_capsule_measurement_nodes_t _cached_previous_capsuledata;
00107     bool                                         _is_previous_capsuledataRdy;
00108 
00109         rp::hal::Thread _cachethread;
00110 };
00111 
00112 
00113 }}}


rplidar_ros
Author(s):
autogenerated on Fri Dec 16 2016 03:59:16