drivers/distance_sensor replace std::vector usage with px4::Array

This commit is contained in:
Daniel Agar
2019-01-19 13:02:53 -05:00
committed by Lorenz Meier
parent edeb59a8c3
commit 7008558fac
6 changed files with 12 additions and 22 deletions

View File

@@ -31,16 +31,16 @@
# #
############################################################################ ############################################################################
add_subdirectory(cm8jl65)
#add_subdirectory(hc_sr04) # not currently supported #add_subdirectory(hc_sr04) # not currently supported
add_subdirectory(leddar_one)
add_subdirectory(ll40ls) add_subdirectory(ll40ls)
add_subdirectory(mb12xx) add_subdirectory(mb12xx)
add_subdirectory(pga460)
add_subdirectory(sf0x) add_subdirectory(sf0x)
add_subdirectory(sf1xx) add_subdirectory(sf1xx)
add_subdirectory(srf02) add_subdirectory(srf02)
add_subdirectory(teraranger) add_subdirectory(teraranger)
add_subdirectory(tfmini) add_subdirectory(tfmini)
add_subdirectory(ulanding) add_subdirectory(ulanding)
add_subdirectory(leddar_one)
add_subdirectory(vl53lxx) add_subdirectory(vl53lxx)
add_subdirectory(pga460)
add_subdirectory(cm8jl65)

View File

@@ -41,6 +41,7 @@
#include <px4_workqueue.h> #include <px4_workqueue.h>
#include <drivers/device/device.h> #include <drivers/device/device.h>
#include <px4_defines.h> #include <px4_defines.h>
#include <containers/Array.hpp>
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
@@ -54,7 +55,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <systemlib/err.h> #include <systemlib/err.h>
@@ -86,7 +86,7 @@
class HC_SR04 : public cdev::CDev class HC_SR04 : public cdev::CDev
{ {
public: public:
HC_SR04(unsigned sonars = 6); HC_SR04();
virtual ~HC_SR04(); virtual ~HC_SR04();
virtual int init(); virtual int init();
@@ -123,9 +123,9 @@ private:
int _cycling_rate; /* */ int _cycling_rate; /* */
uint8_t _index_counter; /* temporary sonar i2c address */ uint8_t _index_counter; /* temporary sonar i2c address */
std::vector<float> px4::Array<float, 6>
_latest_sonar_measurements; /* vector to store latest sonar measurements in before writing to report */ _latest_sonar_measurements; /* vector to store latest sonar measurements in before writing to report */
unsigned _sonars; unsigned _sonars{6};
struct GPIOConfig { struct GPIOConfig {
uint32_t trig_port; uint32_t trig_port;
uint32_t echo_port; uint32_t echo_port;
@@ -200,7 +200,7 @@ const HC_SR04::GPIOConfig HC_SR04::_gpio_tab[] = {
extern "C" __EXPORT int hc_sr04_main(int argc, char *argv[]); extern "C" __EXPORT int hc_sr04_main(int argc, char *argv[]);
static int sonar_isr(int irq, void *context); static int sonar_isr(int irq, void *context);
HC_SR04::HC_SR04(unsigned sonars) : HC_SR04::HC_SR04() :
CDev(SR04_DEVICE_PATH, 0), CDev(SR04_DEVICE_PATH, 0),
_min_distance(SR04_MIN_DISTANCE), _min_distance(SR04_MIN_DISTANCE),
_max_distance(SR04_MAX_DISTANCE), _max_distance(SR04_MAX_DISTANCE),

View File

@@ -42,6 +42,7 @@
#include <px4_config.h> #include <px4_config.h>
#include <px4_getopt.h> #include <px4_getopt.h>
#include <px4_workqueue.h> #include <px4_workqueue.h>
#include <containers/Array.hpp>
#include <drivers/device/i2c.h> #include <drivers/device/i2c.h>
@@ -56,7 +57,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
@@ -131,10 +131,7 @@ private:
uint8_t _cycle_counter; /* counter in cycle to change i2c adresses */ uint8_t _cycle_counter; /* counter in cycle to change i2c adresses */
int _cycling_rate; /* */ int _cycling_rate; /* */
uint8_t _index_counter; /* temporary sonar i2c address */ uint8_t _index_counter; /* temporary sonar i2c address */
std::vector<uint8_t> addr_ind; /* temp sonar i2c address vector */ px4::Array<uint8_t, MB12XX_MAX_RANGEFINDERS> addr_ind; /* temp sonar i2c address vector */
std::vector<float>
_latest_sonar_measurements; /* vector to store latest sonar measurements in before writing to report */
/** /**
* Test whether the device supported by the driver is present at a * Test whether the device supported by the driver is present at a
@@ -277,7 +274,6 @@ MB12XX::init()
if (ret2 == 0) { /* sonar is present -> store address_index in array */ if (ret2 == 0) { /* sonar is present -> store address_index in array */
addr_ind.push_back(_index_counter); addr_ind.push_back(_index_counter);
PX4_DEBUG("sonar added"); PX4_DEBUG("sonar added");
_latest_sonar_measurements.push_back(200);
} }
} }

View File

@@ -60,7 +60,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>

View File

@@ -41,6 +41,7 @@
#include <px4_defines.h> #include <px4_defines.h>
#include <px4_getopt.h> #include <px4_getopt.h>
#include <px4_workqueue.h> #include <px4_workqueue.h>
#include <containers/Array.hpp>
#include <drivers/device/i2c.h> #include <drivers/device/i2c.h>
@@ -55,7 +56,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
@@ -131,10 +131,7 @@ private:
uint8_t _cycle_counter; /* counter in cycle to change i2c adresses */ uint8_t _cycle_counter; /* counter in cycle to change i2c adresses */
int _cycling_rate; /* */ int _cycling_rate; /* */
uint8_t _index_counter; /* temporary sonar i2c address */ uint8_t _index_counter; /* temporary sonar i2c address */
std::vector<uint8_t> addr_ind; /* temp sonar i2c address vector */ px4::Array<uint8_t, MB12XX_MAX_RANGEFINDERS> addr_ind; /* temp sonar i2c address vector */
std::vector<float>
_latest_sonar_measurements; /* vector to store latest sonar measurements in before writing to report */
/** /**
* Test whether the device supported by the driver is present at a * Test whether the device supported by the driver is present at a
@@ -277,7 +274,6 @@ SRF02::init()
if (ret2 == 0) { /* sonar is present -> store address_index in array */ if (ret2 == 0) { /* sonar is present -> store address_index in array */
addr_ind.push_back(_index_counter); addr_ind.push_back(_index_counter);
PX4_DEBUG("sonar added"); PX4_DEBUG("sonar added");
_latest_sonar_measurements.push_back(200);
} }
} }

View File

@@ -55,7 +55,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <systemlib/err.h> #include <systemlib/err.h>
#include <drivers/device/ringbuffer.h> #include <drivers/device/ringbuffer.h>