Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo ServoArm mbed
Fork of PES_PIXY_Official by
Sources/USsensor.cpp@0:15a8480061e8, 2017-05-22 (annotated)
- Committer:
- beacon
- Date:
- Mon May 22 11:24:46 2017 +0000
- Revision:
- 0:15a8480061e8
o
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| beacon | 0:15a8480061e8 | 1 | #include <Robot.h> |
| beacon | 0:15a8480061e8 | 2 | |
| beacon | 0:15a8480061e8 | 3 | USsensor::USsensor() |
| beacon | 0:15a8480061e8 | 4 | { |
| beacon | 0:15a8480061e8 | 5 | } |
| beacon | 0:15a8480061e8 | 6 | |
| beacon | 0:15a8480061e8 | 7 | USsensor::USsensor(Ultraschall* Usensor) |
| beacon | 0:15a8480061e8 | 8 | { |
| beacon | 0:15a8480061e8 | 9 | init(Usensor); |
| beacon | 0:15a8480061e8 | 10 | } |
| beacon | 0:15a8480061e8 | 11 | void USsensor::init(Ultraschall* Usensor) |
| beacon | 0:15a8480061e8 | 12 | { |
| beacon | 0:15a8480061e8 | 13 | this->Usensor = Usensor; |
| beacon | 0:15a8480061e8 | 14 | } |
| beacon | 0:15a8480061e8 | 15 | |
| beacon | 0:15a8480061e8 | 16 | float USsensor::read() |
| beacon | 0:15a8480061e8 | 17 | { |
| beacon | 0:15a8480061e8 | 18 | static int i = 0; |
| beacon | 0:15a8480061e8 | 19 | Usensor->start(); |
| beacon | 0:15a8480061e8 | 20 | if( i ){ |
| beacon | 0:15a8480061e8 | 21 | float dist = Usensor->get_dist_cm(); |
| beacon | 0:15a8480061e8 | 22 | static float distFiltered = dist; |
| beacon | 0:15a8480061e8 | 23 | |
| beacon | 0:15a8480061e8 | 24 | distFiltered = 0.05f * distFiltered + 0.95f * dist; |
| beacon | 0:15a8480061e8 | 25 | return distFiltered / 100; |
| beacon | 0:15a8480061e8 | 26 | //return dist/100.0f; |
| beacon | 0:15a8480061e8 | 27 | } |
| beacon | 0:15a8480061e8 | 28 | else{ |
| beacon | 0:15a8480061e8 | 29 | i++; |
| beacon | 0:15a8480061e8 | 30 | return 0.25f; |
| beacon | 0:15a8480061e8 | 31 | } |
| beacon | 0:15a8480061e8 | 32 | } |
| beacon | 0:15a8480061e8 | 33 | |
| beacon | 0:15a8480061e8 | 34 | USsensor::operator float() |
| beacon | 0:15a8480061e8 | 35 | { |
| beacon | 0:15a8480061e8 | 36 | return read(); |
| beacon | 0:15a8480061e8 | 37 | } |
