OCCRA
Go to Post You play your best, the refs do their best, and at the end of the day we are FIRST, collectively. - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Sensors
CD-Media  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-08-2018, 04:17 PM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Post New Motion Sensor

In the summer of 2017, a company called Bitcraze, makers of the Crazyflie drone, announced a new motion sensor for general purpose use. This product is their Flow Breakout board. We tried to use this sensor on our robot for the 2018 season. The attached white paper describes what we learned about how to get started using the sensor. In total it took several months to figure out how to use the sensor correctly, because the sample program from the vendor was incorrect (still is), and because we didn't pay proper reverence to the sensor chip's SPI interface timing requirements, assuming the RoboRio SPI interface would be just fine. If you decide to use this sensor, and we do recommend it, you will be months ahead if take advantage of what we learned the hard way. We would love to hear what you learn if you use this new sensor, too.
Attached Files
File Type: doc FlowSensorWhitePaper.doc (82.0 KB, 137 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 09-08-2018, 05:29 PM
Brian M's Avatar
Brian M Brian M is offline
Design Lead
FRC #1360 (Orbit Robotics)
Team Role: CAD
 
Join Date: Feb 2017
Rookie Year: 2012
Location: Ontario, Canada
Posts: 328
Brian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond reputeBrian M has a reputation beyond repute
Re: New Motion Sensor

This sensor seems extremely useful, thank you for sharing! I read through your white paper and it seems like you have been able to get readings and should have been able to use it on the real field for an auto, but viewing your most recent matches it seems your team still only had a simple drive forward auto. Have you been able to develop this further and create accurate auto modes or is just testing the sensor as far as you have gotten?
__________________
2016 - Rah Cha Cha Ruckus Winners (3015 & 4039)
2017 - Industrial Design (Durham), Entrepreneurship (McMaster), Quality Award (Ontario DCMPS)
2018 - Georgian District Winner (1305 & 6864) + Innovation in Control, York District Winner (1325 & 6140) + Chairmans Award, Ont DCMP Excellence in Engineering


Reply With Quote
  #3   Spotlight this post!  
Unread 09-08-2018, 05:40 PM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

Thank you for your interest, Brian. We had the sensor mounted on the competition robot, but because of the problems described in the paper, we really never got it working correctly until after the season was finished. It was in the post-season school year that we added the timing delays, rearranged the register read sequence, and added the squal and shutter variables. Because the Arduino code "appeared" to work, and because we "appeared" to get good readings three times out of four, the diagnostic process took us down a lot of dead ends. So you're seeing about six months of trial and error learning collapsed into a paper. I hope the team decides to use the sensor this year for better autonomous performance.
Reply With Quote
  #4   Spotlight this post!  
Unread 09-20-2018, 12:22 AM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

The attachment herein has the spreadsheet we used to capture and analyze the test data for the Flow Motion sensor on the Arduino. I have it in xls format, but we did it originally with OpenOffice. Not sure if that will cause problems.
By way of explanation, Sheets 1 through 7 show the data from the sensor with different loop delay values. You can see the spikey data, but at this point, these can be ignored.
Sheet 8 is where most of the good stuff resides. At this point the software library problem had been solved. The left columns are the ascii data from the sensor via the Arduino. The next columns are the same data in numeric form. The column called "Rounds" is an Arduino count of times through a "sensor ready to read" loop, and its not likely useful any longer.
Then there is the same data through a low pass filter with half second time constant that can be adjusted. The graph shows motion going out and back to zero.
Under the top graph is a sorted list of runs made sequentially, in one direction only. The table is sorted by the number of readings, which goes down as the speed goes up for the fixed distance. To the left of the table is a graph of the same data.
Sheet 9 is the data from just one run of the Y axis, and we see no surprises.
Sheet 10 is a single run by turning (spinning by hand) the sensor. No surprises there either, so far.
I hope this provides some enlightenment on how to begin to interpret the data from the sensor. We certainly have more work to do to understand it before build season.
Attached Files
File Type: xls FlowMotionTests.xls (284.5 KB, 17 views)
Reply With Quote
  #5   Spotlight this post!  
Unread 12-04-2018, 04:21 AM
dannytix dannytix is offline
Registered User
FRC #0568 (Nerds of the North)
Team Role: Mentor
 
Join Date: Dec 2018
Rookie Year: 2007
Location: Anchorage, AK
Posts: 2
dannytix is an unknown quantity at this point
Thumbs up Re: New Motion Sensor

sailerjoe: After years of lurking on CD, I registered just to say thank you for sharing this! We also purchased a couple of these sensors last year, and had to throw in the towel

Quickly scanning through your code, it looks like the key piece we were missing was reading all of the registers in order. I'll try to get some team members on integrating your paper into our code and report back if they find anything interesting.

Our solution to the timing problem was to tap directly into the underlying C libraries to use Linux SPI functions which allow you to add a delay directly. Reliable timing and no extra pins; at the cost of an extra dependency through JNA. We were able to perform basic communication this way, but the motion register readings never made sense. Now I know why (...I hope...)

If you're interested in this approach, it's on the Team 568 GitHub. One difference that stands out is that - by my reading (and recollection) of SPI mode 3 - we should have been setting spiFlow.setClockActiveLow() and spiFlow.setSampleDataOnRising(). However - due to a WPILib bug - the 568 code used setSampleDataOnFalling(); while your team used setClockActiveHigh(). It's equally possible that your team tripped on the same bug we did and chose the opposite fix; or that my team just read the definition wrong - the wikipedia article is a bit hard to parse. Either way, I wanted to point out that the WPILib bug was fixed over the Summer, and - if I'm not mistaken - you should migrate to setClockActiveLow() and the new setSampleDataOnTrailingEdge() method instead. If I am mistaken, I'd appreciate your input all the more.

Regards,
Danny Tix
Mentor - Team 568
Reply With Quote
  #6   Spotlight this post!  
Unread 12-12-2018, 12:43 AM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

Thank you, Danny, for your thoughts on using the Flow Motion Sensor. I rather like how you solved the timing problem, but for now, I think we will stick with what we have since it works and we already have the cable built.
I agree that the wikipedia article is a bit tricky, as is the Arduino article for the same topic. Our initial settings for SPI Mode 3 didn't work as expected. We finally just tried a number of combinations of settings until we found one that worked, which is what we have in the published code. Thanks for letting us know about the bug fix. We will have to take another look at the settings again, and we will republish the code if it needs to be changed.
Looking at your code, on lines 177 and 191, I see timing delays specified in microseconds. My understanding was that delays less than 1 millisecond resolved to just 1 millisecond delays, using the Timer.delay() function. Is this not correct? I asked this question in the white paper, too. We had to use delay loops in the code, but specific delay statements like yours would be better if they are accurate.
Reply With Quote
  #7   Spotlight this post!  
Unread 12-12-2018, 04:16 AM
dannytix dannytix is offline
Registered User
FRC #0568 (Nerds of the North)
Team Role: Mentor
 
Join Date: Dec 2018
Rookie Year: 2007
Location: Anchorage, AK
Posts: 2
dannytix is an unknown quantity at this point
Re: New Motion Sensor

Joe - thank you again for your valuable insight. It appears that you are right about Timer.delay() only supporting millisecond accuracy. It's just a simple wrapper around the less precise version of Thread.sleep().

That still leaves the (supposedly) nanosecond accurate overload of Thread.sleep() though. Do you know if your team was able to rule that out? If not, we'll try it next.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-13-2018, 12:10 AM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

Hi, Danny. Those are good questions. We got the millisecond limit by scouring the web for information about the wpilib function. So we immediately discarded it from consideration for 50 microsecond timing delays. I'm never sure the RoboRio implements all the features of Java, so I usually just stick with the wpilib. Thus, we decided to go old-school and use a delay loop like you see in the code. However, if you're exploration of the Thread.sleep() method turns up a gem, we'd really like to know about it. When we measured the timing loops on the oscilloscope, we saw very stable timing pulses, like within a tenth of a microsecond of repeatability. I'd love to know if the overloaded version of Thread.sleep() works that well on the RIO. Looking forward to your test results. If they're good, we can update the code.
Reply With Quote
  #9   Spotlight this post!  
Unread Yesterday, 01:25 PM
Byte11 Byte11 is offline
Registered User
FRC #2353
 
Join Date: Feb 2017
Location: Kansas City
Posts: 14
Byte11 is an unknown quantity at this point
Re: New Motion Sensor

First off, I want to say that this is an amazing example of how amazing this community is at sharing information. This is a great find that you've graciously shared with everyone on here and I appreciate it.

Regarding the issue of microsecond-level timing in Java. Here is a great article I found on the topic, but I have yet to test it: http://www.rationaljava.com/2015/10/...d-in-java.html. It concludes that busy waiting is the most accurate way to go using System.nanoTime().

How did you wire the breakout board to the RoboRio? We've never created a custom cable before or anything along those lines, so if have a wiring diagram or something like that, it would help a lot.

Secondly, I was looking at the spreadsheet you attached and it mentions that you were filtering the data. How were you doing that? Was it a Kalman filter? I didn't see anything like that in the code.

Thank You
Reply With Quote
  #10   Spotlight this post!  
Unread Yesterday, 01:38 PM
Byte11 Byte11 is offline
Registered User
FRC #2353
 
Join Date: Feb 2017
Location: Kansas City
Posts: 14
Byte11 is an unknown quantity at this point
Re: New Motion Sensor

Quote:
Originally Posted by Byte11 View Post
Secondly, I was looking at the spreadsheet you attached and it mentions that you were filtering the data. How were you doing that? Was it a Kalman filter? I didn't see anything like that in the code.
Never mind, I see that you were averaging the last filtered value with the current deltaX to get the current filtered value. I don't know why that works so well to smooth the data, but the results are pretty good.
Reply With Quote
  #11   Spotlight this post!  
Unread Yesterday, 04:48 PM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

It's a standard low pass filter with a 0.5 time constant. The time cconstant can be modified in the spreadsheet with values from 0 to 1, and you can see the effects. I tried various values, and settled on .5 as the number with good smoothing and minimal settling delay.
Reply With Quote
  #12   Spotlight this post!  
Unread Yesterday, 05:50 PM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

Thanks very much for the tip on microsecond timing. After we test to make sure it works on the Rio, we might switch over to using that, making us less susceptible to hardware changes.

As to the cable, you'll find it's a useful skill to make your own cables sometimes. This is a case in point. In order to avoid modifying the SPI Rio code, we needed a cable that connects to both the SPI interface and to a DIO channel. The Breakout Board has *two* separate interfaces, one for the distance sensor using I2C, and one for the motion sensor using SPI. We didn't use the I2C part. We buy a kit of parts from Amazon that we use to make circuit board headers and matching cable connectors. https://www.amazon.com/OCR-Connector...+connector+kit.
You also need a crimping tool: https://www.amazon.com/IWISS-Profess...RJZZ96G7G0DPHE
We typically use ribbon cable between the connectors at each end, but sometimes we use regular wire. https://www.amazon.com/IWISS-Profess...RJZZ96G7G0DPHE or https://www.amazon.com/Eowpower-16-5...on+cable&psc=1.
And you'll need a wire stripper to bare the ends of the wires. I recommend adding solder to the bare wire ends so they hold the crimped connector better. Check YouTube for how-to videos.
I'll post a pic of what we did tomorrow, along with a schematic.
Note: Don't forget to illuminate the floor where the sensor is looking...a lot!

Last edited by sailorjoe : Yesterday at 05:56 PM.
Reply With Quote
  #13   Spotlight this post!  
Unread Yesterday, 05:58 PM
Byte11 Byte11 is offline
Registered User
FRC #2353
 
Join Date: Feb 2017
Location: Kansas City
Posts: 14
Byte11 is an unknown quantity at this point
Re: New Motion Sensor

What about the wiring? I was looking at the arduino getting started guide for the wiring diagram and trying to match it with SPI, but some didn't line up. Here's a link to the diagram: https://www.bitcraze.io/getting-started-flow-breakout/.

Flow GND -> Roborio SPI GND
Flow VCC -> Roborio SPI 5V
Flow CS -> Roborio SPI CS0
Flow MISO -> Roborio SPI MISO
Flow CLK -> Roborio SPI SCLK? This could also be SCL
Flow MOSI -> Roborio SPI MOSI
Flow SCL -> Roborio SPI SCLK? This could also be CLK
Flow SDA -> I'm not sure. It's plugged into an Arduino analog input, so maybe an analog in. If I had to guess, I'd go with the top pin on the third input because you mention port 3 inside the code, but it doesn't specify port three on what part of the board. m not sure. It's plugged into an Arduino analog input, so maybe an analog in. If I had to guess, I'd go with the top pin on the third input because you mention port 3 inside the code, but it doesn't specify port three on what part of the board.

Can you shed some light on the SCL, SDA, and CLK ports? Or am I getting this wiring all wrong?

Thank You
Reply With Quote
  #14   Spotlight this post!  
Unread Yesterday, 06:24 PM
sailorjoe sailorjoe is offline
Mentor, RoboEagles, FWHS
AKA: Joe Hafner
FRC #4579 (RoboEagles)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Auburn, WA
Posts: 22
sailorjoe will become famous soon enough
Re: New Motion Sensor

I'll try to describe the wiring, because I won't be able to get a picture until tomorrow.
Starting with Pin 1 on the Flow Breakout board, which is Gnd, connect that to ground on the Rio SPI connector.
Pin 2, Vcc connects to 5V on the Rio SPI connector.
Pin 3, CS connects to the S pin of your choice of DIO channel on the Rio.
Pin 4, MISO connects to MISO on the Rio SPI connector.
Pin 5, CLK connects to SCLK on the Rio SPI connector.
Pin 6, MOSI connects to MOSI on the Rio SPI connector.
That's it! None of the other pins are needed, unless you want to. You could connect Pin 7, Motion to any DIO channel, and use it to detect motion. We didn't need it, and our software doesn't support it. You could also connect Pin 8, *RESET to a DIO channel so you can reset the sensor, but it's not necessary.
The remaining pins are the I2C interface for the distance sensor, and they're not used in our application.
*Note: we only have one sensor on the SPI interface. If you have more, you're wiring might change somewhat.
Hope that helps.
Reply With Quote
  #15   Spotlight this post!  
Unread Yesterday, 06:51 PM
Byte11 Byte11 is offline
Registered User
FRC #2353
 
Join Date: Feb 2017
Location: Kansas City
Posts: 14
Byte11 is an unknown quantity at this point
Talking Re: New Motion Sensor

Thank you very very much. This is going to be so much fun to play around with.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:57 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi