/* * Copyright (c) 2021, Erich Styger * * SPDX-License-Identifier: BSD-3-Clause */ #include "platform.h" #if PL_CONFIG_USE_LINE_SENSOR #include "LineHistory.h" #include "Reflectance.h" #define HISTORY_MIN_SENSOR_VAL REF_MIN_LINE_VAL /* minimum threshold value which is recorded in history */ static uint16_t SensorHistory[REF_NOF_SENSORS]; /* value of history while moving forward */ void HISTORY_SampleSensors(void) { uint8_t i; uint16_t val[REF_NOF_SENSORS]; REF_GetSensorValues(&val[0], REF_NOF_SENSORS); for(i=0; i=HISTORY_MIN_SENSOR_VAL) { /* only count line values */ if (val[i]>SensorHistory[i]) { SensorHistory[i] = val[i]; } } } } /*! * \brief Can be called during turning, will use it to sample sensor values. */ bool HISTORY_SampleTurnStopFunction(void) { HISTORY_SampleSensors(); return FALSE; /* do not stop turning */ } REF_LineKind HISTORY_LineKind(void) { int i, cnt, cntLeft, cntRight; cnt = cntLeft = cntRight = 0; for(i=0;i=HISTORY_MIN_SENSOR_VAL) { /* count above threshold values */ cnt++; #if REF_SENSOR1_IS_LEFT if (i=HISTORY_MIN_SENSOR_VAL) { return REF_LINE_LEFT; } else { /* must be cntRight>cntLeft */ return REF_LINE_RIGHT; } } void HISTORY_Clear(void) { int i; for(i=0;i