I could not find a place anywhere else to do this, so I am doing it here. =) I am a senior in high school and currently on VEX team 323A Shockwave and FRC team 1741 Red Alert Robotics. The following is my code for our VEX robot this year....I just wanted to get it out there and see if anyone had any comments on it. Thanks! =D

////////////////////////////////////////////////////////////////////////////////////////////////// //// Pre-Autonomous Functions //// //// You may want to perform some actions before the competition starts. Do them in the //// following function. //// //////////////////////////////////////////////////////////////////////////////////////////////////

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

// While the encoders have not yet met their goal: (left is compared negativly since it will in reverse) while(SensorValue(rightEncoder) < (l * rotations) && SensorValue(leftEncoder) > (-1 * l * rotations)) { motor[rightMotor] = 80; // Run the right motor forward at 100 speed motor[leftMotor] = -80; // Run the left motor backward at 100 speed } motor[rightMotor] = 0; /* Stop both motors! This is important so that each function */ motor[leftMotor] = 0; /* can act independantly as a "chunk" of code, without any loose ends. */}//----------------------------------------------------------------------------------------------------

// While the encoders have not yet met their goal: (left is compared negativly since it will in reverse) while(SensorValue(leftEncoder) < (r * rotations) && SensorValue(rightEncoder) > (-1 * r * rotations)) { motor[rightMotor] = -80; // Run the right motor forward at half speed motor[leftMotor] = 80; // Run the left motor backward at half speed } motor[rightMotor] = 0; /* Stop both motors! This is important so that each function */ motor[leftMotor] = 0; /* can act independantly as a "chunk" of code, without any loose ends. */}//----------------------------------------------------------------------------------------------------

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

//=============================================| DRIVE |==============================================\\task Drive(){ int joy_l; // Will hold the X value of the LEFT analog stick. int joy_r; // Will hold the X value of the RIGHT analog stick. int threshold = 20; // Helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)

while(true) {

joy_l = vexRT[Ch3]; //This gets the X axis value of the LEFT analog stick and assigns the value to "joy_l". joy_r = vexRT[Ch2]; //This gets the X axis value of the RIGHT analog stick and assigns the value to "joy_r".

Dracco,First off, great code. Extremely well laid out, formated, and documented. Better than a lot of professional code I review.

I do not have any experience with ROBOTC on Vex, but I assume it is about the same as on the NXT. I do wonder if your post would get more or less attention if it was in the Vex sub-forum?

That said, some random thoughts/comments while skimming your code...

1) I see that you're a big fan of floats in your function params. In at least one case, I think you may want to consider a more appropirate datatype such as passing an enum to your claw() function. Passing something like CLAW_OPEN or CLAW_CLOSE is more readable than 1 and -1.

2) You have a lot of hard coded values throughout the code (generally motor speeds, encoder targets, and the like). I would suggest using constants for these values as it is easier to read and if the value is used more than one place and you have to update it, you only have to remember to update the one constant. ROBOTC provides the keyword 'const' for defining constants so that you do not have to use the old #define.

3) There are places where you are setting a single output (or set of outputs such as two or four motors) with multiple independent conditional statements in a single function. Generally, you only want one independent set of conditions to control that type of output. For example, in your claw movement code, you have two independent sets of conditions all controlling a single clawMotor output. It would be cleaner to combine them in a single if/else if/else construct to avoid ambigous situations where the last conditional wins.For example, this:

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum