APM:Libraries
AP_RangeFinder_PX4_PWM.h
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 #pragma once
16 
17 #include "RangeFinder.h"
18 #include "RangeFinder_Backend.h"
19 
21 {
22 public:
23  // constructor
24  AP_RangeFinder_PX4_PWM(RangeFinder::RangeFinder_State &_state, AP_Int16 &powersave_range, float &_estimated_terrain_height);
25 
26  // destructor
28 
29  // static detection function
30  static bool detect();
31 
32  // update state
33  void update(void);
34 
35 protected:
36 
37  MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
38  return MAV_DISTANCE_SENSOR_UNKNOWN;
39  }
40 
41 private:
42  int _fd;
43  uint64_t _last_timestamp;
45  uint32_t _disable_time_ms;
48 
49  AP_Int16 &_powersave_range;
51 
52  // return true if we are beyond the power saving range
53  bool out_of_range(void) const {
54  return _powersave_range > 0 && estimated_terrain_height > _powersave_range;
55  }
56 
57 };
AP_RangeFinder_PX4_PWM(RangeFinder::RangeFinder_State &_state, AP_Int16 &powersave_range, float &_estimated_terrain_height)
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override