Skip to content
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

Added autodetect of baro and compass on external bus #7803

Merged
merged 2 commits into from
Apr 11, 2018

Conversation

night-ghost
Copy link
Contributor

fixes this

@WickedShell
Copy link
Contributor

One thing to be worrisome to me is that if anyone is trying to build this for plane that the MS5525 differential sensor is indistinguishable from the MS5611 which could lead to airspeeds being treated as barometers (which does not work out well at all)

@night-ghost
Copy link
Contributor Author

That's why my HAL don't allows to create a 2nd device with the same address on same bus, so if MS5525 will be detected first there will not be a problem.

@WickedShell
Copy link
Contributor

We detect baro's first at the moment rather then airspeed sensors. This is somewhat a larger issue as the two sensors will always be easily conflated with each other. (It's why the airspeed library allows you to specify which of I2C address the sensor is on, but I don't think the baro allows you that sort of control).

@night-ghost
Copy link
Contributor Author

We detect baro's first at the moment rather then airspeed sensors

But who prevents to change order?

#endif
}

#if CONFIG_HAL_BOARD != HAL_BOARD_F4LIGHT // most boards requires external baro
Copy link
Member

Choose a reason for hiding this comment

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

I have no comment on removing the need for a baro, but the comment is wrong. The code below doesn't require an external baro nor any board that I know of requires it; it simply requires that at least one baro is connected.

Copy link
Contributor Author

@night-ghost night-ghost Mar 1, 2018

Choose a reason for hiding this comment

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

User should can to use board without any baro. Arming check will prevent him from flight anyway. So comment is about that most boards for F4light don't has builtin baro

Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice to support boards with no baro in limited flight modes (eg. ACRO mode in copter). It would probably be quite an intrusive change though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it and tried to do it, but it took too long

@@ -535,6 +535,21 @@ void AP_Baro::init(void)
std::move(hal.spi->get_device(HAL_BARO_LPS22H_NAME))));
#endif

#ifdef HAL_BARO_MS5611_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.

Why are all these lines below needed instead of each board simply defining HAL_BARO_DEFAULT? Unless I missed something, this code is repeated above, except it checks HAL_BARO_DEFAULT value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because most boards don't have a baro so user solders it itself, so we don't know what baro will be

@@ -546,12 +561,23 @@ void AP_Baro::init(void)
#else
ADD_BACKEND(AP_Baro_MS56XX::probe(*this,
std::move(hal.i2c_mgr->get_device(_ext_bus, HAL_BARO_MS5611_I2C_ADDR))));

#if CONFIG_HAL_BOARD == HAL_BOARD_F4LIGHT // we don't know which baro user will solder
Copy link
Member

Choose a reason for hiding this comment

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

Maybe not needed for now, but we should add an external driver enable mask parameter here; the issue is that people might not want to enable the MS56XX driver as it conflicts with other device types (as @WickedShell said). Also these baros below might be used in other boards as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't affect other boards, I need to fix user's issue

@@ -834,6 +834,10 @@ void Compass::_detect_backends(void)
ADD_BACKEND(DRIVER_HMC5883, AP_Compass_HMC5843::probe(*this, hal.i2c_mgr->get_device(HAL_COMPASS_HMC5843_I2C_BUS, HAL_COMPASS_HMC5843_I2C_ADDR),
false, HAL_COMPASS_HMC5843_ROTATION),
AP_Compass_HMC5843::name, false);
#ifdef HAL_COMPASS_HMC5843_I2C_EXT_BUS
ADD_BACKEND(DRIVER_HMC5883, AP_Compass_HMC5843::probe(*this, hal.i2c_mgr->get_device(HAL_COMPASS_HMC5843_I2C_EXT_BUS, HAL_COMPASS_HMC5843_I2C_ADDR),true
Copy link
Member

Choose a reason for hiding this comment

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

This line seems to be missing some code at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed

@@ -877,6 +881,41 @@ void Compass::_detect_backends(void)
#error Unrecognised HAL_COMPASS_TYPE setting
#endif


#ifdef BOARD_I2C_BUS_EXT
Copy link
Member

Choose a reason for hiding this comment

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

I get the reason, but two points:

  • the external compasses should probably be detected before the internal compass
  • we should this correctly, read HAL - i2c detect mask #6748 and HAL: define method to get I2C buses to probe #6265 (there are probably other comments elsewhere); with that implemented, there would be no reason to not probe all drivers for external buses for all boards, which would greatly reduce the code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should probably be detected before the internal compass

but why? They are completely independent

read #6748 and #6265

those PRs are hangs for half of year, while my users lost the ability to update right now, so I want to restore full functionality

Copy link
Contributor

Choose a reason for hiding this comment

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

but why? They are completely independent

not quite, the EKF uses the first one in preference, and external compass is usually preferred (otherwise why did the user bother to attach it?)

Copy link
Contributor Author

@night-ghost night-ghost Mar 1, 2018

Choose a reason for hiding this comment

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

why did the user bother to attach it

because most boards don't contains internal one. With per-motor compensation builtin compass gives very good results.

IIRC user can select the main compass in MP?

@night-ghost
Copy link
Contributor Author

night-ghost commented Mar 1, 2018

should probably be detected before the internal compass

but why? They are completely independent

read #6748 and #6265

those PRs are hangs for half of year, while my users lost the ability to update right now, so I want to restore full functionality

@tridge
Copy link
Contributor

tridge commented Mar 1, 2018

That's why my HAL don't allows to create a 2nd device with the same address on same bus, so if MS5525 will be detected first there will not be a problem.

unfortunately we need to have two device handles for one device in some cases. For example, the lsm303d sensor is both a mag and an accel on the same bus/address, separated by register range. The way our driver structure works we attach to the device twice. It's safe as we use thread per bus, plus of course the semaphore.
Perhaps we should disallow attaching twice with the same bus/address except if you make some API call to allow it?

@night-ghost
Copy link
Contributor Author

night-ghost commented Mar 1, 2018

Perhaps we should disallow attaching twice with the same bus/address

We can create one I2c device and reuse in two drivers, so as for compass via MPU just to get device for compass from IMU driver.

UPD. LSM303D is on a SPI bus, not on I2C

@tridge
Copy link
Contributor

tridge commented Mar 1, 2018

UPD. LSM303D is on a SPI bus, not on I2C

it can be on either - just that nobody has been silly enough to put it on I2C yet
The problem with doing this as a general rule without an override is it will bite someone badly in the future. There are a lot of crazy sensors out there.

@night-ghost
Copy link
Contributor Author

Autodetect is very useful feature so I think that wil be better to alter API

@night-ghost
Copy link
Contributor Author

There are a lot of crazy sensors out there.

OK. I do HAL for normal sensors and don't want to know about crazy ones. So let my HAL will have autodetect, pleeeeeeeeeeeeeeeeeeeeease!

@night-ghost night-ghost closed this Mar 3, 2018
@night-ghost night-ghost reopened this Mar 4, 2018
@hiro2233
Copy link
Contributor

hiro2233 commented Mar 4, 2018

@night-ghost
take_it

@night-ghost
Copy link
Contributor Author

Sorry I don't understand you

@night-ghost
Copy link
Contributor Author

What issues still present in this PR?

tridge
tridge previously requested changes Mar 6, 2018
Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

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

The remaining issue with this PR is that it may break things for boards that don't use HAL_F4Light.
In particular, the addition of the probe for the MS5611, the BMP280 and the BMP085 without a check for HAL type could break some HAL_PX4 boards. I suspect it won't, but for this sort of change we'd need to do testing on quite a wide range of boards. We support a wide combination of sensors on the various px4-v3 boards, and we've carefully tested that it comes out right. If you put that part inside a check for HAL_F4Light then it would be fine.
The changes to AP_Compass look safe to me, and can be applied as-is.
I also think the change to not give sensor_config_error() when a baro isn't found is not a good idea. If we could support flight without a baro then it would be OK, but right now we don't. The sensor_config_error() at least gives the user a clear error message as to what is wrong. Without that check the user will get a more confusing error in startup, and probably won't get a mavlink connection, so they won't have the option to look at their board parameters to fix it.

@tridge
Copy link
Contributor

tridge commented Mar 6, 2018

btw, I think our whole system of #ifdefs for compass, baro and INS drivers needs an overhaul. It really is quite messy and hard to maintain. We need to live with it for now, but I am thinking of trying a different approach as we start to support a wider range of boards

@night-ghost
Copy link
Contributor Author

night-ghost commented Mar 7, 2018

If we could support flight without a baro then it would be OK, but right now we don't. The sensor_config_error() at least gives the user a clear error message as to what is wrong. Without that check the user will get a more confusing error in startup

No, this was checked many times! User got "baro not healthy" with working MAVlink with refuse to arm. Just try it yourself.
BTW, in the near past absense of baro was causing a panic()

our whole system of #ifdefs for compass, baro and INS drivers needs an overhaul

Sure. Now all things checked by board's name while the best way to check by feature, defined in board's config.

this PR is that it may break things for boards that don't use HAL_F4Light

changed baro driver to autotest only if BOARD_I2C_BUS_EXT defined (which no one existing HAL does except HAL_F4Light)

@sh83
Copy link
Contributor

sh83 commented Apr 3, 2018

Inav/betaflight had sensor autodetection on external bus a years ago. Current hardcoded sensor detection is simply awful. This pr (partially) fixes it.

@tridge
Copy link
Contributor

tridge commented Apr 11, 2018

I've rebased on master and changed the #ifdefs so its clearer this is just F4Light (while the define was specific to F4Light, that wasn't obvious to someone reading the code)
I've pushed to the PR branch and once this passes CI we can push to master

@night-ghost
Copy link
Contributor Author

This PR is not intended only fo F4Light, it will be useful for any HAL working on racer's boards without built-in baro. So may be it will be better to define something like BOARD_BARO_AUTODETECT in HAL and check it in baro driver?

@tridge tridge dismissed their stale review April 11, 2018 04:58

all fixed

@tridge
Copy link
Contributor

tridge commented Apr 11, 2018

@night-ghost I'm planning on taking a new approach for driver listing in the future for the ChibiOS build. but for now I'll take the cautious approach and do it just for F4Light so I'm sure it doesn't break anything

@tridge tridge merged commit 677f2be into ArduPilot:master Apr 11, 2018
@night-ghost
Copy link
Contributor Author

@tridge you removed checks like '#ifdef HAL_BARO_MS5611_I2C_BUS' so now all baros tries to detect regardless of board. It's wrong!

@night-ghost night-ghost deleted the fix4 branch April 11, 2018 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants