![]() |
Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
1 Attachment(s)
Disclaimer!! Currently this isn't tested!
So, apparantly this code wasn't included in WPILib, so I wrote one myself. I haven't tested it yet so please use with caution, but it's primarily copy-pasted from a mashup of gyroscope and accellerometer classes. Reviews and corrections are welcome. This weekend when we get the thing actually wired I'll post with any updates if needed. (this is the h file) Code:
#ifndef ANALOGRANGEFINDER_H |
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
First, you cannot put code like that in a header file. Header files are meant to declare variables and functions, not use them. You have to put all of the initialization and actual code in a .cpp file. Second, you can just set it up like this:
Code:
void GetDistance() |
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
Quote:
|
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
I chose to write this as a class to make it more standardized with other similar sensors (and so I could use it with a PID).
As for all in the h file, my attempt was to just have all of the operations compiled as inline for the sake of simplicity, however it may not be completely legal (my native language is C, so I'm a bit rusty in C++fu). I know you can do this with individual functions, however the whole class may cause issues. I'll upload it as a cpp and h file just to avoid the confusion/possibility of broke tomorrow. Thanks |
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
2 Attachment(s)
So, I made some fixes to the code, the primary change is that it now (properly) uses an inches/volt conversion factor instead of millivolts (which the analog channel is not providing).
Our range finder isn't fully working yet, but we think we're down to an issue with the frame of the robot being slightly within the cone of the audio pulse, and causing some erratic responses. If you end up using this code, please let me know :D (if nobody finds it helpful, I'll be alot less likely to make the effort to post this stuff in the future :rolleyes: ) Here's the C file for those who just want to peak: Code:
#include "AnalogRangeFinder.h" |
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
Quote:
|
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
Been using this code until the other day we hit the sensor against the bridge and that was the end of that. It worked fine before that.
|
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
Great :), sorry about your luck, you could try asking teams in your area (if there are any) for a loaner/spare.
I know we're really not using ours anymore, I found the potential for interference from robots (or the ball return under the hoop) to be too risky to use it. (the drivers also tend to have better luck eyeballing the shot than the pid's have at getting it right) |
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
Quote:
|
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)
It's been a while since I've looked at the sonar sensor, but if I remember right, near objects are not detected very accurately (if the echo returns quickly, it's likely interfering with itself as it emits the pulse).
We used ours from the key to detect how close the basket was. However, we found that the ball returns caused were being detected in competition rather than the backboard, and due to lack of time on the field to diagnose it, we just dropped the functionality. |
| All times are GMT -5. The time now is 09:47. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi