|
Page 1 of 1
|
[ 2 posts ] |
|
global variable issue in competition code
Author |
Message |
robo
Rookie
Joined: Sat Mar 30, 2013 4:58 pm Posts: 2
|
 global variable issue in competition code
When compiling code, we get the following error: **Error**:Task 'usercontrol' is not defined at global scope level  |  |  |  | Code: #pragma config(Sensor, in6, armPot, sensorAnalog) #pragma config(Sensor, dgtl1, frontBumper, sensorTouch) #pragma config(Sensor, dgtl2, backBumper, sensorNone) #pragma config(Sensor, dgtl3, sonarSensor, sensorSONAR_cm) #pragma config(Sensor, dgtl5, frontLimit, sensorTouch) #pragma config(Motor, port1, leftMotor, tmotorVex393, openLoop, reversed) #pragma config(Motor, port6, clawMotor, tmotorVex393, openLoop) #pragma config(Motor, port7, armMotor, tmotorVex393, openLoop) #pragma config(Motor, port10, rightMotor, tmotorVex393, openLoop)
#pragma platform(VEX)
//Competition Control and Duration Settings #pragma competitionControl(Competition) #pragma autonomousDuration(30) #pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
///////////////////////////////////////////////////////////////////////////////////////// // // 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() {
while (vexRT [Btn7D] == 0)
while (1==1)
if (SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 inches away from an object { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range) motor[rightMotor] = 63; // Motor on port2 is run at half (63) power forward motor[leftMotor] = 63; // Motor on port3 is run at half (63) power forward } else { motor [rightMotor] = 0; motor [leftMotor] = 0; wait1Msec(1000); motor [rightMotor] = - 63; motor [leftMotor] = - 63; wait1Msec (1000); motor [rightMotor] = 63; motor [leftMotor] = -63; wait1Msec (1000);
}
///////////////////////////////////////////////////////////////////////////////////////// // // 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() { while (vexRT [Btn7D] == 0) { } // User control code here, inside the loop
while (true) { wait1Msec(1000); // Robot waits for 1000 milliseconds before executing program
if(SensorValue(sonarSensor) > 5 || SensorValue(sonarSensor) < 0) // Loop while robot's Ultrasonic sensor is further than 4 inches away from an object { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range) motor[rightMotor] = 127; // Motor on port2 is run at half (63) power forward motor[leftMotor] = 127; // Motor on port3 is run at half (63) power forward
if(SensorValue(sonarSensor) < 5) { motor[rightMotor] = 0; motor[leftMotor] = 63; wait1Msec(2000); }
}
// Move forward at full power motor[leftMotor] = 127; // Motor on port1 is run at full (127) power forward motor[rightMotor] = 127; // Motor on port10 is run at full (127) power forward wait1Msec(2000);
while(1 == 1) {
//Driving Motor Control - joystick remote control motor[leftMotor] = vexRT[Ch3] ; // Left Joystick Y value motor[rightMotor] = vexRT[Ch2] ; // Right Joystick Y value
//Arm Control if(vexRT[Btn6U] == 1 && SensorValue [armPot] <4092) { motor[armMotor] = 60; } else if(vexRT[Btn6D] == 1 && SensorValue[frontLimit] == 0) { motor[armMotor] = -60; } else { motor[armMotor] = 0;
//Claw Control if(vexRT[Btn5U] == 1) { motor[clawMotor] = 30; }
else if(vexRT[Btn5D] == 1) { motor[clawMotor] = -30; } else { motor[clawMotor] = 0; } } }
} } }
|  |  |  |  |
Please help.
|
Wed Apr 03, 2013 6:04 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: global variable issue in competition code
The problem lies with the fact that you are not using indentation in your file. You're missing a brace in your code and it's impossible to spot if you're not going to use indentiation. I have fixed it for you, but from now on, use indentation. I have included a screenshot where you can find the option to format your whole file every now and again, so it'll always look good. I've also gone ahead and added the program with the missing brace. Regards, Xander  |  |  |  | Code: #pragma config(Sensor, in6, armPot, sensorAnalog) #pragma config(Sensor, dgtl1, frontBumper, sensorTouch) #pragma config(Sensor, dgtl2, backBumper, sensorNone) #pragma config(Sensor, dgtl3, sonarSensor, sensorSONAR_cm) #pragma config(Sensor, dgtl5, frontLimit, sensorTouch) #pragma config(Motor, port1, leftMotor, tmotorVex393, openLoop, reversed) #pragma config(Motor, port6, clawMotor, tmotorVex393, openLoop) #pragma config(Motor, port7, armMotor, tmotorVex393, openLoop) #pragma config(Motor, port10, rightMotor, tmotorVex393, openLoop)
#pragma platform(VEX)
//Competition Control and Duration Settings #pragma competitionControl(Competition) #pragma autonomousDuration(30) #pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
///////////////////////////////////////////////////////////////////////////////////////// // // 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() {
while (vexRT [Btn7D] == 0)
while (1==1)
if (SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 inches away from an object { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range) motor[rightMotor] = 63; // Motor on port2 is run at half (63) power forward motor[leftMotor] = 63; // Motor on port3 is run at half (63) power forward } else { motor [rightMotor] = 0; motor [leftMotor] = 0; wait1Msec(1000); motor [rightMotor] = - 63; motor [leftMotor] = - 63; wait1Msec (1000); motor [rightMotor] = 63; motor [leftMotor] = -63; wait1Msec (1000);
} } ///////////////////////////////////////////////////////////////////////////////////////// // // 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() { while (vexRT [Btn7D] == 0) { } // User control code here, inside the loop
while (true) { wait1Msec(1000); // Robot waits for 1000 milliseconds before executing program
if(SensorValue(sonarSensor) > 5 || SensorValue(sonarSensor) < 0) // Loop while robot's Ultrasonic sensor is further than 4 inches away from an object { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range) motor[rightMotor] = 127; // Motor on port2 is run at half (63) power forward motor[leftMotor] = 127; // Motor on port3 is run at half (63) power forward
if(SensorValue(sonarSensor) < 5) { motor[rightMotor] = 0; motor[leftMotor] = 63; wait1Msec(2000); }
}
// Move forward at full power motor[leftMotor] = 127; // Motor on port1 is run at full (127) power forward motor[rightMotor] = 127; // Motor on port10 is run at full (127) power forward wait1Msec(2000);
while(1 == 1) {
//Driving Motor Control - joystick remote control motor[leftMotor] = vexRT[Ch3] ; // Left Joystick Y value motor[rightMotor] = vexRT[Ch2] ; // Right Joystick Y value
//Arm Control if(vexRT[Btn6U] == 1 && SensorValue [armPot] <4092) { motor[armMotor] = 60; } else if(vexRT[Btn6D] == 1 && SensorValue[frontLimit] == 0) { motor[armMotor] = -60; } else { motor[armMotor] = 0;
//Claw Control if(vexRT[Btn5U] == 1) { motor[clawMotor] = 30; }
else if(vexRT[Btn5D] == 1) { motor[clawMotor] = -30; } else { motor[clawMotor] = 0; } } } } } |  |  |  |  |
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Thu Apr 04, 2013 12:57 am |
|
|
|
Page 1 of 1
|
[ 2 posts ] |
|
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
|
|