View unanswered posts | View active topics It is currently Fri Oct 31, 2014 4:03 am






Reply to topic  [ 7 posts ] 
Competition code problem 
Author Message
Rookie

Joined: Fri Jan 31, 2014 6:07 pm
Posts: 3
Post Competition code problem
My team is prepping for a Toss-Up Competition tomorrow, and have run into a problem with their program.
They have finally built their autonomous code, but are having problems. They have programmed into the competition template, but only the task (usercontrol) commands are working.

We have been searching forums and sample code, and have come across using either a completion switch (which we don’t have), or the debugger window.

Trying the debugger window has not worked so far

Any ideas?


Fri Jan 31, 2014 6:14 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 597
Post Re: Competition code problem
Please post your code (including the #pragmas) using the [code] tags and we will be more than happy to take a look at it for you. Also, please do not double post; this only creates confusion and splits the discussion between two identical threads.

Thank you.

_________________
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


Fri Jan 31, 2014 6:42 pm
Profile
Rookie

Joined: Fri Jan 31, 2014 6:07 pm
Posts: 3
Post Re: Competition code problem
Apologies for the duplicate, I should have deleted as soon as I found the appropriate category.



#pragma config(Sensor, dgtl1, sa, sensorTouch)
#pragma config(Motor, port2, leftMotor, tmotorVex393, openLoop)
#pragma config(Motor, port3, rightMotor, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port4, am, tmotorVex393, openLoop)
#pragma config(Motor, port5, cwr, tmotorVex393, openLoop)
#pragma config(Motor, port6, cwl, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port7, am2, tmotorVex393, openLoop, reversed)
//bleebleebloop
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//


#pragma platform(VEX)

#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(105)

#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()



{
startMotor(rightMotor, 127);
startMotor(leftMotor, -127);
wait(100);
stopMotor(rightMotor);
stopMotor(leftMotor);

}


/////////////////////////////////////////////////////////////////////////////////////////
//
// 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.


//Right side of the robot is controlled by the right joystick, Y-axis
motor[rightMotor] = vexRT[Ch2];

//Left side of the robot is controlled by the left joystick, Y-axis
motor[leftMotor] = vexRT[Ch3];



}

if(vexRT[Btn6U] == 1) //If Button 6U is pressed...

{
motor[cwr] = 127; //...close the gripper.
motor[cwl] = 127;
}
else if(vexRT[Btn6D] == 1) //Else, if button 6D is pressed...
{
motor[cwr] = -127; //...open the gripper.
motor[cwl] = -127;
}
else //Else (neither button is pressed)...
{
motor[cwr] = 0; //...stop the gripper.
motor[cwl] = 0;


// Open, close or do not more claw
if(vexRT[Btn5D] == 1) //If Button 6U is pressed...
{
motor[am] = 127; //...close the gripper.
}
else if(vexRT[Btn5U] == 1) //Else, if button 6D is pressed...
{
motor[am] = -127; //...open the gripper.
}
else //Else (neither button is pressed)...
{
motor[am] = 0; //...stop the gripper.
// Open, close or do not more claw
if(vexRT[Btn5U] == 1) //If Button 6U is pressed...
{
motor[am2] = 127; //...close the gripper.
}
else if(vexRT[Btn5D] == 1) //Else, if button 6D is pressed...
{
motor[am2] = -127; //...open the gripper.
}
else //Else (neither button is pressed)...
{
motor[am2] = 0; //...stop the gripper.

}

}
}
}


Fri Jan 31, 2014 6:47 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 597
Post Re: Competition code problem
Double check the settings under the 'Robot -> VEX Cortex Communication Mode', and make sure it is set to 'Competition (VEXNet)' and not 'VEXNet or USB' or 'USB Only'. This will force the Cortex to check for the competition switch settings. Once this setting is changed, redownload the program to the Cortex and power cycle it (turn the Cortex off, remove the USB cable (if applicable; the USB cable will power the Cortex otherwise), and turn the Cortex back on) to save this setting. Try this first as it is the most common error, and let us know if this solves the issue.

There are a couple of other things I can suggest checking on the code as well:

Code:
//bleebleebloop


I would recommend removing this comment from the #pragma area as this may cause issue later on. You can safely consider anything above the //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// line to be almost hands-off for best performance.

Code:
task autonomous()



{


There's a lot of empty space between the task autonomous() line and the opening brace; I would also recommend removing this extra space to make sure it doesn't interfere with the code in any way (it shouldn't, but it never hurts to be safe).

Code:
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.


      //Right side of the robot is controlled by the right joystick, Y-axis
      motor[rightMotor] = vexRT[Ch2];

      //Left side of the robot is controlled by the left joystick, Y-axis
      motor[leftMotor] = vexRT[Ch3];



   }


Be careful with the opening and closing parenthesis. It looks like you only have the left and right control in the infinite loop, and not the arm control; you will need to make sure all of your code is encapsulated inside of the while loop's opening and closing brace structure in order to have the joystick control both the drive and the arm of the robot.

_________________
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


Fri Jan 31, 2014 7:00 pm
Profile
Rookie

Joined: Sat Mar 30, 2013 4:58 pm
Posts: 2
Post Re: Competition code problem
we are programing the vex skyrise but the autonomus mode does not run






#pragma config(Sensor, in1, armPot, sensorPotentiometer)
#pragma config(Sensor, dgtl1, armLimit, sensorTouch)
#pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port3, rightMotor2, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port4, leftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port5, leftMotor2, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port6, armMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, armMotor2, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port8, clawMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port9, clawmotor2, 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!

/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{
// .....................................................................................
motor [clawMotor] = 127;
wait1Msec (200);

motor [rightMotor2] = 63;
motor [rightMotor] = 63;
motor [leftMotor2] = 63;
motor [leftMotor] = 63;
wait1Msec (1250);

motor [rightMotor2] = 63;
motor [rightMotor] = 63;
motor [leftMotor2] = -63;
motor [leftMotor] = -63;
wait1Msec (700);

motor [rightMotor2] = 63;
motor [rightMotor] = 63;
motor [leftMotor2] = 63;
motor [leftMotor] = 63;
wait1Msec (900);

motor [clawMotor] = -127;
wait1Msec (200);

motor [rightMotor2] = -63;
motor [rightMotor] = -63;
motor [leftMotor2] = -63;
motor [leftMotor] = -63;
wait1Msec (800);


}
// .....................................................................................



/////////////////////////////////////////////////////////////////////////////////////////
//
// 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.

// .....................................................................................
// Insert user code here. This is where you use the joystick values to update your motors, etc.
// .....................................................................................
{

while(1 == 1)
{
motor[leftMotor] = vexRT[Ch3] /2; // Left Joystick Y value
motor[leftMotor2] = vexRT[Ch3] /2;
motor[rightMotor] = vexRT[Ch2] /2; // Right Joystick Y value
motor[rightMotor2] = vexRT[Ch2] /2;

if(vexRT[Btn7U] == 1) // arm motor number 1
{
motor[armMotor] = 90;
}
else if(vexRT[Btn7D])
{
motor[armMotor] = -90;
}
else
{
motor[armMotor] = 0;
}


if(vexRT[Btn7U] == 1) //arm motor number 2
{
motor[armMotor2] = 90;
}
else if(vexRT[Btn7D])
{
motor[armMotor2] = -90;
}
else
{
motor[armMotor2] = 0;
}



if(SensorValue(armLimit) == 1) // Loop while robot's touch sensor isn't pressed in
{
motor[armMotor] = 0;
motor[armMotor2] = 0;
}
else
{
if(vexRT[Btn7U] == 1) //arm motor number 2
{
motor[armMotor2] = 127;
}
else if(vexRT[Btn7D] == 1)
{
motor[armMotor2] = -127;
}
else
{
motor[armMotor2] = 0;
}

if(vexRT[Btn6U] == 1) //claw motor
{
motor[clawMotor] = 127;
}
else if(vexRT[Btn6D] == 1)
{
motor[clawMotor] = -127;
}
else
{
motor[clawMotor] = 0;
}

if(vexRT[Btn6U] == 1) //claw motor
{
motor[clawMotor2] = 127;
}
else if(vexRT[Btn6D] == 1)
{
motor[clawMotor2] = -127;
}
else
{
motor[clawMotor] = 0;
}
}

}

}
UserControlCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
}
}


Fri Oct 17, 2014 12:32 pm
Profile
Rookie

Joined: Thu Dec 01, 2011 12:07 am
Posts: 40
Post Re: Competition code problem
I assume you are not connected to a competition field. You don't say if it runs pre-auton or user control.

Without a competition field and it's connections you may need to set competitionControl to OFF to give control to your program.

#pragma competitionControl(competition_mode) - Controls the competition mode that
the VEX is in. There are two different competition modes that you can pass:
OFF - No competition control.
Competition - The VEX will respond to field control commands and switch between
Autonomous and User Control modes at the competition-specified times. Use this mode for
competitions.


Fri Oct 17, 2014 9:51 pm
Profile
Rookie

Joined: Sat Oct 18, 2014 2:22 am
Posts: 1
Post Re: Competition code problem
It looks like you only have the left and right control in the infinite loop, and not the arm control; you will need to make sure all of your code is encapsulated inside of the while loop's opening and closing brace structure in order to have the joystick control both the drive and the arm of the robot.

_________________
GuL


Sat Oct 18, 2014 3:31 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.