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
AP_LocationDB: add implementation of location database #24429
base: master
Are you sure you want to change the base?
Conversation
c375363
to
2dc7f33
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.
Looking forward to seeing changes which insert data...
return -1; | ||
} | ||
|
||
bool readonly = ((flags & O_ACCMODE) == O_RDONLY); |
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.
bool readonly = ((flags & O_ACCMODE) == O_RDONLY); | |
const bool readonly = ((flags & O_ACCMODE) == O_RDONLY); |
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.
Should this be checking only to see if the O_RDONLY bit is present? i.e. flags & O_RDONLY
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 think yes, we can do this but I followed AP_Filesystem_Mission. Also, what if more bits like O_WRONLY are also set? I mean, it might be due to an error but just in case.
const uint8_t item_size = sizeof(packet_t); | ||
uint32_t total = 0; | ||
|
||
while (count > 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.
We need a sanity check here that we don't do too many oops.
Can't have anything that even remotely looks like an infinite loop in here.
I mean this looks right, but just a check that we don't stay in this loop more that 500 time would be 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.
Okay. I have replaced it with a for loop with a limit on number of iterations.
|
||
const AP_HAL::HAL& hal = AP_HAL::get_HAL(); | ||
|
||
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX |
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.
Do we compile these tests for things other than those two?
static float random_float(void) { | ||
return ((((unsigned)random()) % 2000000) - 1.0e6) / 1.0e6; | ||
} |
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.
We have a HAL function to get random numbers, I believe.
But... we shouldn't be using random numbers in tests like this unless it is strictly required. Repeatability is key. other sorts of tests can monte-carlo all they like, but these unit tests shouldn't change run-to-run.
Which is to say you should be testing codepaths with crafted identifiers here, not relying on random numbers to explore the space.
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.
Okay. I have removed the use of random numbers from the tests. Thanks for the suggestion.
return (uint8_t)KeyDomain::MAVLINK << 24 | sysid << 16 | compid << 8 | short_mav_msg_id(msgid); | ||
} | ||
|
||
// helper method to construct location database key for an adsb item |
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.
// helper method to construct location database key for an adsb item | |
#if AP_LOCATIONDB_KEYDOMAIN_ADSB_ENABLED | |
// helper method to construct location database key for an adsb item |
... and in the configuration file you would
#ifndef AP_LOCATIONDB_KEYDOMAIN_ADSB_ENABLED
#define AP_LOCATIONDB_KEYDOMAIN_ADSB_ENABLED HAL_ADSB_ENABLED
#24377
(and include AP_ADSB_config.h
in AP_LocationDB_config.h
)
Similarly for the other domains.
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.
Done for ADSB and SCRIPTING domains. Thanks. I couldn't find right define for MAVLINK domain though.
Current flash cost, sans scripting bindings which aren't working ATM:
|
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.
Pretty sweet to see this in action. A few minor requests, overall looking good. I was wondering - what's the behavior if vehicles are added to the database from both scripting and ADSB - do they conflict?
class AP_LocationDB { | ||
public: | ||
friend class AP_Filesystem_LocationDB; | ||
friend class AP_OABendyRuler; |
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'm wondering why Bendy Ruler should be a friend class? Should we not try to avoid entangling the producer and consumer?
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.
We do not give sequential access to the database elements to the outside world. To access any element, we need to have the key to the element. This works good in most of the cases. AP_OABendyRuler needs to access all the elements sequentially and it does not have keys to all the elements. Hence, I have made AP_OABendyRuler a friend class so that it can access the private method get_item_at_index
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.
It would be better IMO to provide an iterator that can allow Bendy Ruler (or any consumer) to access the elements sequentially.
00b0d66
to
4c7c4f1
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.
Refine enablement flag
#include <AP_Scripting/AP_Scripting_config.h> | ||
|
||
#ifndef AP_LOCATIONDB_ENABLED | ||
#define AP_LOCATIONDB_ENABLED BOARD_FLASH_SIZE > 1024 |
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 to be refined. Ideally it should be enabled based on the features that require it (OA at the moment?). Either way I think we should now avoid putting board size checks in the source code, but instead use whatever is the final result of @peterbarker 's minimal_config.inc
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 to be refined. Ideally it should be enabled based on the features that require it (OA at the moment?). Either way I think we should now avoid putting board size checks in the source code, but instead use whatever is the final result of @peterbarker 's minimal_config.inc
I actually suggested this change - previously it was on on all boards, including 1MB boards.
We do have some 1MB boards which haven't been minimized yet, and I don't think we can use the minimize files.
I have wondered about how we might remove the BOARD_FLASH_SIZE checks throughout the code, but haven't really come up with any great ideas. We could add them in the chibios_hwdef.py
in-line includes, I guess? In any case, I don't think the pattern I suggested here is uncommon in AP, so do you think we should hold things up 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.
Why not make it dependent on the features that are using it? I think these are fairly specific
Also shouldn't below be:
#define AP_LOCATIONDB_KEYDOMAIN_ADSB_ENABLED HAL_ADSB_ENABLED && AP_LOCATIONDB_ENABLED
For example, otherwise switching it off is hard
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.
Yep, the individual key domains would probably look something like this:
#define AP_LOCATIONDB_KEYDOMAIN_ADSB_ENABLED AP_LOCATIONDB_KEYDOMAIN_DEFAULT_ENABLED && HAL_ADSB_ENABLED
That's the way we're moving with a lot of our libraries.
We could potentially make it dependent on whether there's any consume of the data - could you investigate that, @shiv-tyagi , please?
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.
Yep, the individual key domains would probably look something like this:
I have applied these changes. Thanks.
We could potentially make it dependent on whether there's any consume of the data - could you investigate that, @shiv-tyagi , please?
Yes, we can probably make it dependent on MODE_FOLLOW_ENABLED || AC_AVOID_ENABLED.
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.
Update: I tried making AP_LOCATIONDB_ENABLED dependent on AP_FOLLOW_ENABLED (which is one of the consumers of the data) and it did not work out because AP_FOLLOW_ENABLED itself is dependent on AP_LOCATIONDB_ENABLED.
8f96914
to
48848bd
Compare
It would be great to get this PR in. What would it take? |
@timtuxworth I think we need to get #24624 merged first |
Why aren't we reusing or extending or refactoring or re-anythinging AC_Avoidance/AP_OADatabase? The word "Location" is kind of a key-word in ArduPilot and this object doesn't even contain that class! This new library has some new features like the FileSystem stuff but generally speaking it's a whole lot of redundant code re-inventing the wheel.
|
I think the intention is for the new class to eventually replace the OA LocationDB so just need to be sure we do that in the long term at least we don't end up with both. So some kind of plan to get rid of the old one. |
I've looked at this again and I think that it is OK for the existing OALocationDB and this LocationDB to co-exist as long as we make it clear (perhaps in the comments or something) that their uses are different. This one is really for vehicles (manned or unmanned) while the existing LocationDB is for small obstacles. |
This adds a global location database which can be used to store the location (as well other information like velocity, acceleration etc.) of other vehicles in neighborhood of a vehicle. This serves as a central repository for all such information and can be used for many purposes like following vehicles, tracking vehicles, avoiding vehicles etc.
Items can be added to this database from mavlink, ADSB and scripting as sources. This can be extended in future to support more sources. This has been tested thoroughly on SITL and units test for this have also been added to make sure this doesn't break in future.
This is used to implement multicopter avoidance to avoid collisions with neighboring vehicles around a copter.
More about the idea of implementing this database and its use cases are posted in this blog post.
Should be merged after #24508