48 #include <px4_platform_common/getopt.h> 49 #include <px4_platform_common/module_params.h> 50 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 55 #define MAPPYDOT_MEASUREMENT_BUDGET 0x42 56 #define MAPPYDOT_READ_ERROR_CODE 0x45 57 #define MAPPYDOT_CHECK_INTERRUPT 0x49 58 #define MAPPYDOT_READ_ACCURACY 0x52 59 #define MAPPYDOT_PERFORM_SINGLE_RANGE 0x53 60 #define MAPPYDOT_SET_CONTINUOUS_RANGING_MODE 0x63 61 #define MAPPYDOT_RANGING_MEASUREMENT_MODE 0x6D 62 #define MAPPYDOT_READ_DISTANCE 0x72 63 #define MAPPYDOT_SET_SINGLE_RANGING_MODE 0x73 66 #define MAPPYDOT_FILTERING_ENABLE 0x46 67 #define MAPPYDOT_SIGNAL_LIMIT_CHECK_VALUE 0x47 68 #define MAPPYDOT_ENABLE_CROSSTALK_COMPENSATION 0x4B 69 #define MAPPYDOT_SIGMA_LIMIT_CHECK_VALUE 0x4C 70 #define MAPPYDOT_INTERSENSOR_CROSSTALK_MEASUREMENT_DELAY 0x51 71 #define MAPPYDOT_INTERSENSOR_CROSSTALK_REDUCTION_ENABLE 0x54 72 #define MAPPYDOT_AVERAGING_ENABLE 0x56 73 #define MAPPYDOT_INTERSENSOR_SYNC_ENABLE 0x59 74 #define MAPPYDOT_CALIBRATE_DISTANCE_OFFSET 0x61 75 #define MAPPYDOT_SET_LED_THRESHOLD_DISTANCE_IN_MM 0x65 76 #define MAPPYDOT_FILTERING_DISABLE 0x66 77 #define MAPPYDOT_SET_GPIO_MODE 0x67 78 #define MAPPYDOT_AVERAGING_SAMPLES 0x69 79 #define MAPPYDOT_DISABLE_CROSSTALK_COMPENSATION 0x6B 80 #define MAPPYDOT_SET_LED_MODE 0x6C 81 #define MAPPYDOT_SET_GPIO_THRESHOLD_DISTANCE_IN_MM 0x6F 82 #define MAPPYDOT_REGION_OF_INTEREST 0x70 83 #define MAPPYDOT_INTERSENSOR_CROSSTALK_TIMEOUT 0x71 84 #define MAPPYDOT_INTERSENSOR_CROSSTALK_REDUCTION_DISABLE 0x74 85 #define MAPPYDOT_CALIBRATE_SPAD 0x75 86 #define MAPPYDOT_AVERAGING_DISABLE 0x76 87 #define MAPPYDOT_CALIBRATE_CROSSTALK 0x78 88 #define MAPPYDOT_INTERSENSOR_SYNC_DISABLE 0x79 91 #define MAPPYDOT_FIRMWARE_VERSION 0x4E 92 #define MAPPYDOT_READ_CURRENT_SETTINGS 0x62 93 #define MAPPYDOT_DEVICE_NAME 0x64 94 #define MAPPYDOT_NAME_DEVICE 0x6E 95 #define MAPPYDOT_WRITE_CURRENT_SETTINGS_AS_START_UP_DEFAULT 0x77 96 #define MAPPYDOT_RESTORE_FACTORY_DEFAULTS 0x7A 99 #define MAPPYDOT_AMBIENT_RATE_RETURN 0x41 100 #define MAPPYDOT_VL53L1X_NOT_SHUTDOWN 0x48 101 #define MAPPYDOT_SIGNAL_RATE_RETURN 0x4A 102 #define MAPPYDOT_RESET_VL53L1X_RANGING 0x58 103 #define MAPPYDOT_VL53L1X_SHUTDOWN 0x68 104 #define MAPPYDOT_READ_NONFILTERED_VALUE 0x6A 107 #define MAPPYDOT_ENTER_FACTORY_MODE 0x23 //"#"//"!#!#!#" 108 #define MAPPYDOT_WIPE_ALL_SETTINGS 0x3C //"<"//"><><><" (Must be in factory mode) 111 #define MAPPYDOT_LONG_RANGE 0x6C 112 #define MAPPYDOT_MED_RANGE 0x6D 113 #define MAPPYDOT_SHORT_RANGE 0x73 116 #define MAPPYDOT_LED_OFF 0x66 117 #define MAPPYDOT_LED_MEASUREMENT_OUTPUT 0x6D 118 #define MAPPYDOT_LED_ON 0x6F 119 #define MAPPYDOT_LED_PWM_ENABLED 0x70 120 #define MAPPYDOT_LED_THRESHOLD_ENABLED 0x74 123 #define MAPPYDOT_GPIO_LOW 0x66 124 #define MAPPYDOT_GPIO_MEASUREMENT_INTERRUPT 0x6D 125 #define MAPPYDOT_GPIO_HIGH 0x6F 126 #define MAPPYDOT_GPIO_PWM_ENABLED 0x70 127 #define MAPPYDOT_GPIO_THRESHOLD_ENABLED 0x74 130 #define MAPPYDOT_REBOOT_TO_BOOTLOADER 0x01 133 #define MAPPYDOT_MIN_DISTANCE (0.2f) // meters 134 #define MAPPYDOT_MAX_DISTANCE (4.f) // meters 136 #define MAPPYDOT_BUS_CLOCK 400000 // 400kHz bus speed 137 #define MAPPYDOT_DEVICE_PATH "/dev/mappydot" 140 #define MAPPYDOT_BASE_ADDR 0x08 141 #define MAPPYDOT_BUS_DEFAULT PX4_I2C_BUS_EXPANSION 142 #define MAPPYDOT_MEASUREMENT_INTERVAL_USEC 50000 // 50ms measurement interval, 20Hz. 146 class MappyDot :
public device::I2C,
public ModuleParams,
public px4::ScheduledWorkItem
156 virtual int init()
override;
195 int get_sensor_rotation(
const size_t index);
200 size_t _sensor_count{0};
208 (ParamInt<px4::params::SENS_EN_MPDT>) _p_sensor_enabled,
209 (ParamInt<px4::params::SENS_MPDT0_ROT>) _p_sensor0_rot,
210 (ParamInt<px4::params::SENS_MPDT1_ROT>) _p_sensor1_rot,
211 (ParamInt<px4::params::SENS_MPDT2_ROT>) _p_sensor2_rot,
212 (ParamInt<px4::params::SENS_MPDT3_ROT>) _p_sensor3_rot,
213 (ParamInt<px4::params::SENS_MPDT4_ROT>) _p_sensor4_rot,
214 (ParamInt<px4::params::SENS_MPDT5_ROT>) _p_sensor5_rot,
215 (ParamInt<px4::params::SENS_MPDT6_ROT>) _p_sensor6_rot,
216 (ParamInt<px4::params::SENS_MPDT7_ROT>) _p_sensor7_rot,
217 (ParamInt<px4::params::SENS_MPDT8_ROT>) _p_sensor8_rot,
218 (ParamInt<px4::params::SENS_MPDT9_ROT>) _p_sensor9_rot,
219 (ParamInt<px4::params::SENS_MPDT10_ROT>) _p_sensor10_rot,
220 (ParamInt<px4::params::SENS_MPDT11_ROT>) _p_sensor11_rot
227 ModuleParams(nullptr),
228 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id()))
259 int ret_val = transfer(
nullptr, 0, &val[0], 2);
262 PX4_ERR(
"sensor %i read failed, address: 0x%02X", index,
_sensor_addresses[index]);
268 uint16_t distance_mm = uint16_t(val[0]) << 8 | val[1];
269 float distance_m =
static_cast<float>(distance_mm) / 1000.
f;
277 report.signal_quality = -1;
279 report.type = distance_sensor_s::MAV_DISTANCE_SENSOR_LASER;
295 case 0:
return _p_sensor0_rot.get();
297 case 1:
return _p_sensor1_rot.get();
299 case 2:
return _p_sensor2_rot.get();
301 case 3:
return _p_sensor3_rot.get();
303 case 4:
return _p_sensor4_rot.get();
305 case 5:
return _p_sensor5_rot.get();
307 case 6:
return _p_sensor6_rot.get();
309 case 7:
return _p_sensor7_rot.get();
311 case 8:
return _p_sensor8_rot.get();
313 case 9:
return _p_sensor9_rot.get();
315 case 10:
return _p_sensor10_rot.get();
317 case 11:
return _p_sensor11_rot.get();
319 default:
return PX4_ERROR;
326 if (_p_sensor_enabled.get() == 0) {
327 PX4_WARN(
"disabled");
344 if (
probe() != PX4_OK) {
357 uint8_t(budget_ms >> 8 & 0xFF),
358 uint8_t(budget_ms & 0xFF)
360 transfer(&budget_cmd[0], 3,
nullptr, 0);
367 transfer(&range_cmd[0], 2,
nullptr, 0);
371 uint16_t threshold_mm = 1000;
373 uint8_t(threshold_mm >> 8 & 0xFF),
374 uint8_t(threshold_mm & 0xFF)
376 transfer(&threshold_cmd[0], 3,
nullptr, 0);
379 PX4_INFO(
"sensor %i at address 0x%02X added", i, get_device_address());
395 int ret_val = transfer(&cmd, 1,
nullptr, 0);
412 PX4_INFO(
"collection error");
423 ModuleParams::updateParams();
460 if (g_dev !=
nullptr) {
461 PX4_ERR(
"already started");
483 if (g_dev !=
nullptr) {
484 PX4_ERR(
"already started");
491 if (g_dev ==
nullptr) {
497 if (g_dev->
init() != PX4_OK) {
506 PX4_INFO(
"driver started");
516 if (g_dev ==
nullptr) {
517 PX4_ERR(
"driver not running");
532 if (g_dev !=
nullptr) {
538 PX4_INFO(
"driver stopped");
548 PX4_INFO(
"Usage: mappydot <command> [options]");
549 PX4_INFO(
"options:");
550 PX4_INFO(
"\t-a --all");
552 PX4_INFO(
"command:");
553 PX4_INFO(
"\tstart|start_bus|status|stop");
565 const char *myoptarg =
nullptr;
571 bool start_all =
false;
573 while ((ch = px4_getopt(argc, argv,
"ab:", &myoptind, &myoptarg)) != EOF) {
580 i2c_bus = atoi(myoptarg);
584 PX4_WARN(
"Unknown option!");
589 if (myoptind >= argc) {
593 if (!strcmp(argv[myoptind],
"start")) {
603 if (!strcmp(argv[myoptind],
"status")) {
608 if (!strcmp(argv[myoptind],
"stop")) {
int probe()
Sends an i2c measure command to check for presence of a sensor.
void Run() override
Performs a poll cycle; collect from the previous measurement and start a new one. ...
int usage()
Print usage information about the driver.
measure the time elapsed performing an event
void usage(const char *reason)
Print the correct usage.
px4::Array< uint8_t, RANGE_FINDER_MAX_SENSORS > _sensor_addresses
#define MAPPYDOT_BASE_ADDR
#define MAPPYDOT_DEVICE_PATH
#define MAPPYDOT_MEASUREMENT_INTERVAL_USEC
count the number of times an event occurs
#define MAPPYDOT_BUS_CLOCK
#define MAPPYDOT_MEASUREMENT_BUDGET
#define MAPPYDOT_SET_LED_THRESHOLD_DISTANCE_IN_MM
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
void perf_count(perf_counter_t handle)
Count a performance event.
int status()
Print the driver status.
orb_advert_t _distance_sensor_topic
#define MAPPYDOT_MAX_DISTANCE
void perf_free(perf_counter_t handle)
Free a counter.
int start_bus(int i2c_bus)
Start the driver on a specific bus.
void init()
Activates/configures the hardware registers.
px4::Array< uint8_t, RANGE_FINDER_MAX_SENSORS > _sensor_rotations
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void print_info()
Prints basic diagnostic information about the driver.
#define MAPPYDOT_BUS_DEFAULT
void perf_end(perf_counter_t handle)
End a performance event.
void stop()
Stop the automatic measurement state machine.
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Local functions in support of the shell command.
int get_sensor_rotation(const size_t index)
Gets the current sensor rotation value.
static const int i2c_bus_options[]
int collect()
Collects the most recent sensor measurement data from the i2c bus.
#define MAPPYDOT_MIN_DISTANCE
__EXPORT int mappydot_main(int argc, char *argv[])
Driver 'main' command.
#define MAPPYDOT_LONG_RANGE
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
#define MAPPYDOT_RANGING_MEASUREMENT_MODE
int orb_unadvertise(orb_advert_t handle)
virtual int init() override
Initializes the sensors, advertises uORB topic, sets device addresses.
#define MAPPYDOT_PERFORM_SINGLE_RANGE
MappyDot(const int bus=MAPPYDOT_BUS_DEFAULT)
int stop()
Stop the driver.
#define NUM_I2C_BUS_OPTIONS
perf_counter_t _comms_errors
perf_counter_t _sample_perf
void start()
Initializes the automatic measurement state machine and starts the driver.
void perf_begin(perf_counter_t handle)
Begin a performance event.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data, int *instance, int priority)
Advertise as the publisher of a topic.
int start()
Attempt to start driver on all available I2C busses.
#define RANGE_FINDER_MAX_SENSORS
Performance measuring tools.
Base class for devices connected via I2C.