go_away

Author Topic: Why wont code compile?  (Read 941 times)

0 Members and 1 Guest are viewing this topic.

Offline mr robotoTopic starter

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 0
Why wont code compile?
« 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
}   




   








I once though that my brain was the most wonderful part of my body. then i realized who was telling me this

"A question that sometimes drives me hazy, am i or are the others crazy"?
 Albert Einstein

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 744
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Why wont code compile?
« Reply #1 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)
« Last Edit: March 03, 2012, 03:33:52 PM by Gertlex »
I

Offline agold

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 1
Re: Why wont code compile?
« Reply #2 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

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 110
Re: Why wont code compile?
« Reply #3 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
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline mr robotoTopic starter

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 0
Re: Why wont code compile?
« Reply #4 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.

I once though that my brain was the most wonderful part of my body. then i realized who was telling me this

"A question that sometimes drives me hazy, am i or are the others crazy"?
 Albert Einstein

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 110
Re: Why wont code compile?
« Reply #5 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 - although if your using Project Designer then it automatically does all the #includes for you.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline mr robotoTopic starter

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 0
Re: Why wont code compile?
« Reply #6 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
}   




   








I once though that my brain was the most wonderful part of my body. then i realized who was telling me this

"A question that sometimes drives me hazy, am i or are the others crazy"?
 Albert Einstein

Offline agold

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 1
Re: Why wont code compile?
« Reply #7 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

 


Get Your Ad Here

data_list