View unanswered posts | View active topics It is currently Tue Sep 30, 2014 12:42 pm






Reply to topic  [ 4 posts ] 
Could someone look over my code? 
Author Message
Rookie

Joined: Fri Feb 06, 2009 11:43 am
Posts: 11
Post Could someone look over my code?
I am following the VEX lessons on the website and so far have had no problems. Then in the Autonomy section where we have to a boolean variable , i feel like we followed the directions but yet the robot is not responding correctly. Basically we want an have operator assist by running a moving straight function using the lower Ch5 button. We want to end an Idle loop by using the upper Ch5 button. We want to operate an arm using the buttons on ch6. Everything compiles correctly with no errors, but yet we should be able to disengage the idle loop, have RC when we want it, be able to use the move straight function if we need it and be able able to operate the arm. Hope that is clear. See the code below.

Thanks - Ken



const tSensors downLimit = (tSensors) in1; //sensorTouch //*!!!!*//
const tSensors rightEncoder = (tSensors) in2; //sensorRotation //*!!!!*//
const tSensors leftEncoder = (tSensors) in3; //sensorRotation //*!!!!*//
const tSensors upLimit = (tSensors) in4; //sensorTouch //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//

void moveStraight()
{if(SensorValue[leftEncoder] > SensorValue[rightEncoder])
{
motor[port3] = 50;
motor[port2] = 63;
}
if(SensorValue[leftEncoder] < SensorValue[rightEncoder])
{
motor[port3] = 63;
motor[port2] = 50;
}
if(SensorValue[leftEncoder] == SensorValue[rightEncoder])
{
motor[port3] = 63;
motor[port2] = 63;
}}

task main()
{
int armDirection;
bool isMovingStraight;
bIfiAutonomousMode = false;
while(vexRT[Ch5] == 0)
{
}
bMotorReflected[port2] = 1;

armDirection = 0;
isMovingStraight = false;
ClearTimer(T1);

while(time10[T1] < 12000)

{

if(armDirection == 1)
{
if(SensorValue(upLimit) == 0)
{
motor[port6] = 31;
}
else
{
motor[port6] = 0;
}

if(armDirection == -1)
{
if(SensorValue(downLimit) == 0)
{
motor[port6] = -31;
}
else
{
motor[port6] = 0;
}
if(armDirection == 0)
{
motor[port6] = 0;
}

if(vexRT[Ch6] == -127)

{
armDirection = 1;
}


if(vexRT[Ch6] == 127)

{
armDirection = -1;
}

if(vexRT[Ch5] == -127)
{
if(isMovingStraight == false)
{
SensorValue[leftEncoder] = 0;
SensorValue[rightEncoder] = 0;
isMovingStraight = true;
}
else
{
moveStraight();
}
}
else
{
isMovingStraight = false;
motor[port3] = vexRT[Ch3];
motor[port2] = vexRT[Ch2];
}

}
}
}
motor[port3] = 0;
motor[port2] = 0;
}


Tue Feb 10, 2009 10:13 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post Re: Could someone look over my code?
Hi Ken -

I think I've found the source of your problems. In your program, you have two if statements that don't get closed until almost the very end of the program. If I copy your code and paste it directly into ROBOTC, the if statements I'm referring to begin on lines 38 and 49. There should be closing curly braces on lines 48, and after 58 to close each, I think (and two less toward the end of the program). By not closing the if statements in the correct places, all the following code gets put in one giant if statement... which would explain the weird, undesirable behavior.

Let me know if that helps.

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Mon Feb 16, 2009 2:00 pm
Profile
Rookie

Joined: Fri Feb 06, 2009 11:43 am
Posts: 11
Post Re: Could someone look over my code?
THANKS! WORKS like a charm now! I think I will stress using the TAB key to make sure all brackets line up with the control structure they belong to.


Wed Feb 25, 2009 4:45 pm
Profile
Rookie

Joined: Sat Aug 30, 2008 2:25 am
Posts: 25
Post Re: Could someone look over my code?
Code formatting goes a huge distance in making things readable. On forums, you can use [ code ] and [ /code ] to enclose your nicely formatted code and make it easier to read.

RobotC also has some formatting options, so if your program isn't already nicely aligned you can easily apply some standard alignment rules which will make things like this totally obvious.


Fri Mar 20, 2009 12:33 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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

Search for:
Jump to:  



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