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

Refactor cm8jl65 driver. Employ uniform initialization, format, and deprecate ringbuffer and IOCTL. #11853

Merged
merged 5 commits into from Jun 29, 2019

Conversation

mcsauder
Copy link
Contributor

@mcsauder mcsauder commented Apr 15, 2019

Describe problem solved by the proposed pull request
This PR refactors the CM8JL65 driver to employ uniform initialization, move the parser and crc16 methods into the CM8JL65 class, move doxy documentation to the method declarations, and formats/standardize the driver structure.

This PR is a step in standardizing the cm8jl65 driver with other distance sensor drivers moving toward resolution of Issue #9279.

Distance sensor drivers and IMU drivers are perhaps the most numerous instances of code duplication in the drivers. Similar work is being undertaken in the IMU drivers as well, (PR #11629). Additional work within this driver will follow this PR.

Additional context
See Issue #9279.

Test data / coverage
This PR has been bench tested and flight tested with pixhawk 4 and pixkhawk 4 mini hardware, see comments below for data plots.

Please let me know if you have questions on this PR. Thanks!

-Mark

@mcsauder mcsauder force-pushed the cm8jl65_driver_work branch 3 times, most recently from e0f1e59 to e929642 Compare April 23, 2019 15:19
@mcsauder mcsauder changed the title Move cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments. Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments. Apr 24, 2019
@mcsauder mcsauder force-pushed the cm8jl65_driver_work branch 2 times, most recently from d0d9f3a to 719df19 Compare April 30, 2019 15:47
@mcsauder
Copy link
Contributor Author

@cmic0 , would you mind reviewing this PR? Thanks in advance!


};
ringbuffer::RingBuffer *_reports{nullptr};
Copy link
Member

Choose a reason for hiding this comment

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

Can this be gutted entirely (ringbuffer, ioctl, read, etc)?

Copy link
Contributor Author

@mcsauder mcsauder Jun 16, 2019

Choose a reason for hiding this comment

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

Unfortunately, not that easily... See my work here. However, if we can get this PR accepted and one to follow it from the continued work in the link I think the issue will become apparent.

I can successfully deprecate IOCTL usage from I2C devices, but not CDev devices. For CDev devices, these calls are still required.

UPDATED: The ringbuffer and read calls might be a little more straightforward. I will address those in subsequent PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please disregard my comments above. I discovered the issue preventing me from succeeding in deleting the ioctl calls was that the ioctl calls were where the start() method was being called from. Palm->forehead. :}

I have pushed up a commit that is bench tested and accomplishes your requests. I will post a/b comparisons and flight logs as soon as I can get to that work.

@mcsauder
Copy link
Contributor Author

Hi @cmic0 and @dagar , here are flight logs and plots of current PX4 master and this PR on a 250 sized drone, pixhawk 4 mini in position hold mode from ground level incrementing altitude slowly and holding at ~75cm increments up to ~3m.. The results are indistinguishable to me, so I think this PR is good to go. (I would like to squash the commits before merging to keep a clean history, please let me know when I can do this.)

PX4 master: https://review.px4.io/plot_app?log=89b6ccba-833f-454f-a0a7-f82078fbb049
image

This PR: https://review.px4.io/plot_app?log=b09b4f8a-12d4-4d1a-a062-a51852f3b189
image

@mcsauder mcsauder changed the title Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments. Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments and deprecate IOCTL. Jun 16, 2019
@mcsauder mcsauder changed the title Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments and deprecate IOCTL. Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments, refactor, and deprecate IOCTL. Jun 16, 2019
@mcsauder
Copy link
Contributor Author

@dagar, ping.

@mcsauder mcsauder mentioned this pull request Jun 24, 2019
@mcsauder mcsauder force-pushed the cm8jl65_driver_work branch 3 times, most recently from c17f0b9 to eb2bc54 Compare June 28, 2019 03:20
@mcsauder
Copy link
Contributor Author

@dagar and @davids5 , the cm8jl65 driver has sufficient stack allocated in PX4:master and (unchanged) with this PR:
image

@davids5
Copy link
Member

davids5 commented Jun 28, 2019

@mcsauder - we need @dagar confirmation but (IIRC) the 300 margin in the stackmon could be reduced to 96-100 - we only stack like 8 registers on the user process stack when an ISR is run. The rest of the penetration is application determined. Without 100% code coverage that worst case is not known. But 96 bytes of overhead is more than enough if the longest call depth has been exercised.

…st to declarations. Format whitespace and move method doxy comments to declarations.
 - Condense all class files into a single *.cpp file and give class scope resolution to previously unscoped methods.
 - Refactor cm8jl65 namespace level driver entry methods to reduce code and improve clarity.
 - Breakout CDev specific initialization LOC into the device_init() method.
 - Move the endian modification inside of the crc16_calc() method.
… printout and correct a comment in the driver.
@mcsauder
Copy link
Contributor Author

@davids5 and @dagar , I've reduced the cm8jl65 stack allocation from 1400 to 1200, merged latest master and rebased.

Stackcheck fails at 1100 and functions at the current commit value of 1200.

image

@mcsauder mcsauder changed the title Migrate cm8jl65 variable initialization from constructor list to declarations, format whitespace/comments, refactor, and deprecate IOCTL. Refactor cm8jl65 driver. Employ uniform initialization, format, and deprecate ringbuffer and IOCTL. Jun 28, 2019
@davids5
Copy link
Member

davids5 commented Jun 28, 2019

@mcsauder There are 3 things here.

  1. The stack check build - hardware test from 68+136 margin
  2. The loadmon's opinion that 300 (iirc) are needed.
  3. The Actual penetration of the application + ISR overhead.

The hard truth is that #1 will dictate 204 bytes of margin (it does not assume a separate interrupt stack)
So it is wasteful.

So I would have stack mon warn at 216

@dagar dagar merged commit db96b6c into PX4:master Jun 29, 2019
@mcsauder mcsauder deleted the cm8jl65_driver_work branch June 29, 2019 02:00
@mcsauder
Copy link
Contributor Author

Thank you for your review @dagar !

@mcsauder
Copy link
Contributor Author

(and thank you for your feedback @davids5!!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants