Log in

View Full Version : Need help with code


CaseyKasem_1251
18-02-2006, 07:57
ok so i have some autonomous code right now and This code gets the Tilt_servo variable from tracking.c, then goes into a
loop, and waits for a while, then gets the value again and tests it
against the previous value to guaranty that it has not changed. If the
value has not been updated, we assume that the target has been found
and we can then pass the value as the final value. right now this code looks like this void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */

angle = TILT_Servo;
try_again = false
while (try_again == false)
{
first_angle == TILT_Servo;
for (y = 1; y<=1000; y++)
//do nothing-wait
second_angle = TILT_Servo
if (first_angle == second_angle)
{
(TILT_Servo)
}
else
try_again = true;
}
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}


i keep getting errors at while (try_again == false) and (first_angle == second_angle) any help or constructive criticsm would be most helpful

Thanks

kaszeta
18-02-2006, 09:08
Is this really the code? If so, the errors are because you are missing a bunch of semicolons (like after "try_again = false"). You should also clean up the curly braces with the else statements

Mark McLeod
18-02-2006, 09:38
This scheme will also not work with the IFI Robot Controller design because you cannot pause execution with a "while" statement or a timing loop for any appreciable amount of time.
Doing so prevents you from servicing the regular radio packets with Getdata/Putdata, and when the Master control doesn't hear from you it automatically shuts your code down -- Red "Code Error" light.

Gamer930
18-02-2006, 09:39
angle = TILT_Servo;
try_again = false;
while (try_again == false)
{
first_angle = TILT_Servo;
for (y = 1; y<=1000; y++)
{
//do nothing-wait
}
second_angle = TILT_Servo;
if (first_angle == second_angle)
{
(TILT_Servo)
}
else
{
try_again = true;
}


Couple of Things:
1. There is no Boolean Variables right out of the box for MPLAB. You can get them by assigning your variables as int and then have:
#define TRUE 1
#define FALSE 0
at the top of your code
2. Try and use indentation. It will make debugging your code a lot easier
3. I have noticed a lot that MPLAB doesn't like when you don't use {} on single line For/If/While statements. That is why I put those in.
4. == is for conditional statements. IF / While statements
= is for assignment statements. There were couple of places where those were messed up

If you have any more question feel free to contact me on one of my Instant Messaging ways