Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Driver changes for porting PX4 to BeagleBone Blue #228

Merged
merged 7 commits into from
Aug 2, 2018

Conversation

UAV-Pilot
Copy link
Contributor

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.

Copy link
Member

@bkueng bkueng left a 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.

#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();
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

{
#if defined(__DF_BBBLUE)
pthread_mutex_lock(&_mutex_shared_i2c_2_bus);
int busInUse = rc_i2c_get_lock(2);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed.

#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
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

@UAV-Pilot UAV-Pilot Jul 29, 2018

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
Copy link
Member

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?

Copy link
Contributor Author

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.

#if defined(__IMU_USE_I2C)
rc_init();

int result = I2CDevObj::start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@@ -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};
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@@ -43,6 +43,10 @@ if("${DF_TARGET}" STREQUAL "nuttx")
)
add_dependencies(df_driver_framework prebuild_targets)
else()
include_directories(../../../Robotics_Cape_Installer/library/include)
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

@UAV-Pilot UAV-Pilot Jul 31, 2018

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.

Copy link
Member

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.

@UAV-Pilot
Copy link
Contributor Author

Not sure why the Travis CI build failed. The build was 100% completed, and all tests passed successfully.

Copy link
Member

@bkueng bkueng left a 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.

@UAV-Pilot
Copy link
Contributor Author

I missed the build error message. All checks passed this time. Thanks!

@bkueng
Copy link
Member

bkueng commented Jul 31, 2018

Thanks for the update. Can you rebase to master, it shows some conflicts?

@UAV-Pilot
Copy link
Contributor Author

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.

Copy link
Member

@bkueng bkueng left a 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

@bkueng bkueng merged commit 3bdfdf3 into PX4:master Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants