ROBOTC.net forums
http://robotc.net/forums/

Line counting problem
http://robotc.net/forums/viewtopic.php?f=1&t=19561
Page 1 of 1

Author:  Korndog [ Wed Apr 19, 2017 2:57 pm ]
Post subject:  Line counting problem

We are trying to count 13 lines on a table. Robots must make a turn to continue the counting process. Everything is working okay until it makes the left turn and then it will reads one line, instead of two, and jumps to the next piece of code. I'd like for someone else to take a look and give us some advise on what it wrong.
Thank you.




#pragma config(Sensor, S1, Light, sensorLightActive)
#pragma config(Sensor, S4, Touch, sensorTouch)
#pragma config(Motor, motorA, , tmotorNXT, openLoop, encoder)
#pragma config(Motor, motorB, B, tmotorNXT, openLoop, encoder)
#pragma config(Motor, motorC, C, tmotorNXT, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
int lightValue;
int darkValue;
int sumValue;
int thresholdValue;
int countValue = 0;
int lastseen;

nMotorPIDSpeedCtrl[C] = mtrSpeedReg;
nMotorPIDSpeedCtrl[B] = mtrSpeedReg;

while (SensorValue(Touch)==0)
{
nxtDisplayBigStringAt(0, 31, "LIGHTNESS"); // tell to read
}

lightValue=SensorValue(Light);

wait1Msec(1000);

while (SensorValue(Touch)==0)
{
nxtDisplayBigStringAt(0, 31, "DARKNESS"); // tell to read
}
darkValue=SensorValue(Light);

wait1Msec(1000);

sumValue= lightValue + darkValue;
thresholdValue = sumValue/2;

ClearTimer(T1); // clear timer
while(time1[T1]<10000)
{
lastseen = 1;

while(countValue <6) // how many lines to count
{
if (SensorValue(Light) < thresholdValue) // find threshold
{

motor[B] = 50;
motor[C] = 50;

if (lastseen == 1)
{
countValue = countValue + 1; // conting line
lastseen = 0;
}
}
else
{
lastseen = 1;
}

}

motor[C] = 40;
motor[B] = 40; // forward
wait1Msec(800);

motor[C] = -40;
motor[B] = 40; // Turn left
wait1Msec(375);

motor[C] = 0;
motor[B] = 0;
wait1Msec(500);

while(countValue < 2) // how many lines to count
{
if (SensorValue(Light) < thresholdValue) // find threshold
{

motor[B] = 50;
motor[C] = 50;

if (lastseen == 1)
{
countValue = countValue + 1; // conting line
lastseen = 0;
}
}
else
{
lastseen = 1;
}

}

motor[C] = 40;
motor[B] = 40; // forward
wait1Msec(800);

motor[C] = -40;
motor[B] = 40; // Turn left
wait1Msec(400);

motor[C] = 0;
motor[B] = 0;
wait1Msec(500);
}
}

Author:  CARBOT [ Fri Apr 21, 2017 12:10 pm ]
Post subject:  Re: Line counting problem

You have a while loop using the variable countValue for each section to count. You increment the variable in the first count. You either need to reset the variable countValue for the second count or make the second while the sum of the first two counts.
Good Luck.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/