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

Pr tfminiplus and command support #13831

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

amoizard
Copy link

@amoizard amoizard commented Jan 2, 2020

Describe problem solved by this pull request

Describe your solution

A new "tfmini command -c XXXXXX" is introduced to help device configuration
directly from the flight controler. TFMini and TFMini-plus are both supported.

The parser has been improved to support receiving confirmation from the device
after a command has been written.

The parameter SENS_EN_TFMINI is implemented again to let user define the TFMini
model that will be used. This helps to validate commands and validate command's answers.

SENS_EN_TFMINI is also required because TFMini models don't offer the same capabilities
for FOV and MIN-DISTANCE.

The parser has been improved to provide signal quality for TFMini-plus.
The same should be done in the future for TFMini model.

The driver has been improved to autoconfigure the mode AND enable the output for TFMini-plus upon starting.
The same should be done in the future for TFMini model.

Describe possible alternatives

The TFMini-plus has signal strength between 100 and 0xFFFF for valid values. However, from testing, values are usually between 100 and 20000 instead. The scaling may not be perfect, but I have decided to measure signal_quality (in percentage) as 100strength/20000 instead of 100strength/0xFFFF with maximum strength being 20000 instead of 0xFFFFF.

Test data / coverage

I have tested the patch on a drone with a flight controler running latest master branch, but without flying. I have no drone ready to fly. Most of the patch concerns configuration, so I don't feel this is critical. Of course, I hope someone can fly with the patch and report

I have implemented as much as I need about the TFMini-plus model, but I have decided to not write the autosetup for the TFMini model because I don't have the device. However, I could write it, if someone is willing to test it.

Here are some example of command lines that can be used to configure the TFmini-plus device using nsh:

Retreive the version on a TFMINI-Plus: (0x5A 0x04 0x01 0x5F)
$ tfmini command -c 5A04015F

Configure TFMINI-Plus in Standard 9 bytes (cm) mode: (0x5A 0x05 0x05 0x01 0x65)
$ tfmini command -c 5A05050165

Configure TFMINI-Plus Frame Rate: (0x5A 0x06 0x03 0xLL 0xHH 0xSU) - Example for 100Hz
$ tfmini command -c 5A06036400C7

Apply and Save Settings for TFMINI-Plus: (0x5A 0x04 0x11 0x6F)
$ tfmini command -c 5A04116F

@dagar
Copy link
Member

dagar commented Jan 3, 2020

I have implemented as much as I need about the TFMini-plus model, but I have decided to not write the autosetup for the TFMini model because I don't have the device. However, I could write it, if someone is willing to test it.

I can arrange tfmini testing.

@dagar
Copy link
Member

dagar commented Jan 3, 2020

Instead of passing through raw commands did you consider making them a bit higher level? For example requesting the version, configuring the frame rate, etc.

@amoizard
Copy link
Author

amoizard commented Jan 3, 2020

Tks @dagar for all your comments. I have pushed 4 commits to answer your reports.

  • I have added comments to reference the documentation of TFmini and TFmini-plus models.
  • I have added comments to explain the command/answers for both TFmini and TFmini-plus models.
  • I have added an enum TFMINI_MODEL for code readability
  • I have used PX4_INFO instead of printf where you asked. (it's not clear from other drivers as sometimes printf is used, and other times PX4_INFO is used...)

Instead of passing through raw commands did you consider making them a bit higher level? For example requesting the version, configuring the frame rate, etc.

I had the feeling that I should try to minimize the amount of code written, to avoid increasing the final binary size. If a higher level code is provided, it would means translating around 10 commands per devices, same amount of answers, plus the variant of each commands (on/off, or frequency, etc..)

If you feel this is required (at least for interesting commands), it may be better to bring this in a separate pull request?

@dagar
Copy link
Member

dagar commented Jan 3, 2020

I have used PX4_INFO instead of printf where you asked. (it's not clear from other drivers as sometimes printf is used, and other times PX4_INFO is used...)

Thanks, there's still a bit too much inconsistency at the moment. Nearly all the printfs should be removed.

If you feel this is required (at least for interesting commands), it may be better to bring this in a separate pull request?

Certainly not required, I was mainly trying to gauge if there's a subset of commands worth implementing directly to actually make the functionality accessible.

@mcsauder
Copy link
Contributor

mcsauder commented Jan 3, 2020

The PR checks out well with a pixhawk 4 and tfmini plus.

I'll make a few comments in the code but it looks to be in good shape from my perspective! Nice work!

Configure TFMINI-Plus Frame Rate: (0x5A 0x06 0x03 0xLL 0xHH 0xSU) - Example for 100Hz
$ tfmini command -c 5A06036400C7
Apply and Save Settings for TFMINI-Plus: (0x5A 0x04 0x11 0x6F)
$ tfmini command -c 5A04116F
Copy link
Contributor

@mcsauder mcsauder Jan 3, 2020

Choose a reason for hiding this comment

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

If there are a limited number of commands available, it might be easier for the user to abstract the hex values here by giving them variables/names.

Copy link
Author

Choose a reason for hiding this comment

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

If there are a limited number of commands available, it might be easier for the user to abstract the hex values here by giving them variables/names.

The commands are not limited to any subset. They will be validated for TFmini and TFmini-plus (header and lenght only) and will be rejected if model is not defined.

I will take into account your comments and will push more changes.
Thanks a lot @mcsauder !

@amoizard
Copy link
Author

amoizard commented Jan 3, 2020

I have implemented as much as I need about the TFMini-plus model, but I have decided to not write the autosetup for the TFMini model because I don't have the device. However, I could write it, if someone is willing to test it.

I can arrange tfmini testing.

I have commited autosetup for TFmini model. As I said, I don't have the device, so this is very blind code...

In order to verify, you need at least to run the command "tfmini status" under nsh with a TFmini model being connected and with SENS_EN_TFMINI being set to 1.

This should display, among other lines:
"TFMINI is configured - version=unknown"

If anything went wrong, please let me know!

@mcsauder
Copy link
Contributor

mcsauder commented Jan 4, 2020

Hi @amoizard ,

It looks like things are functioning properly.

One detail we could attend to, it appears the driver is returning tfmini::usage() at every start. It might make the driver main() function cleaner if we eliminate the else if chain and just use if statements. (The terraranger and ulanding drivers illustrate that as an example.)

image

image

image

@mcsauder
Copy link
Contributor

mcsauder commented Jan 4, 2020

@amoizard and @dagar , just an FYI, the tfmini driver is starting and continuing to run even if no tfmini is connected at boot in this PR and in current master. If a device is connected after boot, it recognizes the device and continues to run properly in both branches as well.

@amoizard
Copy link
Author

amoizard commented Jan 5, 2020

@mcsauder / thanks for testing, but it's not working...

image

From your snapshot above, the "autosetup" for TFmini doesn't work. It is written "TFmini is being configured" instead of "TFmini is configured". The "state" is still the first one, which means even the first "command" (enter setup) was not accepted.

I advise you to try this command first:

tfmini command -c 4257020000000102

The result must be: (20ms can be different)

command confirmed [20ms] [4257020100000102]

I'm sorry I can't debug this myself. I have looked for a typo or some obvious mistake, but couldn't locate the issue.

@hamishwillee
Copy link
Contributor

FYI, when this goes in, we should update this page: http://docs.px4.io/master/en/sensor/tfmini.html

@amoizard
Copy link
Author

@mcsauder , @dagar

I have finally purchased a TFMINI in order to test myself.
With minor change, I was able to fix the autosetup and validate usage of the command with TFMINI model.

As you can see in the snapshot, the "tfmini status" is showing the expected line saying:

INFO [tfmini] TFMINI is configured - version=unknown

image

Also, setup via the command line also works. The use-case below is showing the sequence:

  • enter setup mode
  • configure standard mode
  • configure unit in cm
  • save setting and leave setup mode

image

@amoizard
Copy link
Author

amoizard commented Jan 23, 2020

It seems the build failure was related to a timeout which is not related to my patch... Any way to restart the checks?

@amoizard amoizard force-pushed the pr-tfminiplus-and-command-support branch from 3fd7a6d to 9789465 Compare January 23, 2020 18:58
@mcsauder
Copy link
Contributor

@amoizard , try merging upstream/rebasing and see if we get the same CI failure again.

@amoizard amoizard force-pushed the pr-tfminiplus-and-command-support branch 2 times, most recently from 012e55b to 957484f Compare January 28, 2020 11:36
mcsauder
mcsauder previously approved these changes Jan 28, 2020
Copy link
Contributor

@mcsauder mcsauder left a comment

Choose a reason for hiding this comment

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

This looks good to me. I'd like to follow up with another PR after this one goes it to do a bit of refactoring and move some of the new method calls out of collect() into init(), but this is a good first step.

Nice work @amoizard !

@stale
Copy link

stale bot commented Apr 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@LorenzMeier
Copy link
Member

Would you mind rebasing and re-testing this? My apologies that this wasn't followed up on.

@stale stale bot removed the stale label Jan 10, 2021
@amoizard
Copy link
Author

Would you mind rebasing and re-testing this? My apologies that this wasn't followed up on.

I'm sorry: I'm not any more involved on the project and I don't have my px4 any more. I do hope @mcsauder will be able to replace me on this patch?

@mcsauder
Copy link
Contributor

Would you mind rebasing and re-testing this? My apologies that this wasn't followed up on.

I'm sorry: I'm not any more involved on the project and I don't have my px4 any more. I do hope @mcsauder will be able to replace me on this patch?

Sure thing. I'll take care of it! Thanks for your work!

@mcsauder mcsauder force-pushed the pr-tfminiplus-and-command-support branch from 957484f to 926b2ce Compare January 11, 2021 23:23
@mcsauder
Copy link
Contributor

mcsauder commented Jan 12, 2021

Don't merge this yet, I still need to complete functional testing to make sure nothing has become broken in the time since this PR was submitted... I was actually shocked that the CI tests all passed. :)

@mcsauder mcsauder force-pushed the pr-tfminiplus-and-command-support branch 2 times, most recently from e53240a to 4e0497e Compare May 25, 2021 16:05
@mcsauder
Copy link
Contributor

I've rebased this PR and performed a few quick spot checks on the bench. This PR is good to go from what I can observe.

See also PR #17645.

… command

Add support various TFmini models and basic autosetup for TFMini-plus
Add "tfmini command -c XXXXXX" for device configuration
Improve parser to support receiving confirmation from the device after a command has been written.
Add SENS_EN_TFMINI param
Improve autoconfigure mode for TFMini-plus upon starting.
@mcsauder mcsauder force-pushed the pr-tfminiplus-and-command-support branch from 4e0497e to e112685 Compare October 2, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants