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

PMW3901MB optic flow sensor driver #2529

Closed
wants to merge 27 commits into from

Conversation

tomvand
Copy link
Contributor

@tomvand tomvand commented May 8, 2020

This PR adds a driver for the PMW3901MB optic flow sensor as found on the bitcraze flowdeck.

I only have access to a bench setup right now, if anyone could flight-test this it would be highly appreciated (@gautierhattenberger?). The sensor readings appear very noisy so I'm curious how well it works in closed-loop.

Copy link
Member

@gautierhattenberger gautierhattenberger left a comment

Choose a reason for hiding this comment

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

Great, thank you for this driver, I'll test it soon

sw/airborne/modules/sensors/opticflow_pmw3901.c Outdated Show resolved Hide resolved
Copy link
Member

@gautierhattenberger gautierhattenberger left a comment

Choose a reason for hiding this comment

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

I tried this on a crazyflie, but I can't get it to work. Spi transactions look good with logic analyzer, but no reply from the sensor. On which board did you test this code ?

conf/modules/opticflow_pmw3901.xml Outdated Show resolved Hide resolved
@tomvand
Copy link
Contributor Author

tomvand commented May 10, 2020

Hi Gautier, I tested this on the crazybee f4fr pro (=stm32f4) of the eachine trashcan, with the spi bus connected to the pads of the desoldered max osd chip.
Can you confirm that both the VCC and VCOM pins of the flowdeck receive power? (https://wiki.bitcraze.io/_media/projects:crazyflie2:expansionboards:flow-deck-v2_rev-a_schematic.pdf). That's what I was really stuck on and produced the same symptoms, although i would assume that the crazyflie should already handle this. And to be sure, you also checked the nCS signal I assume? And does the logic analyzer show the correct values being sent during chip initialization? (To rule out polarity issues?)
And what revision of the flow deck are you using? I tested this on the v2, although the optic flow sensor and circuit should be the same on both versions...

@gautierhattenberger
Copy link
Member

I'm using the flow deck v2 and with crazyflie v2.1 (stm32f4) and the range sensor is working, so I guess the power on the board is correct. The chip select line seems to be correctly used and the transmitted values are the correct one.
Actually, it starts sending the register values after the 100 trials at reading the register 0x00 without success as nothing is ever received (always 0xFF).

flow_deck_spi_analyzer

@tomvand
Copy link
Contributor Author

tomvand commented May 10, 2020

The range sensor uses only one of the two power pins, so it is not necessarily true that the optic flow sensor should also work then. Apart from that I have no idea what could be going wrong right now, I can take a closer look after the weekend. I would really like to be sure that the two voltages are present and correct. If that doesn't work, maybe adding a pull-down on miso changes anything?

@gautierhattenberger
Copy link
Member

I checked the power levels and they seem to be all good for both of them. Some thing for the internal 1.8V regulator. This might also be a hardware issue on by sensor. I will try to test it with the original firmware.

@tomvand
Copy link
Contributor Author

tomvand commented May 11, 2020

Fixed all comments. Will check if sensor still responds on my test setup with latest commit.

Edit: I had to test it on my trashcan branch (here) because the crazybee board is not merged with master yet, but there it all seems to work fine.

@gautierhattenberger
Copy link
Member

I reflashed the original firmware, but none of my decks are properly detected. Do you have any idea how to check that with crazyflie firmware ? From the doc, it tries to read the one wire memory chip, but in my case there is no reply at all. Even the multi-ranger, which is working for sure.
I might have some hardware issues here, so if you confirm that this is working for you, I'll merge as his.

@gautierhattenberger
Copy link
Member

Here is a capture of the sensor (finally) working with original firmware
flow_deck_spi_analyzer2
As you can see, the SPI idle level and phase are not the one you have selected for Paparazzi. Apparently it is idle low and detect on rising edge (edge 1).

@gautierhattenberger
Copy link
Member

@tomvand your crazybee board, is it using ChibiOS or libopencm3 ? I think the problem comes from the spi driver of ChibiOS that is not implementing (yet) the select/unselect option.

@gautierhattenberger
Copy link
Member

@tomvand check the pmw3901mb-pr in the paparazzi repo, I made some changes to the spi driver of chibios and some settings of your driver. It is now working on crazyflie

@gautierhattenberger
Copy link
Member

@tomvand did you get a chance to test with my modifications (https://github.com/paparazzi/paparazzi/tree/pmw3901mb-pr) ? I would like to merge this before the next release (soon)
I did a short flight with a crazyflie and it was working nicely.

@tomvand
Copy link
Contributor Author

tomvand commented May 13, 2020

Will check and review changes this morning.

edit: reviewed and tested, works well! Glad to hear it is actually flyable. Ready to merge.

@tomvand
Copy link
Contributor Author

tomvand commented May 15, 2020

(bump because I'm not sure if edited comments show up as new)

@gautierhattenberger
Copy link
Member

merged with 022e6ab
thanks

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.

2 participants