ETrobocon2017 - 片山研究所モデルベース開発推進事業部
SonarAlert.cpp
[詳解]
1 #include "SonarAlert.h"
2 
3 SonarAlert::SonarAlert( int secPerCycle )
4 {
5  timeCounter = 0;
6  sonarSensor = new SonarSensor( PORT_2 );
7  this->secPerCycle = secPerCycle;
8 }
9 
10 // Testコード用
11 SonarAlert::SonarAlert( int distanceBorder, int secPerCycle, SonarSensor& sensor):
12  SONAR_ALERT_DISTANCE( distanceBorder )
13 {
14  timeCounter = 0;
15  sonarSensor = &sensor;
16  this->secPerCycle = secPerCycle;
17 }
18 
20 {
21  // delete sonarSensor;
22 }
23 
31 {
32  timeCounter++;
33  int alert = 0;
34 
35  if( timeCounter == 40/secPerCycle )
36  {
37  if( sonarSensor->getDistance() <= SONAR_ALERT_DISTANCE
38  && 0 <= sonarSensor->getDistance() )
39  {
40  alert = 1;
41  }
42  else
43  {
44  alert = 0;
45  }
46  timeCounter = 0;
47  }
48 
49  return alert;
50 }
SonarAlert(int)
Definition: SonarAlert.cpp:3
int detectBarrier()
Definition: SonarAlert.cpp:30
Definition: Port.h:21
int16_t getDistance(void) const
Definition: SonarSensor.cpp:29