in src/app.cpp [224:255]
static int sonar_alert(void)
{
static unsigned int counter = 0;
static int alert = 0;
signed int distance;
char msg[32];
if (++counter == 40/4) /* 約40msec周期毎に障害物検知 */
{
/*
* 超音波センサによる距離測定周期は、超音波の減衰特性に依存します。
* NXTの場合は、40msec周期程度が経験上の最短測定周期です。
* EV3の場合は、要確認
*/
distance = ev3_ultrasonic_sensor_get_distance(sonar_sensor);
sprintf(msg, "Soner: %d", distance);
//msg_f(msg, 2);
if ((distance <= SONAR_ALERT_DISTANCE) && (distance >= 0))
{
alert = 1; /* 障害物を検知 */
}
else
{
alert = 0; /* 障害物無し */
}
counter = 0;
}
return alert;
}