-
Notifications
You must be signed in to change notification settings - Fork 132
Driver changes for porting PX4 to BeagleBone Blue #228
Conversation
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 PR! Generally looks good.
The _mutex_shared_i2c_2_bus
mutex is not required as all drivers within DriverFramework run on a single thread.
drivers/bmp280/BMP280.cpp
Outdated
#if defined(__DF_BBBLUE) | ||
// on BBBLUE, MPU9250 and BMP280 are on the same I2C bus | ||
pthread_mutex_lock(&_mutex_shared_i2c_2_bus); | ||
int ret = _start(); |
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.
Wrong indentation (same for other places)
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.
Changed
drivers/bmp280/BMP280.cpp
Outdated
{ | ||
#if defined(__DF_BBBLUE) | ||
pthread_mutex_lock(&_mutex_shared_i2c_2_bus); | ||
int busInUse = rc_i2c_get_lock(2); |
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.
m_bus_num
instead of 2?
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.
Yes, changed.
drivers/bmp280/BMP280.cpp
Outdated
#define BMP280_FILTER_CUTOFF_FREQ 2.0f | ||
// 2rad/s, about 0.3hz | ||
#define BMP280_FILTER_CHECK_HZ 25 | ||
#define BMP280_FILTER_DT 1.0f/BMP280_FILTER_CHECK_HZ |
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 define needs brackets: (1.0f/BMP280_FILTER_CHECK_HZ)
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.
Changed
drivers/bmp280/BMP280.hpp
Outdated
@@ -79,6 +88,10 @@ class BMP280 : public BaroSensor | |||
{ | |||
m_id.dev_id_s.devtype = DRV_DF_DEVTYPE_BMP280; | |||
m_id.dev_id_s.address = BMP280_SLAVE_ADDRESS; | |||
|
|||
#ifdef __DF_BBBLUE |
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 should not be indented.
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.
Changed
drivers/bmp280/BMP280.cpp
Outdated
@@ -53,8 +53,37 @@ | |||
#define BMP280_BITS_CONFIG_FILTER_OFF 0b00000000 | |||
#define BMP280_BITS_CONFIG_SPI_OFF 0b00000000 | |||
|
|||
#if defined(__DF_BBBLUE) | |||
#define BMP280_FILTER_ORDER 2 | |||
#define BMP280_FILTER_CUTOFF_FREQ 2.0f |
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.
Is the filter required? The cutoff freq is really low.
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 filter is not required. I got it from a librobotcontrol sample code. The cutoff frequency is increased.
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.
I suggest removing it altogether then, since we generally don't filter the baro in the drivers.
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.
Removed the filter
|
||
void BMP280::_measureDataRC() | ||
{ | ||
#if defined(__DF_BBBLUE_USE_RC_BMP280_IMP) |
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.
All these ifdef's almost justify a separate driver.
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 RC variant of the driver was developed before I got barometer and IMU drive work with PX4 I2C driver work on BBBlue. Later it's kept since it worked and has an additional filter.
@@ -248,9 +300,56 @@ int MPU9250::mpu9250_deinit() | |||
} | |||
|
|||
int MPU9250::start() | |||
{ | |||
#if defined(__DF_BBBLUE) | |||
// on BBBLUE, MPU9250 and BMP280 are on the same I2C bus |
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.
Sounds like a bad design choice. Do you get good flight performance on that board?
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 seems to be a common concern regarding using BBBlue as a flight controller. I saw similar comments regarding ArduPilot port on BBBlue. I wish that in future version of BBBlue, IMU could be on a faster bus. Previous PX4 code discarded 3/4 of IMU samples. After I saw some IMU TIMEOUT messages, I changed code to not to discard any IMU sample. Before I submitted the initial pull request with librobotcontrol as submodule, someone made the same change to not to discard any IMU sample ( so such change is not shown in this pull request). Since previously with 1/4 of current IMU sample frequency, it's on the boundary of meeting minimum sample frequency, now with 4 times of previous sample frequency, current IMU sample frequency seems to be adequate. However, due to my limited experience with drones and PX4, I don't know what kind of performance is qualified as good flight performance. I hope after this pull request is merged in, other more experienced PX4 users can better evaluate the flight performance on this board.
drivers/mpu9250/MPU9250.cpp
Outdated
#if defined(__IMU_USE_I2C) | ||
rc_init(); | ||
|
||
int result = I2CDevObj::start(); |
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.
int result
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.
changed
framework/include/I2CDevObj.hpp
Outdated
@@ -74,6 +77,8 @@ class I2CDevObj : public DevObj | |||
|
|||
int m_fd{ -1}; | |||
unsigned _retries{0}; | |||
int m_bus_num{0}; | |||
//uint32_t m_slave_address{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.
Commented code should be removed
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.
removed.
framework/src/CMakeLists.txt
Outdated
@@ -43,6 +43,10 @@ if("${DF_TARGET}" STREQUAL "nuttx") | |||
) | |||
add_dependencies(df_driver_framework prebuild_targets) | |||
else() | |||
include_directories(../../../Robotics_Cape_Installer/library/include) |
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.
Is this needed? And if so, can we move it to Toolchain-bbblue.cmake?
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.
No. I missed it last time. Removed.
|
||
#if defined(__DF_BBBLUE) | ||
#define BARO_DEVICE_PATH "/dev/i2c-2" | ||
extern pthread_mutex_t _mutex_shared_i2c_2_bus; |
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 mutex? Everything runs on a single thread.
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.
After removing the mutex, the following error occurred, so I added the mutex back. BTW, the low pass filter with bmp280 was removed.
px4 starting.
INFO [dataman] Unknown restart, data manager file 'rootfs/fs/microsd/dataman' size is 11405132 bytes
INFO [bbblue_adc] Initializing Robotics Cape library ...
344199 BMP280 sensor configuration succeeded
INFO [df_bmp280_wrapper] BMP280 started
447748 MPU9250 sensor WHOAMI wrong: 0x0, should be: 0x71
ERROR [df_mpu9250_wrapper] MPU9250 start fail: -1
ERROR [df_mpu9250_wrapper] DfMpu9250Wrapper start failed
Command 'df_mpu9250_wrapper' failed, returned -1
INFO [bbblue_adc] BBBlueADC started
Also note that "bbblue_adc start" is placed after bmp280 & mpu9250 wrapper in px4.config, the log message of bbblue_adc came first.
BTW, in pull request PX4/PX4-Autopilot#9635, Lorenz Meier mentioned moving from DriverFramework to CDev soon, so these 2 drivers will be replaced eventually.
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.
Might be that some startup code is called from the wrong thread then. Ok, let's keep it in under the assumption that we want to move away from DriverFramework.
Not sure why the Travis CI build failed. The build was 100% completed, and all tests passed successfully. |
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.
CI fails with:
Formatted ./drivers/bmp280/BMP280.cpp
./drivers/bmp280/BMP280.cpp bad formatting
Formatted ./drivers/mpu9250/MPU9250.cpp
./drivers/mpu9250/MPU9250.cpp bad formatting
Formatted ./framework/src/I2CDevObj.cpp
./framework/src/I2CDevObj.cpp bad formatting
Please run "make fix-style"
Otherwise this is good to go.
I missed the build error message. All checks passed this time. Thanks! |
Thanks for the update. Can you rebase to master, it shows some conflicts? |
c30a18d
to
6d5c0c6
Compare
Did rebase, etc. Current files should be the same as those in last commit except some commit history were somehow skipped during those git rebase master / git rebase --continue / git rebase --skip operations. I copied the saved latest files over in the last few runs of rebase. Please try again. |
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.
Let's merge it then
Robotics Cape library is included as a submodule in pull request #9635 in PX4/Firmware repository.
On BeagleBone Blue board, BMP280 and MPU9250 are on the same I2C bus.