mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 15:53:33 +08:00
srf02: update for new orientation convention
add possibility to specify orientation and adapt to new defaults and use px4_getopt
This commit is contained in:
committed by
ChristophTobler
parent
d5ddc2b489
commit
018aa8e535
+35
-12
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
|
#include <px4_getopt.h>
|
||||||
|
|
||||||
#include <drivers/device/i2c.h>
|
#include <drivers/device/i2c.h>
|
||||||
|
|
||||||
@@ -100,7 +101,8 @@
|
|||||||
class SRF02 : public device::I2C
|
class SRF02 : public device::I2C
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SRF02(int bus = SRF02_BUS, int address = SRF02_BASEADDR);
|
SRF02(uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING, int bus = SRF02_BUS,
|
||||||
|
int address = SRF02_BASEADDR);
|
||||||
virtual ~SRF02();
|
virtual ~SRF02();
|
||||||
|
|
||||||
virtual int init();
|
virtual int init();
|
||||||
@@ -117,6 +119,7 @@ protected:
|
|||||||
virtual int probe();
|
virtual int probe();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint8_t _rotation;
|
||||||
float _min_distance;
|
float _min_distance;
|
||||||
float _max_distance;
|
float _max_distance;
|
||||||
work_s _work;
|
work_s _work;
|
||||||
@@ -195,8 +198,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
extern "C" __EXPORT int srf02_main(int argc, char *argv[]);
|
extern "C" __EXPORT int srf02_main(int argc, char *argv[]);
|
||||||
|
|
||||||
SRF02::SRF02(int bus, int address) :
|
SRF02::SRF02(uint8_t rotation, int bus, int address) :
|
||||||
I2C("MB12xx", SRF02_DEVICE_PATH, bus, address, 100000),
|
I2C("MB12xx", SRF02_DEVICE_PATH, bus, address, 100000),
|
||||||
|
_rotation(rotation),
|
||||||
_min_distance(SRF02_MIN_DISTANCE),
|
_min_distance(SRF02_MIN_DISTANCE),
|
||||||
_max_distance(SRF02_MAX_DISTANCE),
|
_max_distance(SRF02_MAX_DISTANCE),
|
||||||
_reports(nullptr),
|
_reports(nullptr),
|
||||||
@@ -572,7 +576,7 @@ SRF02::collect()
|
|||||||
struct distance_sensor_s report;
|
struct distance_sensor_s report;
|
||||||
report.timestamp = hrt_absolute_time();
|
report.timestamp = hrt_absolute_time();
|
||||||
report.type = distance_sensor_s::MAV_DISTANCE_SENSOR_ULTRASOUND;
|
report.type = distance_sensor_s::MAV_DISTANCE_SENSOR_ULTRASOUND;
|
||||||
report.orientation = 8;
|
report.orientation = _rotation;
|
||||||
report.current_distance = distance_m;
|
report.current_distance = distance_m;
|
||||||
report.min_distance = get_minimum_distance();
|
report.min_distance = get_minimum_distance();
|
||||||
report.max_distance = get_maximum_distance();
|
report.max_distance = get_maximum_distance();
|
||||||
@@ -722,7 +726,7 @@ namespace srf02
|
|||||||
|
|
||||||
SRF02 *g_dev;
|
SRF02 *g_dev;
|
||||||
|
|
||||||
void start();
|
void start(uint8_t rotation);
|
||||||
void stop();
|
void stop();
|
||||||
void test();
|
void test();
|
||||||
void reset();
|
void reset();
|
||||||
@@ -732,7 +736,7 @@ void info();
|
|||||||
* Start the driver.
|
* Start the driver.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
start()
|
start(uint8_t rotation)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@@ -741,7 +745,7 @@ start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create the driver */
|
/* create the driver */
|
||||||
g_dev = new SRF02(SRF02_BUS);
|
g_dev = new SRF02(rotation, SRF02_BUS);
|
||||||
|
|
||||||
if (g_dev == nullptr) {
|
if (g_dev == nullptr) {
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -903,38 +907,57 @@ info()
|
|||||||
int
|
int
|
||||||
srf02_main(int argc, char *argv[])
|
srf02_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// check for optional arguments
|
||||||
|
int ch;
|
||||||
|
int myoptind = 1;
|
||||||
|
const char *myoptarg = NULL;
|
||||||
|
uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||||
|
|
||||||
|
|
||||||
|
while ((ch = px4_getopt(argc, argv, "R:", &myoptind, &myoptarg)) != EOF) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'R':
|
||||||
|
rotation = (uint8_t)atoi(myoptarg);
|
||||||
|
PX4_INFO("Setting distance sensor orientation to %d", (int)rotation);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
PX4_WARN("Unknown option!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "start")) {
|
if (!strcmp(argv[myoptind], "start")) {
|
||||||
srf02::start();
|
srf02::start(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop the driver
|
* Stop the driver
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "stop")) {
|
if (!strcmp(argv[myoptind], "stop")) {
|
||||||
srf02::stop();
|
srf02::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test the driver/device.
|
* Test the driver/device.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "test")) {
|
if (!strcmp(argv[myoptind], "test")) {
|
||||||
srf02::test();
|
srf02::test();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset the driver.
|
* Reset the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "reset")) {
|
if (!strcmp(argv[myoptind], "reset")) {
|
||||||
srf02::reset();
|
srf02::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print driver information.
|
* Print driver information.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status")) {
|
if (!strcmp(argv[myoptind], "info") || !strcmp(argv[myoptind], "status")) {
|
||||||
srf02::info();
|
srf02::info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user