三浦 颯太 / Mbed 2 deprecated AutoMaster2019_B_2

Dependencies:   mbed TrapezoidControl QEI Pulse LM61CIZ

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USS.cpp Source File

USS.cpp

00001 #include "USS.h"
00002 #include "mbed.h"
00003 
00004 USS::USS(PinName echoPin, PinName trigPin, PinName tempPin) 
00005                         :echo_(echoPin), trig_(trigPin), temp_(tempPin)  
00006 {
00007     distance_ = 0;
00008     
00009 }
00010 
00011 double USS::ReadDis(void) {
00012     int temp = temp_.getTemperature();
00013     double duration = echo_.read_high_us(5000);
00014     trig_.write_us(1,10);
00015     if(duration > 0){
00016         duration /= 2;
00017         double sspead = 331.5+0.6*temp;
00018         distance_ = duration*sspead*100/1000000;
00019     } else distance_ = 0;
00020     return distance_;
00021 }
00022 
00023 double USS::GetDis(void) {
00024     return distance_;
00025 }