View unanswered posts | View active topics It is currently Fri Aug 29, 2014 6:24 pm






Reply to topic  [ 5 posts ] 
Problem testing autonomous section of code 
Author Message
Rookie

Joined: Tue Feb 18, 2014 1:32 pm
Posts: 2
Post Problem testing autonomous section of code
I have been trying to use the competition emulator with no luck here is my code please see if you can help. Thanks RWalker

Code:
#pragma config(Motor,  port2,           LeftMidFront,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           LeftRear,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           RightRear,     tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port5,           RightMidFront, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           Intake,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           SixBar,        tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#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 = false;

   // 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()
{
    //bMotorReflected[port4]=true;
   //bMotorReflected[port5]=true;
   for(int x = 0; x  < 2; x++)
   {
   motor[LeftMidFront]=(127);
   motor[LeftRear]=(127);
                                    //Drive forward
   motor[RightRear]=(127);
   motor[RightMidFront]=(127);
   wait1Msec(1000);

   motor[LeftMidFront]=(0);
   motor[LeftRear]=(0);
                                    //Drive forward
   motor[RightRear]=(0);
   motor[RightMidFront]=(0);
   wait1Msec(1000);

   motor[SixBar]=(-127);   //raise 6 arm
   //motor[port8]=(-127);
   wait1Msec(1000);

   motor[LeftMidFront]=(80);
   motor[LeftRear]=(80);
                                    //drive forward to knock off balls into score zone
   motor[RightRear]=(80);
   motor[RightMidFront]=(80);
   wait1Msec(500);


motor[LeftMidFront]=(-127);
   motor[LeftRear]=(-127);
                                    //reverse back into the start position
   motor[RightRear]=(-127);
   motor[RightMidFront]=(-127);
   wait1Msec(2250);

   motor[LeftMidFront]=(0);
   motor[LeftRear]=(0);
                                    //Drive forward
   motor[RightRear]=(0);
   motor[RightMidFront]=(0);
   wait1Msec(1000);

   motor[SixBar]=(127);//lower 6 bar
   //motor[port8]=(127);
   wait1Msec(1000);
}
AutonomousCodePlaceholderForTesting();
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 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()
{
   //bIfiAutonomousMode = false;

   // User control code here, inside the loop

   while (1 == 1)
   {
   motor[LeftMidFront]=vexRT[Ch3];
   motor[LeftRear]=vexRT[Ch3];

   motor[RightRear]=vexRT[Ch2];
   motor[RightMidFront]=vexRT[Ch2];

   if(vexRT[Btn5U] == 1)      //If button 5U is pressed:
  {
    motor[Intake] = 64;         //run motor port 5 at quarter speed (i.e. turn wheels in)
  }
  else if(vexRT[Btn5D] == 1) //If button 5D is pressed:
  {
    motor[Intake] = -64;        //run motor port 5 at quarter speed reversed (i.e. turn wheels out)
  }
  else                       //If neither buttons 5U or 5D are pressed:
  {
    motor[Intake] = 0;         //stop motor port 5 (i.e. don't move)
  }

   motor[SixBar]=vexRT[Ch6];
   if(vexRT[Btn6U] == 1)      //If button 5U is pressed:
  {
    motor[SixBar] = 127;         //run motor port 5 at quarter speed (i.e. lift an arm)
  }
  else if(vexRT[Btn6D] == 1) //If button 5D is pressed:
  {
    motor[SixBar] = -127;        //run motor port 5 at quarter speed reversed (i.e. lower an arm)
  }
  else                       //If neither buttons 5U or 5D are pressed:
  {
    motor[SixBar] = 0;         //stop motor port 5 (i.e. don't move arm up or down)
  }


   UserControlCodePlaceholderForTesting();
   }
}


Last edited by JohnWatson on Tue Feb 18, 2014 1:44 pm, edited 1 time in total.

Added code tags for readability



Tue Feb 18, 2014 1:39 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: Problem testing autonomous section of code
I believe I see the issues with the code. Try removing the filler functions listed below, as they may be preventing the code from executing properly:

Code:
//In the Autonomous task:
AutonomousCodePlaceholderForTesting();

//In the User Control task:
UserControlCodePlaceholderForTesting();


Also, you may want to set the bStopTasksBetweenModes flag to true and uncomment it (found in the pre_auton function):

Code:
 bStopTasksBetweenModes = true;


Please let us know if this solves the code issues for you and, if not, how you are hooking the Cortex up to the computer for debugging.

_________________
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


Tue Feb 18, 2014 1:53 pm
Profile
Rookie

Joined: Tue Feb 18, 2014 1:32 pm
Posts: 2
Post Re: Problem testing autonomous section of code
Have commented the two lines of code out before but can't remember setting the top piece to true will try that and see what happens. Let me go over the procedures for running the program.
1 connect to controller
2 compile and download program
3 window with start appears and competition emulator appears
4 press start
5 press autonomous to test that part of the program?

is this correct? RWalker


Tue Feb 18, 2014 3:15 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: Problem testing autonomous section of code
I believe this issue may be with how the Cortex is connected to the computer. The Competition Debug window will only work if the Cortex is connected to the computer through a VEXNet connection via a VEXNet Joystick connection.

To test this program fully, you will need to perform the following steps

1) Navigate to the 'Robot -> VEX Cortex Communication Mode' menu option and change the menu to 'Competition (VEXNet)'.
2) Download the program to the robot. Once the program has been downloaded, a pop up window will appear informing you that you need to power cycle the robot.
3) To power cycle the robot, unplug the USB A-to-A cable from the computer and turn off the Cortex, then reconnect it and turn it back on. This will save the Competition (VEXNet) settings to the Cortex. Note that the robot may start to run the program at this time, so make sure it is not able to cause any damage.
4) Pair the VEXNet Controller to the Cortex. To do this, connect the two together via USB Cable, turn both on, and wait until the VEXNet lights turn green (indicating a successful pairing).
5) Turn off the VEXNet Controller and connect it to the computer using the Programming Hardware Kit (the phone jack end will go into the Program port on the back of the VEXNet Joystick Controller, and the USB end will go into the USB port of the computer).
6) Plug the VEXNet keys into both the Joystick Controller and the Cortex. Turn both on at roughly the same time, and wait for the VEXNet lights to turn green (on both the Cortex and Joystick controller).
7) Compile and download the program, and run the Competition Debug window.
8 ) Press Start on the Program Debug window and control the code execution using the buttons on the Competition Debug window.

If the process fails at any point, please let us know where and we'll be more than happy to help debug this further.

_________________
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


Tue Feb 18, 2014 5:19 pm
Profile
Rookie

Joined: Tue Feb 11, 2014 3:15 pm
Posts: 1
Location: North Bay, Ontario, Canada
Post Re: Problem testing autonomous section of code
Hello,

We are having similar problems... can't seem to test our autonomous modes. I coach my school's first new VEX team, and so this is all new to us. We are heading to our very first competition tomorrow. Would you mind having a peak at our code? Referring to the steps you provided below, must we absolutely use the "Programming Hardware Kit" (phone jack to USB) to test autonomous modes? This was not supplied with our competition kits.

Here is our code:

Quote:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1, autonbut1, sensorTouch)
#pragma config(Sensor, dgtl2, autonbut2, sensorTouch)
#pragma config(Sensor, dgtl3, autonbut3, sensorTouch)
#pragma config(Sensor, dgtl4, autonbut4, sensorTouch)
#pragma config(Sensor, dgtl5, autonbut5, sensorTouch)
#pragma config(Sensor, dgtl6, autonbut6, sensorTouch)
#pragma config(Sensor, dgtl7, autonbut7, sensorTouch)
#pragma config(Sensor, dgtl8, autonbut8, sensorTouch)
#pragma config(Sensor, dgtl9, limittop, sensorTouch)
#pragma config(Sensor, dgtl10, limitbottom, sensorTouch)
#pragma config(Sensor, dgtl11, solenoid1, sensorDigitalOut)
#pragma config(Sensor, dgtl12, solenoid2, sensorDigitalOut)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_3, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port6, liftbottom, tmotorVex393_MC29, openLoop, encoderPort, I2C_3)
#pragma config(Motor, port7, backleft, tmotorVex393_MC29, openLoop, encoderPort, I2C_2)
#pragma config(Motor, port8, frontleft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, backright, tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_1)
#pragma config(Motor, port10, frontright, tmotorVex393_HBridge, openLoop, reversed)
//*!!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 selectedAutonomous = 0; //Variable to select autonomous mode (viewtopic.php?f=11&t=7656)

/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void turnleft(int degrees, int speed)
{
nMotorEncoder[backright] = 0;
nMotorEncoder[backleft] = 0;

// Default high-torque encoder: 627.2 counts per revolution.
while(abs(nMotorEncoder[backright]) < (627.2*2*3.14*6.7*degrees/360/4.075/4.2))
{
motor[backright] = speed;
motor[frontright] = speed;
motor[backleft] = -speed;
motor[frontleft] = -speed;
}
motor[backright] = 0;
motor[frontright] = 0;
motor[backleft] = 0;
motor[frontleft] = 0;
}

void turnright(int degrees, int speed)
{
nMotorEncoder[backright] = 0;
nMotorEncoder[backleft] = 0;

while(abs(nMotorEncoder[backright]) < (627.2*2*3.14*6.7*degrees/360/4.075/4.2))
{
motor[backright] = -speed;
motor[frontright] = -speed;
motor[backleft] = speed;
motor[frontleft] = speed;
}
motor[backright] = 0;
motor[frontright] = 0;
motor[backleft] = 0;
motor[frontleft] = 0;
}

void moveforward(int distanceinches, int speed)
{
nMotorEncoder[backright] = 0; // Reset the motor encoders
nMotorEncoder[backleft] = 0;

while(abs(nMotorEncoder[backright]) < 627.2*distanceinches/4.075/3.14)
{
motor[backright] = speed;
motor[frontright] = speed;
motor[backleft] = speed;
motor[frontleft] = speed;
}

motor[backright] = 0;
motor[frontright] = 0;
motor[backleft] = 0;
motor[frontleft] = 0;
}

void movereverse(int distanceinches, int speed)
{
nMotorEncoder[backright] = 0; // Reset the motor encoders
nMotorEncoder[backleft] = 0;

while(abs(nMotorEncoder[backright]) < 627.2*distanceinches/4.075/3.14)
{
motor[backright] = -speed;
motor[frontright] = -speed;
motor[backleft] = -speed;
motor[frontleft] = -speed;
}

motor[backright] = 0;
motor[frontright] = 0;
motor[backleft] = 0;
motor[frontleft] = 0;
}

void lowerarm()
{
while(SensorValue(limitbottom) == 0)
{
motor[liftbottom] = -63;
}
}

void raisearmlow()
{
while(SensorValue(limittop) == 0)
{
motor[liftbottom] = 63;
}
}

void pushup()
{
SensorValue[solenoid1] = 1; // ...activate the solenoid.
SensorValue[solenoid2] = 1; // ...activate the solenoid.
}

void pushdown()
{
SensorValue[solenoid1] = 0; // ...deactivate the solenoid.
SensorValue[solenoid2] = 0; // ...deactivate the solenoid.
}

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


///////////////////////////////////////////
// //
// Set overal dimensions to 18 x 18 x 18 //
// //
///////////////////////////////////////////


selectedAutonomous = 0;
while(selectedAutonomous == 0)
{

///////////////////////////////////////////////////////////////////////////////////////
//
// The following code sets the autonomous function we want according to the button we push
// (viewtopic.php?f=11&t=7656)
//
///////////////////////////////////////////////////////////////////////////////////////


if(SensorValue[autonbut1]) //If the first touch sensor is pressed...
{
selectedAutonomous = 1; // blue, hanging zone, scenario 1
}

if(SensorValue[autonbut2]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 2; // blue, hanging zone, scenario 2
}

if(SensorValue[autonbut3]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 3; // blue, middle zone, scenario 1
}

if(SensorValue[autonbut4]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 4; // blue, middle zone, scenario 2
}

if(SensorValue[autonbut5]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 5; // red, hanging zone, scenario 1
}

if(SensorValue[autonbut6]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 6; // red, hanging zone, scenario 2
}

if(SensorValue[autonbut7]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 7; // red, middle zone, scenario 1
}

if(SensorValue[autonbut8]) //Else, if the second touch sensor is pressed...
{
selectedAutonomous = 8; // red, middle zone, scenario 2
}

}

}




/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{

if (selectedAutonomous == 1) //blue, hanging zone, scenario 1
{
// 1. robot facing red alliance,

nMotorEncoder[backright] = 0; // set drive encoders to zero
nMotorEncoder[backleft] = 0;

raisearmlow();

moveforward(12, 127);

wait1Msec(500);

turnright(90, 63);

wait1Msec(500);

moveforward(10, 127);

wait1Msec(500);

turnright(90, 127);

wait1Msec(500);

moveforward(15, 127);

wait1Msec(500);

movereverse(15, 127);

wait1Msec(500);

turnleft(90, 63) ;

wait1Msec(500);

moveforward(12, 127);

wait1Msec(500);

turnright(90, 63);

wait1Msec(500);

moveforward(30, 127);

pushup();

moveforward(10, 127);

pushdown();

turnleft(90, 127);

wait1Msec(500);

moveforward(30, 127);

wait1Msec(500);

turnleft(90,127); // 16. Turn left 90 degrees

wait1Msec(500);

moveforward(15, 127); // 17. Move forward 30"
}

else if (selectedAutonomous == 2) // blue, hanging zone, scenario 2
{
Instructions....
}

else if (selectedAutonomous == 3) // blue, middle zone, scenario 1
{
Instructions....
}

else if (selectedAutonomous == 4) // blue, middle zone, scenario 2
{
Instructions....
}

else if (selectedAutonomous == 5) // red, hanging zone, scenario 1
{
Instructions....
}

else if (selectedAutonomous == 6) // red, hanging zone, scenario 2
{
Instructions....
}

else if (selectedAutonomous == 7) // red, middle zone, scenario 1
{
Instructions....
}

else if (selectedAutonomous == 8) // red, middle zone, scenario 2
{
Instructions....
}
}


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

int threshold = 10; // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)

while(1 == 1)
{
if(abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
{
motor[frontleft] = (vexRT[Ch3])/2; // Left Joystick Y value / 2.
motor[backleft] = (vexRT[Ch3])/2;
}
else // If the left joystick is within the threshold:
{
motor[frontleft] = 0; // Stop the left motor (cancel noise)
motor[backleft] = 0;
}

if(abs(vexRT[Ch2]) > threshold) // If the right joystick is greater than or less than the threshold:
{
motor[frontright] = (vexRT[Ch2])/2; // Right Joystick Y value / 2.
motor[backright] = (vexRT[Ch2])/2;
}
else // If the right joystick is within the threshold:
{
motor[frontright] = 0; // Stop the right motor (cancel noise)
motor[backright] = 0;
}

// Buttons on front, group 6 to raise arm to barrier height to hit beachballs
if(vexRT[Btn6U] == 1)
{
raisearmlow();
}
else if(vexRT[Btn6D] == 1)
{
lowerarm();
}


if(vexRT[Btn8D] == 1) // If button 8D is pressed:
{
pushup();
}
else // If button 8D is NOT pressed:
{
pushdown();
}


}

}


Thus far, we successfully loaded this competition program onto the Cortex. We've attempted to test the program via USB connection between the computer and the Cortex. In RobotC, as you instruct in this thread, we set the "VEX Cortex Communication Mode" to "Competition (VEXNet)". After compiling and dowloading the program, we set the "Debugger Window" to "Competition...". No bugs... We see the small window with the three buttons "Disable, Autonomous, and User control". After all this, we cannot seem to get our autonomous modes to work...

ALSO: We cannot seem to pair our VEXNet Joystick to the Cortex wirelessly! We've updated the firmware on both the Cortex and VEXNet Joystick and successfully tethered the Joystick to the Cortex - all green lights... We plugged-in the VEXNet Keys afterwards but we get nothing but flashing orange lights - no communication.

Hoping you can help us... getting a little desperate!

Thank you,

Dan Orr
Team 5533 Coach
École secondaire publique Odyssée
North Bay, Ontario.

_________________
Dan Orr
Team 5533 Coach
École secondaire publique Odyssée
North Bay, Ontario


Fri Feb 21, 2014 7:43 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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:  



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