View unanswered posts | View active topics It is currently Mon Oct 22, 2018 8:39 pm






Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
RobotC Programming 
Author Message
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post RobotC Programming
Hi i have been trying to program for our project and whenever i fix it, it just pulls up something different wrong about it
so here is what i have


#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
turnFlashlightOff(buzz1);

turnFlashlightOn(Flashlight1, 127); //Turns Flashlight1 on
turnFlashlightOn(Flashlight2, 127); //Turns Flashlight2 on

wait(1);
}
while (1 == 1)

{
if(SensorValue[Sensor2] >= 120)

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}
{
else;
if(SensorValue[Sensor1] >= 120);

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);


Mon Jan 05, 2015 3:50 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: RobotC Programming
Code:
task main()
{
turnFlashlightOff(buzz1);

turnFlashlightOn(Flashlight1, 127); //Turns Flashlight1 on
turnFlashlightOn(Flashlight2, 127); //Turns Flashlight2 on

wait(1);
}


As far as the compiler is concerned, this is the entirety of the program (notice the opening and closing curly braces; anything outside of this is not considered a part of task main). Since task main was closed early with the closing curly brace, all of the code below it will not compile correctly.

Try moving the rest of the code inside of task main's closing brace }, and this should resolve the majority of the issues you are encountering.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon Jan 05, 2015 5:30 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: RobotC Programming
What he said ^^. :D Plus, once you get all of your code inside of task main, you'll still have some other issues. I'll point out the ones I see in your code
Code:

#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
   turnFlashlightOff(buzz1);

   turnFlashlightOn(Flashlight1, 127); //Turns Flashlight1 on
   turnFlashlightOn(Flashlight2, 127); //Turns Flashlight2 on

   wait(1);
} // <- As JohnWatson said, task main ends here. This curly brace needs to be at the end of all of your code.
while (1 == 1) // <- This is an infinite loop. Once your code gets to here, it will not execute anything except what is inside the loop.

{
   if(SensorValue[Sensor2] >= 120)

   waitInMilliseconds(5);

   clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
   waitInMilliseconds(5);
   turnFlashlightOn(buzz1, 127);
   wait(10);
   turnFlashlightOff(buzz1);
}
{ // <- This bracket is in the wrong place. It needs to go below the else.
   else; // <- There shouldn't be a semicolon here...
   if(SensorValue[Sensor1] >= 120); // <- ...or here

   waitInMilliseconds(5);

   clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
   waitInMilliseconds(5);
   turnFlashlightOn(buzz1, 127);
   wait(10);
   turnFlashlightOff(buzz1);
// <- You're missing a closing curly brace for the if statement.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Mon Jan 05, 2015 5:46 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
it gave this me after that

**Error**:Executable statements not valid in 'main' declaration block
**Error**:Executable statements not valid in 'main' declaration block
**Error**:Duplicate definition for task 'main'.
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected ';' during parsing
*Warning*:';' found following 'if' statement. Is this intentional?
**Error**:Ummatched left brace '{'
**Error**:Expected->'}'. Found 'EOF'
**Error**:Executable statements not valid in 'main' declaration block


Last edited by kewlguy535 on Tue Jan 06, 2015 3:03 pm, edited 1 time in total.



Tue Jan 06, 2015 2:47 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: RobotC Programming
I guess maybe I didn't make my last post clear. If you look at the version of your code that I posted above, there are comments in it that point out where various errors are likely to occur. The things I point out there seem to match up with the errors you posted. But, if you make those changes and are still getting errors, feel free to post up your modified code for us to take a look at. :bigthumb:

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Jan 06, 2015 2:55 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
i have fixed or seemed to fix what you told me and this is what i have

#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
turnFlashlightOff(buzz1);

turnFlashlightOn(Flashlight1, 127);
turnFlashlightOn(Flashlight2, 127);

wait(1);
}
while (1 == 1) //
{
if(SensorValue[Sensor2] >= 120)

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}

else
{
if(SensorValue[Sensor1] >= 120)

waitInMilliseconds(5);

clearTimer(T1);

if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);


Tue Jan 06, 2015 3:05 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: RobotC Programming
You fixed most of it, it looks like, but you still have just a couple errors with you curly braces
Code:
task main()
{
 turnFlashlightOff(buzz1);

 turnFlashlightOn(Flashlight1, 127);
 turnFlashlightOn(Flashlight2, 127);

 wait(1);
// } ends task main. It needs to be at the end of the program
while (1 == 1) //
{
 if(SensorValue[Sensor2] >= 120)

 waitInMilliseconds(5);

 clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
 waitInMilliseconds(5);
 turnFlashlightOn(buzz1, 127);
 wait(10);
 turnFlashlightOff(buzz1);
}

else
{
   if(SensorValue[Sensor1] >= 120)

 waitInMilliseconds(5);

 clearTimer(T1);

if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
 waitInMilliseconds(5);
 turnFlashlightOn(buzz1, 127);
 wait(10);
 turnFlashlightOff(buzz1);
} // Closing brace missing for above if statement
} // Closing brace missing for else statement
} // task main curly brace moved to here

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Jan 06, 2015 11:05 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: RobotC Programming
BurningLights wrote:
You fixed most of it, it looks like, but you still have just a couple errors with you curly braces


BurningLights is correct, and this is a very common issue that both new and experienced programmers run into. The absolute best way to resolve this issue long term is to make sure that you follow a set, clean programming practice.

For instance, when I make a control structure that has a condition and a set of curly braces, I always type in the structure keyword (such as 'if' or 'while'), then a set of empty parentheses, then a set of curly braces on the following lines. I also make sure they are indented properly so they are easier to see and so they don't get cluttered into the rest of the program.

By forcing myself to write out the control structure's framework before I start filling in the actual code, I ensure that I don't accidentally miss any parts or pieces (or risk losing a curly brace somewhere).

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Wed Jan 07, 2015 10:55 am
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
Thanks everyone Ilol let you know if it worked in about an hour


Wed Jan 07, 2015 2:00 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
so this is what you told me do do and i fixed it i think!!

#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
turnFlashlightOff(flashlightport);
turnFlashlightOn(Flashlight1, 127);
turnFlashlightOn(Flashlight2, 127);

wait(1);

while (1 == 1) //

if(SensorValue[Sensor2] >= 120)

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}

else
{
if(SensorValue[Sensor1] >= 120)

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}


Wed Jan 07, 2015 2:51 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
and these are the errors it gave me

**Error**:Undefined variable 'flashlightport'. 'short' assumed.
**Error**:Ummatched left brace '{'
**Error**:Expected->'}'. Found 'EOF'
**Error**:Executable statements not valid in 'main' declaration block


Wed Jan 07, 2015 2:51 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
Im sorry if im not seeing what your telling me in new to this and our teacher didnt really teach us what we are doing or how to do it


Wed Jan 07, 2015 2:57 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: RobotC Programming
As to the flashilight error, you named your two flashlight motors Flashlight1 and Flashlight 2. But then you call turnFlashlightOff using flashlightport - which doesn't exist in your program. So, you need to call turnFlashlightOff using either Flashlight1 or Flashlight2.

As for your other errors, your main task is still being closed early. I've marked the spot where it ends below. In your program, all of your code needs to be inside of task main. And I do have one question. What is supposed to be inside your while (1 == 1) infinite loop? Because anything that comes after an infinite loop will not get executed because the program will never leave the infinite loop. And as a quick tip to help you with John Watson said, ROBOTC has this handy code formatting button with a picture of a magic wand on it. That will fix your indentation and help you to see where your sections marked off by curly braces start and end, and also what code is inside things like if statements and loops.
Code:
#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
 turnFlashlightOff(flashlightport);
 turnFlashlightOn(Flashlight1, 127);
 turnFlashlightOn(Flashlight2, 127);

 wait(1);

while (1 == 1) //

 if(SensorValue[Sensor2] >= 120)

 waitInMilliseconds(5);

 clearTimer(T1);
} // <- task main ends here
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
 waitInMilliseconds(5);
 turnFlashlightOn(buzz1, 127);
 wait(10);
 turnFlashlightOff(buzz1);
}

else
{
 if(SensorValue[Sensor1] >= 120)

 waitInMilliseconds(5);

 clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
 waitInMilliseconds(5);
 turnFlashlightOn(buzz1, 127);
 wait(10);
 turnFlashlightOff(buzz1);
}

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Thu Jan 08, 2015 9:45 am
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
What is the Buzzelight


Thu Jan 08, 2015 3:02 pm
Profile
Rookie

Joined: Mon Jan 05, 2015 3:46 pm
Posts: 10
Post Re: RobotC Programming
This is what i have and its still telling me the same thing

#pragma config(Sensor, in1, Sensor1, sensorReflection)
#pragma config(Sensor, in2, Sensor2, sensorReflection)
#pragma config(Sensor, in3, Sensor3, sensorReflection)
#pragma config(Sensor, in4, Sensor4, sensorLineFollower)
#pragma config(Sensor, in5, Sensor5, sensorReflection)
#pragma config(Sensor, in6, Sensor6, sensorReflection)
#pragma config(Sensor, in7, Sensor7, sensorReflection)
#pragma config(Sensor, in8, Sensor8, sensorReflection)
#pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut)
#pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port8, Flashlight2, tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
Project Title: Smart Goal
Team Members: Jordon Hayes, Bryce Menzer, Katie Otsuka, Calvin Nguyen
Date: December 19, 2014
Section:


Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between
human and ball.


Pseudocode:

*/

task main()
{
turnFlashlightOff(Flashlight1);
turnFlashlightOn(Flashlight1, 127);
turnFlashlightOn(Flashlight2, 127);

wait(1);

while (1 == 1) //

if(SensorValue[Sensor2] >= 120)

waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}

else

if(SensorValue[Sensor1] >= 120)
{
waitInMilliseconds(5);

clearTimer(T1);
}
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5)
{
waitInMilliseconds(5);
turnFlashlightOn(buzz1, 127);
wait(10);
turnFlashlightOff(buzz1);
}


Thu Jan 08, 2015 3:20 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


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.