![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Diff: Sources/USsensor.cpp
- Revision:
- 17:4e1be70bdedb
diff -r 915f8839fe48 -r 4e1be70bdedb Sources/USsensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/USsensor.cpp Thu May 18 14:27:09 2017 +0000 @@ -0,0 +1,37 @@ +#include <Robot.h> + +USsensor::USsensor() +{ +} + +USsensor::USsensor(Ultraschall* Usensor) +{ + init(Usensor); +} +void USsensor::init(Ultraschall* Usensor) +{ + this->Usensor = Usensor; +} + +float USsensor::read() +{ + static int i = 0; + Usensor->start(); + if( i ){ + float dist = Usensor->get_dist_cm(); + static float distFiltered = dist; + + distFiltered = 0.05f * distFiltered + 0.95f * dist; + return distFiltered / 100; + //return dist/100.0f; + } + else{ + i++; + return 0.25f; + } +} + + USsensor::operator float() +{ + return read(); +} \ No newline at end of file