View unanswered posts | View active topics It is currently Fri Jul 25, 2014 8:06 am






Reply to topic  [ 5 posts ] 
Help With Robo Line Counter Challenge? 
Author Message
Rookie

Joined: Thu Nov 07, 2013 7:22 pm
Posts: 4
Post Help With Robo Line Counter Challenge?
Hello,

I have been trying to complete a program for the Line Counter challenge for my class but my program seems to have many errors in it. I have tried many times to correct them but it doesn't seem to work. D: What am I doing wrong? Here is my code:

#pragma config(Sensor, S1, touchSensor, sensorTouch)
#pragma config(Sensor, S2, lightSensor, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int lightValue;
int darkValue;
int sumValue;
int thresholdValue;
int countValue = 0;
int lastSeen;
int numLines

task main()
{
void forwardlines(int numLines)
{
lastSeen = 1;
countValue = 0;
while(SensorValue(touchSensor) == 0)
{
nxtDisplayStringAt(0,31,"Read Light Now");
}

lightValue = SensorValue(lightSensor);

wait1Msec(1000);

while(SensorValue(touchSensor) == 0)
{
nxtDisplayStringAt(0,31,"Read Dark Now");
}

darkValue = SensorValue(lightSensor);

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

ClearTimer(T1);
lastSeen = 1;

void forwardlines(int numLines)
{

while(countValue < numLines)
{

if(SensorValue(lightSensor) < thresholdValue)
{

motor[motorC] = 50;
motor[motorB] = 50;

if(lastSeen == 1)
{

motor[motorC] = -50;
motor[motorB] = -50;
wait1Msec(1500);
countValue = countValue + 1;
lastSeen = 0;

}

else
{
motor[motorC]= 50;
motor[motorB]= 50;
lastSeen = 1;
}
}
}
void reverse(int numLines)
{
lastSeen = 1;
countValue = 0;

while(countValue < numLines)
{
if (SensorValue(lightSensor) < thresholdValue)
{
motor[motorC]= -50;
motor[motorB]= -50;

if(lastSeen == 1)
{
countValue = countValue + 1;
lastSeen = 0;
}
}

else
{
motor[motorC]= -50;
motor[motorB]= -50;
lastSeen = 1;
}
}
}
}

task main()
{
forwardlines(2);
reverse(2);
forwardlines(3);
reverse(3);
forwardlines(4);
reverse(4);
forwardlines(5);
reverse(5);
forwardlines(6);
reverse(6);
}


}

Thanks!
Yoloballer#


Attachments:
File comment: Please help me! I am stuck!
linecounter.c [1.82 KiB]
Downloaded 85 times
Thu Nov 07, 2013 7:26 pm
Profile
Rookie

Joined: Thu May 02, 2013 10:52 am
Posts: 22
Post Re: Help With Robo Line Counter Challenge?
So the first error is:
**Error**: Expected ';'. Found 'task'
Here is the code:
Code:
int numLines

task main()

That is telling you that you missed a semicolon. So change:
int numLines
to
int numLines;

**Error**: Unmatched left brace '{'
That is saying that you have one too few close (or right) braces (}). We will fix that in a bit.

Then all of the:
**Error** :Function must be defined at main scope level
That is telling you that your functions should not be defined within task main. They should be like this:
Code:
void FunctionA(int Value)
{
   ...code...
}

task main(()
{
  ...code...
}


Then if we correct for the problems thus far, task main looks like this:
Code:
task main()
{
  task main()
  {
    forwardlines(2);
    reverse(2);
    forwardlines(3);
    reverse(3);
    forwardlines(4);
    reverse(4);
    forwardlines(5);
    reverse(5);
    forwardlines(6);
    reverse(6);
  }
}

That is what all of those errors on line 101 are about, you only need one task main.

Here is the code all corrected up so far:
Code:
#pragma config(Sensor, S1, touchSensor, sensorTouch)
#pragma config(Sensor, S2, lightSensor, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int lightValue;
int darkValue;
int sumValue;
int thresholdValue;
int countValue = 0;
int lastSeen;
int numLines;

void forwardlines(int numLines)
{
  lastSeen = 1;
  countValue = 0;
  while(SensorValue(touchSensor) == 0)
  {
    nxtDisplayStringAt(0,31,"Read Light Now");
  }

  lightValue = SensorValue(lightSensor);

  wait1Msec(1000);

  while(SensorValue(touchSensor) == 0)
  {
    nxtDisplayStringAt(0,31,"Read Dark Now");
  }

  darkValue = SensorValue(lightSensor);

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

  ClearTimer(T1);
  lastSeen = 1;
}

void forwardlines(int numLines)
{
  while(countValue < numLines)
  {
    if(SensorValue(lightSensor) < thresholdValue)
    {
      motor[motorC] = 50;
      motor[motorB] = 50;

      if(lastSeen == 1)
      {
        motor[motorC] = -50;
        motor[motorB] = -50;
        wait1Msec(1500);
        countValue = countValue + 1;
        lastSeen = 0;
      }
      else
      {
        motor[motorC]= 50;
        motor[motorB]= 50;
        lastSeen = 1;
      }
    }
  }
}

void reverse(int numLines)
{
  lastSeen = 1;
  countValue = 0;

  while(countValue < numLines)
  {
    if (SensorValue(lightSensor) < thresholdValue)
    {
      motor[motorC]= -50;
      motor[motorB]= -50;

      if(lastSeen == 1)
      {
        countValue = countValue + 1;
        lastSeen = 0;
      }
    }

    else
    {
      motor[motorC]= -50;
      motor[motorB]= -50;
      lastSeen = 1;
    }
  }
}


task main()
{
  forwardlines(2);
  reverse(2);
  forwardlines(3);
  reverse(3);
  forwardlines(4);
  reverse(4);
  forwardlines(5);
  reverse(5);
  forwardlines(6);
  reverse(6);
}


But if you notice you have two "void forwardlines(int numLines)", with different code inside of them. So either delete the one, or change the name of one so they are not the same. But then you also have a global variable called "int numLines", there is also an argument (that value you pass to a function) called that, so I don't know which it will take the value from when you read it. The global variable is not being used so it could be deleted, unless their is something else I am missing.

Another thing is that "thresholdValue" is never set to a value.

That should get the code to compile, but I don't know about the code itself.
Hope this helps.

_________________
What is easy you have done, what is hard you can do, what is impossible will take a little longer


Fri Nov 08, 2013 12:14 pm
Profile
Rookie

Joined: Thu Nov 07, 2013 7:22 pm
Posts: 4
Post Re: Help With Robo Line Counter Challenge?
Wow! :bigthumb: Thank you for helping me out, however I am still having issue with two parts of the program. On the first part of the program it says that the "int numLines is unreferenced. What does the program mean by that? Also how do you suppose I fix the two task main problem or how to combine them, I really appreciated your help.

Thanks!
:mrgreen: :D :)


Fri Nov 08, 2013 2:53 pm
Profile
Rookie

Joined: Thu May 02, 2013 10:52 am
Posts: 22
Post Re: Help With Robo Line Counter Challenge?
**info***: Unreferenced variable 'NumLines'
Is saying that that variable is unused, so it can be deleted.

As I showed in the last bit of code in my last post, the only thing that should be in task main is the program that the robot runs, the functions definitions (void function(int value) { code } ) should not be in there.

Here is a rough outline of one way it can be done:
Code:
//Motors and Sensor setup
#pragma config(Sensor, S1, touchSensor, sensorTouch)
...

//Global Variables
int Value = 9;

//function definitions
void Function(int Number)
{
   code
}

// then task main
task main()
{
   Function(Value);
}


Or another way (I prefer to do it this way over the last for small-medium size programs, but I don't know if one way is absolutely better than the other, this way just makes it easier to quickly find task main):
Code:
//Motors and Sensor setup
#pragma config(Sensor, S1, touchSensor, sensorTouch)
...

//Global Variables
int Value = 9;

//function declarations (these tell the program that these functions do exist somewhere in this code)
void Function(int Number);
void FunctionB(int Number);
void FunctionC(int Number);

// then task main
task main()
{
   Function(Value);
}

//function definitions
void Function(int Number)
{
   code
}

void FunctionB(int Number)
{
   code
}

void FunctionC(int Number)
{
   code
}

_________________
What is easy you have done, what is hard you can do, what is impossible will take a little longer


Fri Nov 08, 2013 5:13 pm
Profile
Rookie

Joined: Thu Nov 07, 2013 7:22 pm
Posts: 4
Post Re: Help With Robo Line Counter Challenge?
Thanks!


Tue Nov 12, 2013 9:03 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: parkway 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.