track white lines better
This commit is contained in:
parent
b50d69a2ae
commit
95f85e8e07
3 changed files with 22 additions and 4 deletions
|
@ -23,7 +23,12 @@ float LineSensor::AverageReflectance(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LineSensor::LineDetected() {
|
bool LineSensor::LineDetected() {
|
||||||
|
#ifdef DARK
|
||||||
return AverageReflectance() > LINE_THRESHOLD;
|
return AverageReflectance() > LINE_THRESHOLD;
|
||||||
|
#endif
|
||||||
|
#ifndef DARK
|
||||||
|
return AverageReflectance() < 200;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float LineSensor::CalcError(void)
|
float LineSensor::CalcError(void)
|
||||||
|
@ -32,6 +37,9 @@ float LineSensor::CalcError(void)
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
for (int i = 0; i<sensorCount; i++) {
|
for (int i = 0; i<sensorCount; i++) {
|
||||||
int ret = analogRead(sensors[i]);
|
int ret = analogRead(sensors[i]);
|
||||||
|
#ifndef DARK
|
||||||
|
ret = 1000 - ret;
|
||||||
|
#endif
|
||||||
sum_pos += ret * (i+1);
|
sum_pos += ret * (i+1);
|
||||||
sum += ret;
|
sum += ret;
|
||||||
#ifdef __TRACK_DEBUG__
|
#ifdef __TRACK_DEBUG__
|
||||||
|
@ -41,6 +49,8 @@ float LineSensor::CalcError(void)
|
||||||
}
|
}
|
||||||
float pos = sum_pos / sum;
|
float pos = sum_pos / sum;
|
||||||
#ifdef __TRACK_DEBUG__
|
#ifdef __TRACK_DEBUG__
|
||||||
|
Serial.print(AverageReflectance());
|
||||||
|
Serial.print(" ");
|
||||||
Serial.println(pos);
|
Serial.println(pos);
|
||||||
#endif
|
#endif
|
||||||
return pos;
|
return pos;
|
||||||
|
@ -49,5 +59,10 @@ float LineSensor::CalcError(void)
|
||||||
|
|
||||||
bool LineSensor::CheckIntersection(void)
|
bool LineSensor::CheckIntersection(void)
|
||||||
{
|
{
|
||||||
|
#ifdef DARK
|
||||||
return AverageReflectance() > INTERSECTION_THRESHOLD;
|
return AverageReflectance() > INTERSECTION_THRESHOLD;
|
||||||
|
#endif
|
||||||
|
#ifndef DARK
|
||||||
|
return AverageReflectance() < 100;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define FIRST_LINE_SENSOR A0
|
|
||||||
|
|
||||||
class LineSensor
|
class LineSensor
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const static uint8_t sensorCount = 6;
|
const static uint8_t sensorCount = 6;
|
||||||
const byte sensors[sensorCount] = {A0,A7,A2,A3,A4,A6};
|
const byte sensors[sensorCount] = {A0,A11,A2,A3,A4,A6};
|
||||||
|
|
||||||
bool prevOnIntersection = false;
|
bool prevOnIntersection = false;
|
||||||
|
|
||||||
|
public:
|
||||||
float AverageReflectance();
|
float AverageReflectance();
|
||||||
|
|
||||||
public:
|
|
||||||
LineSensor(void) {}
|
LineSensor(void) {}
|
||||||
void Initialize(void);
|
void Initialize(void);
|
||||||
float CalcError(void); // varies between 1 and 6
|
float CalcError(void); // varies between 1 and 6
|
||||||
|
|
|
@ -135,7 +135,12 @@ void Robot::LineFollowingUpdate(void)
|
||||||
{
|
{
|
||||||
if(robotState == ROBOT_LINING)
|
if(robotState == ROBOT_LINING)
|
||||||
{
|
{
|
||||||
|
#ifdef DARK
|
||||||
float setpoint = rollingTurnRate > 0.1 ? 4 : 3;
|
float setpoint = rollingTurnRate > 0.1 ? 4 : 3;
|
||||||
|
#endif
|
||||||
|
#ifndef DARK
|
||||||
|
float setpoint = 3.5;
|
||||||
|
#endif
|
||||||
|
|
||||||
float lineError = setpoint - lineSensor.CalcError();
|
float lineError = setpoint - lineSensor.CalcError();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue