Society of Robots - Robot Forum

Software => Software => Topic started by: mr roboto on March 03, 2012, 01:33:05 PM

Title: Why wont code compile?
Post by: mr roboto on March 03, 2012, 01:33:05 PM
this was set up in webbot lib so the hardware is declared. this is the code i have written so far. my problem is that it wont compile. (this is for wall avoidence. there are 4 servos. and a sharp ir range sensor.)
THANKS
#include<hardware.h>

#include<xhardware.h>

#include<stdio.h>

#include<SoR_Utils>

#include<conio.h>

int main(void)

{
   
   int angle_1;
   int angle_2;
   int distance_1;
   int distance_2;
   int constant_width;
   int constant_scanner_placement;
    int state;
   int left_sharp;
   int right_sharp;
   int thresh_hold;
   int angle_1=0;
   int angle_2=0;
   int distance_1=0;
   int distance_2=0;
   int constant_width=85
   int constant_scanner_placement=40;
    int state=1;
   int thresh_hold=8
   
}

while()

{
extern Sharp_GP2Y0A02YK0F sharp_scanner=a2dConvert8bit(5);
if sharp_scanner > thresh_hold
{
    extern LED LED_1_on()
    extern SERVO servo_left_front(25)
    extern SERVO servo_right_front(25)
    extern SERVO servo_left_back(25)
    extern SERVO servo_right_back(25)
}
else
{
    extern LED LED_1_off()
    extern SERVO servo_left_front(40)
    extern SERVO servo_right_front(25)
    extern SERVO servo_left_back(40)
    extern SERVO servo_right_back(25)
}
   delay_cycles(500);
}

return 0
}   




   








Title: Re: Why wont code compile?
Post by: Gertlex on March 03, 2012, 03:31:56 PM
Two questions that would help here... 1) are you using Project Designer? (doesn't look like it) 2) What are the error messages you're getting? (Copy/paste is fine)

One thing I found right off is that you can't use while() like that. You need to put somethign in the parentheses... and it can just be while(1) for an infinite loop. (probably what you want)
Title: Re: Why wont code compile?
Post by: agold on March 04, 2012, 12:22:27 AM
Two more quick problems:
Code: [Select]
if sharp_scanner > thresh_hold
doesn't have parenthesis, it should be:
Code: [Select]
if (sharp_scanner > thresh_hold)

The lines like this:
Code: [Select]
extern SERVO servo_right_back(25)

firstly shouldn't need the type declaration, and secondly need to finish with a semicolon, e.g.
Code: [Select]
servo_right_back(25);

Adrian
Title: Re: Why wont code compile?
Post by: Webbot on March 04, 2012, 08:08:12 AM
Also, with WebbotLib, you shouldn't have a 'main' function you should use the appControl function instead
Title: Re: Why wont code compile?
Post by: mr roboto on March 04, 2012, 10:28:02 PM
oh.

thanks for all of your help.
it seems that C is a bit different than other languages ive used.
Gertlex:
1) I am using project designer.
2) My robots not with me ATM to check. (I should have it arround wednesday)
agold:
im gonna go fix said problems now.
webbot:
so it should be int appControl(void) instead of int main(void)? im not sure i understand.
thanks to all.

Title: Re: Why wont code compile?
Post by: Webbot on March 05, 2012, 01:32:53 PM

webbot:
so it should be int appControl(void) instead of int main(void)? im not sure i understand.


See the documentation http://webbot.org.uk/WebbotLibDocs/27746.html (http://webbot.org.uk/WebbotLibDocs/27746.html) - although if your using Project Designer then it automatically does all the #includes for you.
Title: Re: Why wont code compile?
Post by: mr roboto on March 15, 2012, 10:50:16 AM
just made said changes.
like this?
{
   
   int angle_1;
   int angle_2;
   int distance_1;
   int distance_2;
   int constant_width;
   int constant_scanner_placement;
               int state;
   int left_sharp;
   int right_sharp;
   int thresh_hold;
   int angle_1=0;
   int angle_2=0;
   int distance_1=0;
   int distance_2=0;
   int constant_width=85
   int constant_scanner_placement=40;
               int state=1;
   int thresh_hold=8
   
}

while()

{
extern Sharp_GP2Y0A02YK0F sharp_scanner=a2dConvert8bit(5);
if (sharp_scanner > thresh_hold)
{
    LED_1_on()
    servo_left_front(25)
    servo_right_front(25);
    servo_right_back(25);
    servo_left_back(25);
}
else
{
    extern LED LED_1_off()
    extern SERVO servo_left_front(40)
    extern SERVO servo_right_front(25)
    extern SERVO servo_left_back(40)
    extern SERVO servo_right_back(25)
}
   delay_cycles(500);
}

return 0
}   




   








Title: Re: Why wont code compile?
Post by: agold on March 16, 2012, 08:37:46 PM
Umm, did you read through *all* of the posts carefully?

You don't seem to have made the changes mentioned, Gertlex said:
One thing I found right off is that you can't use while() like that. You need to put somethign in the parentheses... and it can just be while(1) for an infinite loop. (probably what you want)
However, if you're using WebbotLib, you need to use appControl which Webbot already said (though PD should be doing that for you if you're using it correctly)

You haven't fixed up what I said about not needing the type definitions. You did them in the if statement but nowhere else.

Also remember that almost every statement in C must end in a semi-colon (except while loops, for loops, switch cases and if statements). You've missed a fair few semi-colons

Adrian