Flow Breakout readings

Discussions about all things Bitcraze
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Flow Breakout readings

Post by Sailorjoe »

I am a Mentor for a high school team building robots for FIRST Robotics competitions. https://www.firstinspires.org/robotics/frc We are trying to use a Flow Breakout sensor to measure the movement of the robot on the field, and to control the autonomous activities of the robot. We have the Breakout board successfully connected to the SPI interface of the RoboRio, the robot's main processor. http://www.ni.com/en-us/support/model.roborio.html We also successfully connected the sensor to an Arduino using the Getting Started guide on the Bitcraze website.

As we move the robot around the room, we can observe and record the delta X and Y readings we get from the sensor. At first, everything seemed fine, but as we looked more closely, we discovered an unexpected effect. The robot starts a new control cycle approximately every 20 msec. A robot moving in a straight line at a constant speed should show a relatively constant delta X reading each cycle. We do see that, but about every fifth reading (approximately every 0.1 seconds) we see a reading that is approximately half of the expected reading. This is what we see on the RoboRio. On the Arduino, about every fifth reading is twice what we see on the other cycles. The unexpected values are not caused by a single bit change; it's most often multiple bits that change between readings.

There is a lack of detail from the sensor vendor in their datasheet, so I'm hoping someone on this forum has some experience or other information that can explain this issue and how to mitigate it. Thanks in advance for any advice.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flow Breakout readings

Post by arnaud »

Hi,

If you accumulate the counts, is it consistent?

For the Crazyflie, using the flow deck which is based on the same sensor, we are getting measurements that oscillate between a count and another. Here I flew the crazyflie in velocity control mode and I made it fly in a constant velocity for a while:
constant_motion.png
My assumption is that the sensor is somehow accumulating movement and updating the delta by batch and since we are reading the delta asynchronously we get different count depending of when we are reading. So the instant reading is wrong but if we accumulate the delta we read, the accumulation is accurate.

In the Crazyflie we are not using the delta count directly to measure velocity, it is pushed in a Kalman filter together with other sensors, this allows us to get a smooth velocity estimate.

Have you tried to read the sensor faster or slower to see if it yields more consistent readings?
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Re: Flow Breakout readings

Post by Sailorjoe »

Thank you for your quick reply, arnaud. One of the difficulties of our control system is that it's cycle time of 20 msec varies quite a bit, by as much as +/- 5 msec. So during one test I divided the delta X counts by the actual time step to see if that would explain the inconsistencies. It didn't. There was no correlation between the timestep variation and the readings, except for what you would expect for the normal readings.

As I look at your graphs, I see what appears to be a normal noise signal, with readings that vary above and below an average midpoint. That's not what we are seeing. I will post a graph later today if I can get one off the robot. But for now, imagine your delta X graph raised to about 100 counts. Now imagine that every fifth reading is about 60 counts. It might be the fourth reading in a row, or sometimes the sixth reading, but it averages to every fifth reading. At first I thought we were dropping a bit (2^5), but that didn't check out. I don't have a logic analyzer to watch the SPI bus, so all I can do is deduce from the readings.

In another experiment, we put an Arduino on the robot and measured the sensor readings. This elimininated the robot control system from the equation. But we experienced essentially the same effect. I will have some graphs in my next post. I'm hoping someone knows about a control setting on the sensor that can eliminate this problem.
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Re: Flow Breakout readings

Post by Sailorjoe »

I couldn't get the readings I need because the kids have the robot torn down for improvements. In the meantime, I've been analyzing some early data I have, and it seems clear that I'm having a bit readout problem. I was able to show, using a histogram, that I'm losing the 2^4 bit about one time in four. It changes from a 1 to a 0, or a 0 to a 1, about 25% of the time. If anyone knows of a way to modify the FlowMotion chip SPI interface via the control registers, I'd like to hear about it. I'm not completely convinced that the SPI interface on the RoboRio is fully compatible with the Flow Breakout. More later when the robot is working again.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flow Breakout readings

Post by arnaud »

One thing we have found during development is that the SPI timings documented in the datasheet (section 2.4) are very important. We have had a lot of problem when driving the n_cs pin too quickly before/after data transfer and with the timing between bytes during data transfer. Though, if there where this kind of problem with the SPI, I would expect the problem to be gone with an Arduino since the Arduino lib for the PMW3901 has 'sleeps' in the SPI routines.
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Re: Flow Breakout readings

Post by Sailorjoe »

Thank you, arnaud. I will take a close look at those timing requirements when I get a scope set up. I don't have a lot of control on the SPI interface on the RoboRio, so I may have to bit-bang some gpio pins to get what we need.

In the meantime, I noticed that the initialization steps for the PWM3901 are different between the Arduino code and the Crazyflie code. Are the differences important? Should I use the crazyflie code with my RoboRio, or the Arduino code? Thanks for your advice.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flow Breakout readings

Post by arnaud »

Either init procedure should work but they should be very similar, what is the difference you have seen?
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Re: Flow Breakout readings

Post by Sailorjoe »

In the crazyflie code there are about thre or four changes in the data values used in a certain register, and there are a few additional register settings at the end of the sequence. I don't have the listing in front of me to compare or I'd list the line numbers. With the lack of vendor information, there's no way to tell if the differences are important or not.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Flow Breakout readings

Post by arnaud »

Hum, I do not think there should be a difference, if you try the Crazyflie register setting I would love to know if it makes a difference.
Sailorjoe
Beginner
Posts: 10
Joined: Thu Mar 22, 2018 5:30 am

Re: Flow Breakout readings

Post by Sailorjoe »

OK, we had a long delay after the FRC competition season while the kids recovered, and the teacher/coach recovered from pneumonia. I finally got access to our sensor, and I've been experimenting with it at home with an Arduino. I've tried a number of different options for reading the device, but in the end, nothing seemed to work very well except the existing readMotionCounts library call. One of the things I tried was to do a burst read of the first 11 registers using Arduino's SPI.transfer(buffer, size) call, but that didn't seem to work at all. I doubt it meets the timing requirements for the sensor chip. So I'm back to the beginning, just looking at deltaX, deltaY readouts. I have a simple set up on my desk with the sensor on a bracket looking down from a fixed distance of approximately 102 mm. The Arduino main loop is reading the motion counts, printing the results, then delaying 20 msec, and starting again. I get varying results depending on the amount of delay, and this is the interesting part of this investigation. The attached spreadsheet shows several typical runs, one per sheet. In each case, I seem to get a spurious reading every fourth or fifth reading. The 10 msec loop has unexpected low readings, the 20 msec loop has unexpected high readings. On the FRC Robot where we really want to use the Flow Motion sensor, we get the exact same effect as described in my earlier posts. To my eye, this doesn't look like sensor noise, because it's so periodic. I think it's something else.

On the Arduino, the motion information is read out one register at a time, for a total of five registers. In the Crazyflie software, the same registers, plus others, are read out in a single burst. Does this make a difference? Is it possible that reading single registers causes some kind of mixup of data from the first register read to the second one? Does anyone know of a control register or bit that we can use to ensure we are properly synchronized with the sensor operation? Alternatively, is there a way to do a burst read of all the registers with the Arduino? If I can get that to work, maybe I can get it to work on the FRC Robot.

The attached spreadsheet has several sheets, each labeled with a different time delay setting in the main loop.
Thanks for any advice you all can provide.
Attachments
FlowMotionTests.xls
Test runs of the Flow Breakout board on Arduino.
(62 KiB) Downloaded 227 times
Post Reply