-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crazyflie drivers #9462
Crazyflie drivers #9462
Conversation
…gyro data during simple rotation
…and device in pmw3901 driver)
… 200 Hz for this board
src/drivers/imu/mpu9250/mpu9250.cpp
Outdated
@@ -139,7 +139,11 @@ MPU9250::MPU9250(device::Device *interface, device::Device *mag_interface, const | |||
_gyro_range_scale(0.0f), | |||
_gyro_range_rad_s(0.0f), | |||
_dlpf_freq(MPU9250_DEFAULT_ONCHIP_FILTER_FREQ), | |||
#ifdef CONFIG_ARCH_BOARD_CRAZYFLIE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we find a way to do this without board specific defines in drivers? How about defaulting to 200 Hz for I2C?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dagar I can get it to run up to 330Hz on the crazyflie but at this frequency I get some weird behavior because the delay between two samples becomes quite variable. It seems to work well between 200 and 250Hz. Could changing this create issues on other architectures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the important difference SPI vs I2C rather than anything crazyflie specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I can fix this
src/drivers/pmw3901/CMakeLists.txt
Outdated
MODULE drivers__pmw3901 | ||
MAIN pmw3901 | ||
COMPILE_FLAGS | ||
-Wno-sign-compare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed?
src/drivers/pmw3901/CMakeLists.txt
Outdated
SRCS | ||
pmw3901.cpp | ||
DEPENDS | ||
platforms__common |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be deleted, although it's harmless if left.
src/drivers/pmw3901/pmw3901.cpp
Outdated
|
||
#include <conversion/rotation.h> | ||
|
||
#include <systemlib/perf_counter.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<systemlib/perf_counter.h> -> <perf/perf_counter.h>
FYI @barzanisar |
|
||
usleep(1000); | ||
|
||
// set performance optimization registers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanielePettenuzzo Any reference we can put here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really but I can look more
src/drivers/pmw3901/pmw3901.cpp
Outdated
/* For devices competing with NuttX SPI drivers on a bus (Crazyflie SD Card expansion board) */ | ||
SPI::set_lockmode(LOCK_THREADS); | ||
|
||
/* do I2C init (and probe) first */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment lies
src/drivers/pmw3901/pmw3901.cpp
Outdated
/* notify anyone waiting for data */ | ||
poll_notify(POLLIN); | ||
|
||
ret = OK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just initialize this to 'OK' at the top?
src/drivers/pmw3901/pmw3901.cpp
Outdated
_reports->flush(); | ||
|
||
/* schedule a cycle to start things */ | ||
work_queue(LPWORK, &_work, (worker_t)&PMW3901::cycle_trampoline, this, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use USEC2TICK(PMW3901_SAMPLE_RATE) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PMW3901_SAMPLE_RATE is 10ms.. I will create a define for 1ms and use the USEC2TICK
goto fail; | ||
} | ||
|
||
exit(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dagar If we see a chance of this driver ever running in on a linux platform should we then get rid of this NuttX specific stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I would suggest assuming that possibility nearly everywhere as we go and even bother including them in the posix builds (sitl https://github.com/PX4/Firmware/blob/master/cmake/configs/posix_sitl_default.cmake#L6, rpi, etc).
At a minimum it will cause the code to be checked by tools like coverity and clang-tidy.
All that's actually required to "port" most NuttX drivers to Linux/QuRT is to use the px4 headers instead of anything NuttX specific, and prevent it from directly exiting (exit, err).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed, the general structure looks good, but needs a second pass to cleanup smaller things.
src/drivers/boards/crazyflie/spi.c
Outdated
return -ENODEV; | ||
} | ||
|
||
//#ifdef CONFIG_MMCSD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented?
Same for message("[boot] FAILED to bind SPI port 1 to the MMCSD driver\n");
src/drivers/boards/crazyflie/spi.c
Outdated
/* SPI select is active low, so write !selected to select the device */ | ||
|
||
int sel = (int) devid; | ||
//ASSERT(PX4_SPI_BUS_ID(sel) == PX4_SPI_BUS_EXPANSION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove if not needed
src/drivers/boards/crazyflie/spi.c
Outdated
stm32_configgpio(GPIO_SPI1_MOSI_OFF); | ||
|
||
/* set the sensor rail off */ | ||
//stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove or uncomment if needed (same below)
@@ -0,0 +1,1223 @@ | |||
/**************************************************************************** | |||
* | |||
* Copyright (c) 2013-2017 PX4 Development Team. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires updating
#define DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD_REG 0x4E | ||
#define GLOBAL_CONFIG_REF_EN_START_SELECT_REG 0xB6 | ||
#define GLOBAL_CONFIG_SPAD_ENABLES_REF_0_REG 0xB0 | ||
#define SYSTEM_INTERRUPT_CONFIG_GPIO_REG 0x0A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tabs here are completely off, can you make sure these are aligned?
/* get a publish handle on the range finder topic */ | ||
struct distance_sensor_s ds_report; | ||
|
||
_reports->get(&ds_report); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are reading from _reports, but nothing has been added to the ringbuffer yet.
switch (ch) { | ||
case 'R': | ||
rotation = (uint8_t)atoi(myoptarg); | ||
PX4_INFO("Setting sensor orientation to %d", (int)rotation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit verbose: can you remove it?
src/drivers/pmw3901/pmw3901.cpp
Outdated
@@ -0,0 +1,944 @@ | |||
/**************************************************************************** | |||
* | |||
* Copyright (c) 2013-2017 PX4 Development Team. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires updating
src/drivers/pmw3901/pmw3901.cpp
Outdated
delete _reports; | ||
} | ||
|
||
// if (_class_instance != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code: can you remove it if not needed?
src/drivers/pmw3901/pmw3901.cpp
Outdated
switch (ch) { | ||
case 'R': | ||
rotation = (uint8_t)atoi(myoptarg); | ||
PX4_INFO("Setting sensor orientation to %d", (int)rotation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit too verbose
* make the integration autoreset faster so that we integrate just one | ||
* sample since the sampling rate is already low. | ||
*/ | ||
if (is_i2c()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I'd use something like _accel_int.set_autoreset_interval(1000000 / 1000);
, so that it does not depend on the macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. I noticed a few more things that require to be fixed.
MODULE drivers__vl53lxx | ||
MAIN vl53lxx | ||
COMPILE_FLAGS | ||
-Wno-sign-compare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this?
#define VL53LXX_RA_IDENTIFICATION_MODEL_ID 0xC0 | ||
#define VL53LXX_IDENTIFICATION_MODEL_ID 0xEEAA | ||
|
||
#define VL53LXX_MS 1000 /* 1ms */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in us, so should be named VL53LXX_US
return ret; | ||
} | ||
|
||
ret = OK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed
work_queue(LPWORK, &_work, (worker_t)&VL53LXX::cycle_trampoline, this, USEC2TICK(VL53LXX_MS)); | ||
|
||
/* notify about state change */ | ||
struct subsystem_info_s info = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info.timestamp
is not set
info.ok = true; | ||
info.subsystem_type = subsystem_info_s::SUBSYSTEM_TYPE_RANGEFINDER; | ||
|
||
static orb_advert_t pub = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a class member instead of static
src/drivers/pmw3901/pmw3901.cpp
Outdated
info.ok = true; | ||
info.subsystem_type = subsystem_info_s::SUBSYSTEM_TYPE_OPTICALFLOW; | ||
|
||
static orb_advert_t pub = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid static
} | ||
|
||
/* read from the sensor */ | ||
ret = transfer(nullptr, 0, &val[0], length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can have a buffer overflow here if readRegisterMulti is called with length > 6
. Can you directly use value
instead of val
?
|
||
cmd[0] = reg_address; | ||
|
||
memcpy(&cmd[1], &value[0], length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a length check, or an API documentation for writeRegisterMulti
about the maximum length (length
must not be more than 5).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go
This PR enables Crazyflie's optical flow deck by adding the drivers for the optical flow module (pmw3901) and the range sensor (vl53lxx). Moreover adds support for logging on sd card and increases the imu sampling rate.