View unanswered posts | View active topics It is currently Thu Jul 31, 2014 8:07 am






Reply to topic  [ 3 posts ] 
First Time Programming, don't understand template 
Author Message
Rookie

Joined: Wed Jan 09, 2013 5:26 pm
Posts: 9
Post First Time Programming, don't understand template
This is my first year as head programmer for my school's team, I shadowed under someone last year but we didn't have to use autonomous in our game, this year we do. I've tried using the template but I keep getting an error message saying "Executable statements not valid in 'main' declaration block" for my user controlled portion. Can anyone help explain what i'm doing wrong? Here's my code.

#pragma config(Sensor, in1, LeftLight, sensorReflection)
#pragma config(Sensor, in2, RightLight, sensorReflection)
#pragma config(Sensor, dgtl1, SONAR, sensorSONAR_inch)
#pragma config(Motor, port2, BackLeft, tmotorVex393, openLoop)
#pragma config(Motor, port3, BackRight, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port4, FrontLeft, tmotorVex393, openLoop)
#pragma config(Motor, port5, FrontRight, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port7, Pushers, tmotorServoStandard, openLoop)
#pragma config(Motor, port8, GarageDoor, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port9, TheCannon, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(105)

#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!

int pushstate = 0;
bool latch = false;
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;


// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}

/////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
// .....................................................................................
// Insert user code here.
// .....................................................................................

if(SensorValue[SONAR] <= 3)
{
motor[BackLeft] = 0;
motor[BackRight] = 0;
motor[FrontLeft] = 0;
motor[FrontRight] = 0;
if(SensorValue[RightLight] <= 100)
{
motor[Pushers] = 127;
wait10Msec(100);
}
if(SensorValue[LeftLight] <= 100)
{
motor[Pushers] = -127;
wait10Msec(100);
}
else
{
motor[BackLeft] = 127;
motor[BackRight] = 127;
motor[FrontLeft] = 127;
motor[FrontRight] = 127;
wait10Msec(100);
motor[BackLeft] = -127;
motor[BackRight] = 127;
motor[FrontLeft] = -127;
motor[FrontRight] = 127;
wait10Msec(150);
}
}
else
{
motor[BackLeft] = -127;
motor[BackRight] = -127;
motor[FrontLeft] = -127;
motor[FrontRight] = -127;
}
}



/////////////////////////////////////////////////////////////////////////////////////////
//
// User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
// User control code here, inside the loop

}


while (true)
{
// This is the main execution loop for the user control program. Each time through the loop
// your program should update motor + servo values based on feedback from the joysticks.

while (vexRT[Btn8D]==1)
{
motor[GarageDoor]=127;
}


motor[FrontLeft]=vexRT[Ch3];
motor[BackLeft]=vexRT[Ch3];
motor[FrontRight]=vexRT[Ch2];
motor[BackRight]=vexRT[Ch2];


motor[TheCannon] = vexRT[Btn5U]*127;
motor[TheCannon] = vexRT[Btn6U]*45;


pushstate = vexRT[Btn7D] + 2*vexRT[Btn7L];
if ((pushstate == 0) && latch == true)
latch = false;
else
{
if ((latch == false))
{
switch (pushstate)
{
case 1:
motor[Pushers] = -127;
break;
case 2:
motor[Pushers] = 127;
break;
case 3:
motor[Pushers] = 0;
latch = true;
break;
default:
}
}
}
}


Thu Jan 17, 2013 5:23 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 558
Post Re: First Time Programming, don't understand template
There are a couple of major problems with the code that I'm seeing, but don't get discouraged; they are fairly simple mistakes, you have the right idea, and you are headed on the right track. Check out the comments I've made in the autonomous code (below):

Code:
task autonomous()
{
   if(SensorValue[SONAR] <= 3) //If sonar sensor is less than or equal to three
   {
      motor[BackLeft] = 0; //Turn all motors off
      motor[BackRight] = 0;
      motor[FrontLeft] = 0;
      motor[FrontRight] = 0;
      
      if(SensorValue[RightLight] <= 100) //If the right light sensor is less than/equal to 100, do this
      {
         motor[Pushers] = 127;
         wait10Msec(100);
      }
      if(SensorValue[LeftLight] <= 100) //If the left light sensor is less than/equal to 100, do this; what happens if both are less than 100?
      {
         motor[Pushers] = -127;
         wait10Msec(100);
      }
      else //if the left light sensor is not less than or equal to 100, do this instead
      {
         motor[BackLeft] = 127;
         motor[BackRight] = 127;
         motor[FrontLeft] = 127;
         motor[FrontRight] = 127;
         wait10Msec(100);
         motor[BackLeft] = -127;
         motor[BackRight] = 127;
         motor[FrontLeft] = -127;
         motor[FrontRight] = 127;
         wait10Msec(150);
      }
   }
   
   else //If the Sonar value is not less than or equal to 3, do this
   {
      motor[BackLeft] = -127;
      motor[BackRight] = -127;
      motor[FrontLeft] = -127;
      motor[FrontRight] = -127;
   }
}



And also the user control code (which is where the error is coming from):

Code:
task usercontrol()
{
// User control code here, inside the loop

}


Remember, each task starts and stops with a matching set of braces. In this case, the usercontrol task has no code to execute because of the misplaced end brace }. Then, ROBOTC sees all of the other code outside of the task and tells you that 'Executable statements (meaning, user code) not valid in 'main' declaration block (outside of tasks, functions, etc)'. If you move the closing brace to the very end and 'encompass' all the rest of your user control code, ROBOTC will compile it without error. You may not get the results you'd like from the program, but the syntax should be correct.

I would suggest taking a look through our Video Trainer Curriculum for VEX (http://www.education.rec.ri.cmu.edu/pro ... index.html) as it can walk you through, step by step, all of the programming procedures I've described here. Not only will it reinforce what you already know, but you may also be able to pick up some neat tricks to make your robot run smoother.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Thu Jan 17, 2013 6:02 pm
Profile
Rookie

Joined: Wed Jan 09, 2013 5:26 pm
Posts: 9
Post Re: First Time Programming, don't understand template
Thank you very much!


Tue Jan 22, 2013 4:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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:  
cron



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