44 int error(
float encoderDistance,
45 int borderDetectorError,
50 checkObstacle(encoderDistance);
52 if (m_config.isDeactivate) {
53 return borderDetectorError;
57 return borderDetectorError;
60 return leftBorder - (64 - m_config.moveFromObstacle);
63 return rightBorder - (64 + m_config.moveFromObstacle);
73 return m_leftSensorValue;
83 return m_rightSensorValue;
93 return m_avoidingObstacle;
103 switch (m_avoidingObstacle) {
138 m_encoderDistanceStart = 0;
146 void updateSensorValue()
148 m_leftSensorValue = m_leftSensor.read_u16();
149 m_rightSensorValue = m_rightSensor.read_u16();
157 void checkObstacle(
float encoderDistance)
160 if (m_leftSensorValue < m_config.thresholdDistance
161 && m_rightSensorValue < m_config.thresholdDistance) {
164 if (m_leftSensorValue > m_config.thresholdDistance) {
169 m_encoderDistanceStart = encoderDistance;
171 if (m_encoderDistanceStart + m_config.encoderAvoidDistance < encoderDistance) {
177 AnalogIn m_leftSensor;
178 AnalogIn m_rightSensor;
182 int m_leftSensorValue = 0;
183 int m_rightSensorValue = 0;
184 float m_encoderDistanceStart = 0;
int avoidingObstacleInteger() const
Definition: ObstacleDetector.h:101
Config config() const
Definition: ObstacleDetector.h:117
int error(float encoderDistance, int borderDetectorError, int leftBorder, int rightBorder)
Definition: ObstacleDetector.h:44
bool isDeactivate
Definition: ObstacleDetector.h:15
float encoderAvoidDistance
Definition: ObstacleDetector.h:14
int thresholdDistance
Definition: ObstacleDetector.h:12
AvoidingObstacle avoidingObstacle() const
Definition: ObstacleDetector.h:91
Definition: BorderDetector.h:6
void setConfig(Config &config)
Definition: ObstacleDetector.h:127
ObstacleDetector(Config &config)
Definition: ObstacleDetector.h:29
int leftSensorValue() const
Definition: ObstacleDetector.h:71
void reset()
Definition: ObstacleDetector.h:136
Definition: ObstacleDetector.h:7
int rightSensorValue() const
Definition: ObstacleDetector.h:81
int moveFromObstacle
Definition: ObstacleDetector.h:13
AvoidingObstacle
Definition: ObstacleDetector.h:18
PinName rightSensorPin
Definition: ObstacleDetector.h:11
PinName leftSensorPin
Definition: ObstacleDetector.h:10
Definition: ObstacleDetector.h:9