View unanswered posts | View active topics It is currently Sun Jun 25, 2017 4:43 pm






Reply to topic  [ 2 posts ] 
Line counting problem 
Author Message
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 32
Post 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);
}
}


Wed Apr 19, 2017 2:57 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 150
Post 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.


Fri Apr 21, 2017 12:10 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.