Firmware
LidarLitePWM.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014, 2015 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 
44 #pragma once
45 
46 #include "LidarLite.h"
47 
48 #include <px4_workqueue.h>
49 
50 
52 #include <perf/perf_counter.h>
53 
54 #include <uORB/uORB.h>
55 #include <uORB/topics/pwm_input.h>
56 #include <uORB/topics/distance_sensor.h>
57 
58 
59 
60 class LidarLitePWM : public LidarLite, public cdev::CDev
61 {
62 public:
63  LidarLitePWM(const char *path, uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
64  virtual ~LidarLitePWM();
65 
66  int init() override;
67 
68  ssize_t read(device::file_t *filp, char *buffer, size_t buflen) override;
69  int ioctl(device::file_t *filp, int cmd, unsigned long arg) override;
70 
71  void start() override;
72 
73  void stop() override;
74 
75  void cycle();
76 
81  void print_info() override;
82 
87  void print_registers() override;
88 
95  static void cycle_trampoline(void *arg);
96 
97  const char *get_dev_name() override;
98 
99 protected:
100 
101  int measure() override;
102 
103  int collect() override;
104 
105  int reset_sensor() override;
106 
107  void task_main_trampoline(int argc, char *argv[]);
108 
109 private:
110  uint8_t _rotation;
111  work_s _work;
112  ringbuffer::RingBuffer *_reports;
113  int _class_instance;
114  int _orb_class_instance;
115  int _pwmSub;
116  struct pwm_input_s _pwm;
117  orb_advert_t _distance_sensor_topic;
118  struct distance_sensor_s _range;
119 
120  perf_counter_t _sample_perf;
121  perf_counter_t _read_errors;
122  perf_counter_t _sensor_zero_resets;
123 };
A flexible ringbuffer class.
Definition: LidarLite.h:57
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
void print_registers() override
print registers to console
Definition: LidarLitePWM.cpp:130
void print_info() override
Diagnostics - print some basic information about the driver.
Definition: LidarLitePWM.cpp:120
Header common to all counters.
Definition: perf_counter.cpp:65
Definition: LidarLitePWM.h:60
API for the uORB lightweight object broker.
Definition: cdev_platform.hpp:20
Abstract class for any character device.
Definition: CDev.hpp:58
Definition: video_device.h:50
ssize_t read(device::file_t *filp, char *buffer, size_t buflen) override
Perform a read from the device.
Definition: LidarLitePWM.cpp:204
static void cycle_trampoline(void *arg)
Static trampoline from the workq context; because we don&#39;t have a generic workq wrapper yet...
Definition: LidarLitePWM.cpp:146
Performance measuring tools.