PX4 Firmware
PX4 Autopilot Software http://px4.io
LidarLite.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 
35 /**
36  * @file LidarLite.h
37  * @author Johan Jansen <jnsn.johan@gmail.com>
38  *
39  * Generic interface driver for the PulsedLight Lidar-Lite range finders.
40  */
41 #pragma once
42 
43 #include <drivers/device/device.h>
45 #include <perf/perf_counter.h>
46 
47 using namespace time_literals;
48 
49 // Device limits
50 static constexpr float LL40LS_MIN_DISTANCE{0.05f};
51 static constexpr float LL40LS_MAX_DISTANCE{25.00f};
52 static constexpr float LL40LS_MAX_DISTANCE_V2{35.00f};
53 
54 // Normal conversion wait time.
55 static constexpr uint32_t LL40LS_CONVERSION_INTERVAL{50_ms};
56 
57 // Maximum time to wait for a conversion to complete.
58 static constexpr uint32_t LL40LS_CONVERSION_TIMEOUT{100_ms};
59 
60 class LidarLite
61 {
62 public:
63  LidarLite(const uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
64  virtual ~LidarLite();
65 
66  virtual int init() = 0;
67  virtual void start() = 0;
68  virtual void stop() = 0;
69 
70  /**
71  * @brief Diagnostics - print some basic information about the driver.
72  */
73  void print_info();
74 
75  /**
76  * @brief print registers to console.
77  */
78  virtual void print_registers() {};
79 
80 protected:
81 
82  uint32_t get_measure_interval() const { return _measure_interval; };
83 
84  virtual int collect() = 0;
85 
86  virtual int measure() = 0;
87 
88  virtual int reset_sensor() { return PX4_ERROR; };
89 
90  PX4Rangefinder _px4_rangefinder;
91 
92  perf_counter_t _comms_errors{perf_alloc(PC_COUNT, "ll40ls: comms errors")};
93  perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, "ll40ls: read")};
94  perf_counter_t _sensor_resets{perf_alloc(PC_COUNT, "ll40ls: resets")};
95  perf_counter_t _sensor_zero_resets{perf_alloc(PC_COUNT, "ll40ls: zero resets")};
96 
97 private:
98 
99  uint32_t _measure_interval{LL40LS_CONVERSION_INTERVAL};
100 };
static constexpr float LL40LS_MAX_DISTANCE
Definition: LidarLite.h:51
static constexpr uint32_t LL40LS_CONVERSION_INTERVAL
Definition: LidarLite.h:55
measure the time elapsed performing an event
Definition: perf_counter.h:56
static void stop()
Definition: dataman.cpp:1491
count the number of times an event occurs
Definition: perf_counter.h:55
virtual int reset_sensor()
Definition: LidarLite.h:88
static constexpr float LL40LS_MAX_DISTANCE_V2
Definition: LidarLite.h:52
Header common to all counters.
void init()
Activates/configures the hardware registers.
uint32_t get_measure_interval() const
Definition: LidarLite.h:82
#define perf_alloc(a, b)
Definition: px4io.h:59
virtual void print_registers()
print registers to console.
Definition: LidarLite.h:78
static int start()
Definition: dataman.cpp:1452
static constexpr float LL40LS_MIN_DISTANCE
Definition: LidarLite.h:50
static constexpr uint32_t LL40LS_CONVERSION_TIMEOUT
Definition: LidarLite.h:58
Performance measuring tools.