![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Sources/USsensor.cpp@17:4e1be70bdedb, 2017-05-18 (annotated)
- Committer:
- beacon
- Date:
- Thu May 18 14:27:09 2017 +0000
- Revision:
- 17:4e1be70bdedb
Si compila.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beacon | 17:4e1be70bdedb | 1 | #include <Robot.h> |
beacon | 17:4e1be70bdedb | 2 | |
beacon | 17:4e1be70bdedb | 3 | USsensor::USsensor() |
beacon | 17:4e1be70bdedb | 4 | { |
beacon | 17:4e1be70bdedb | 5 | } |
beacon | 17:4e1be70bdedb | 6 | |
beacon | 17:4e1be70bdedb | 7 | USsensor::USsensor(Ultraschall* Usensor) |
beacon | 17:4e1be70bdedb | 8 | { |
beacon | 17:4e1be70bdedb | 9 | init(Usensor); |
beacon | 17:4e1be70bdedb | 10 | } |
beacon | 17:4e1be70bdedb | 11 | void USsensor::init(Ultraschall* Usensor) |
beacon | 17:4e1be70bdedb | 12 | { |
beacon | 17:4e1be70bdedb | 13 | this->Usensor = Usensor; |
beacon | 17:4e1be70bdedb | 14 | } |
beacon | 17:4e1be70bdedb | 15 | |
beacon | 17:4e1be70bdedb | 16 | float USsensor::read() |
beacon | 17:4e1be70bdedb | 17 | { |
beacon | 17:4e1be70bdedb | 18 | static int i = 0; |
beacon | 17:4e1be70bdedb | 19 | Usensor->start(); |
beacon | 17:4e1be70bdedb | 20 | if( i ){ |
beacon | 17:4e1be70bdedb | 21 | float dist = Usensor->get_dist_cm(); |
beacon | 17:4e1be70bdedb | 22 | static float distFiltered = dist; |
beacon | 17:4e1be70bdedb | 23 | |
beacon | 17:4e1be70bdedb | 24 | distFiltered = 0.05f * distFiltered + 0.95f * dist; |
beacon | 17:4e1be70bdedb | 25 | return distFiltered / 100; |
beacon | 17:4e1be70bdedb | 26 | //return dist/100.0f; |
beacon | 17:4e1be70bdedb | 27 | } |
beacon | 17:4e1be70bdedb | 28 | else{ |
beacon | 17:4e1be70bdedb | 29 | i++; |
beacon | 17:4e1be70bdedb | 30 | return 0.25f; |
beacon | 17:4e1be70bdedb | 31 | } |
beacon | 17:4e1be70bdedb | 32 | } |
beacon | 17:4e1be70bdedb | 33 | |
beacon | 17:4e1be70bdedb | 34 | USsensor::operator float() |
beacon | 17:4e1be70bdedb | 35 | { |
beacon | 17:4e1be70bdedb | 36 | return read(); |
beacon | 17:4e1be70bdedb | 37 | } |