PX4 Firmware
PX4 Autopilot Software http://px4.io
TFMINI.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017-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  * @file tfmini.cpp
36  * @author Lorenz Meier <lm@inf.ethz.ch>
37  * @author Greg Hulands
38  * @author Ayush Gaud <ayush.gaud@gmail.com>
39  * @author Christoph Tobler <christoph@px4.io>
40  * @author Mohammed Kabir <mhkabir@mit.edu>
41  *
42  * Driver for the Benewake TFmini laser rangefinder series
43  */
44 
45 #pragma once
46 
47 #include <termios.h>
48 
49 #include <drivers/drv_hrt.h>
50 #include <lib/perf/perf_counter.h>
51 #include <px4_platform_common/px4_config.h>
52 #include <px4_platform_common/module.h>
53 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
56 
57 #include "tfmini_parser.h"
58 
59 #define TFMINI_DEFAULT_PORT "/dev/ttyS3"
60 
61 using namespace time_literals;
62 
63 class TFMINI : public px4::ScheduledWorkItem
64 {
65 public:
66  TFMINI(const char *port, uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
67  virtual ~TFMINI();
68 
69  int init();
70 
71  void print_info();
72 
73 private:
74 
75  int collect();
76 
77  void Run() override;
78 
79  void start();
80  void stop();
81 
83 
85 
86  char _linebuf[10] {};
87  char _port[20] {};
88 
89  static constexpr int kCONVERSIONINTERVAL{9_ms};
90 
91  int _fd{-1};
92 
93  unsigned int _linebuf_index{0};
94 
95  hrt_abstime _last_read{0};
96 
97  perf_counter_t _comms_errors{perf_alloc(PC_COUNT, MODULE_NAME": com_err")};
98  perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": read")};
99 
100 };
measure the time elapsed performing an event
Definition: perf_counter.h:56
TFMINI_PARSE_STATE
Definition: tfmini_parser.h:59
static void stop()
Definition: dataman.cpp:1491
count the number of times an event occurs
Definition: perf_counter.h:55
High-resolution timer with callouts and timekeeping.
Header common to all counters.
void init()
Activates/configures the hardware registers.
#define perf_alloc(a, b)
Definition: px4io.h:59
PX4Rangefinder _px4_rangefinder
Definition: TFMINI.hpp:82
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
static int start()
Definition: dataman.cpp:1452
Performance measuring tools.