Author Topic: Help please, with coding errors.  (Read 904 times)

0 Members and 1 Guest are viewing this topic.

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 82
  • Helpful? 0
Help please, with coding errors.
« on: September 20, 2010, 11:08:14 AM »
I've been trying for weeks, now, to get my robot running the stampy code using a sharp IR, on my Axon2
I've already tried all the "pre-compiled" .hex files I can find with no success.
So I am trying to compile the individual files without using the included makefiles.
I get these errors and warnings

Code: [Select]
Build started 20.9.2010 at 17:48:23
avr-gcc -I"C:\Robotics\AXON2\My_New_Code\..\WebBtLib" -I"C:\Robotics\AXON2\My_New_Code\." 

-mmcu=atmega640 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=16000000UL -Os -funsigned-char -

funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Axon.o -MF dep/Axon.o.
d  -c  ../Axon.c

In file included from ../SoR_Utils.h:25,
                 from ../Axon.c:16:
../global.h:37:1: warning: "F_CPU" redefined
<command-line>: warning: this is the location of the previous definition
avr-gcc -I"C:\Robotics\AXON2\My_New_Code\..\WebBtLib" -I"C:\Robotics\AXON2\My_New_Code\." 

-mmcu=atmega640 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=16000000UL -Os -funsigned-char -

funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT control.o -MF dep/cont
rol.o.d  -c  ../control.c

../control.c: In function 'autocalibrate':
../control.c:49: warning: implicit declaration of function 'a2dConvert8bit'
../control.c: In function 'scan':
../control.c:80: warning: implicit declaration of function 'servo_scan'
../control.c: In function 'control':
../control.c:110: warning: implicit declaration of function 'rprintf'
../control.c:113: error: called object 'wheel_left' is not a function
../control.c:114: error: called object 'wheel_right' is not a function
../control.c:115: warning: implicit declaration of function 'delay_ms'
make: *** [control.o] Error 1
Build failed with 2 errors and 6 warnings...

And this is my control.c file

Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

//Add your code here

//global variables
int sharp_ir=0;//Here, we declare the variable sharp_ir and setting it's inital value to be 0.

int scan_thresh=50;//threshold value of scanning sensor

int scan_angle=1000;//position of scanner, in units of servo command
int max_scan_angle=1000;//maximum position scanner can rotate to (57)
long int wheel_left=600;//Here, we declare the variable wheel_left and setting it's inital value to be 600.
long int wheel_right=600;//Here, we declare the variable wheel_right and setting it's inital value to be 600.

void robot_right(void)//This function takes no parameters and returns no value hence the 2 voids.
{
wheel_left=500;
wheel_right=500;
}
void robot_left(void)//This function takes no parameters and returns no value hence the 2 voids.
{
wheel_left=800;
wheel_right=800;
}
void robot_straight(void)//This function takes no parameters and returns no value hence the 2 voids.
{
wheel_left=500;
wheel_right=800;
}
void robot_reverse(void)//This function takes no parameters and returns no value hence the 2 voids.
{
wheel_left=800;
wheel_right=500;
}
void autocalibrate(void)//rather than using a predefined scan threshold, you can use this so that the first reading the sharp_ir takes is set as the threshold.This function takes no parameters and returns no value hence the 2 voids.
{
scan_thresh=a2dConvert8bit(3);//sensor reading
}

void scan(void)//this function makes the sensor center on the left edge of an object.This function takes no parameters and returns no value hence the 2 voids.
{
//lower (-) goes left
//higher (+) goes right
//1000 far right, 700 straight, 300 far left (until it jams)

/*psuedocode
object is detected
scan right object detected
object not detected
scan left until object detected*/

sharp_ir=a2dConvert8bit(3);//read the analogue port 3 and it will be referred to as sharp_ir

if (sharp_ir > scan_thresh)//object detected
{
if (scan_angle>300) //overflow protection
scan_angle-=20;//scan left
}
else //object not detected
{
if (scan_angle<=max_scan_angle) //maximum servo angle
scan_angle+=20; //scan right
else
scan_angle=830;
}

//servo scan code
servo_scan(scan_angle);//this is where I am telling the code that when I say scan_angle, I really mean the servo that I defined in hardware.c
}
void control(void)//this is where I am defining my control function to be called by stampy_v2.c.This function takes no parameters and returns no value hence the 2 voids.
{
autocalibrate();
while(1)//This is what's called a while loop. If there is a 1 in between the parentheses it means that what is in the while loop will repeat forever.
{
scan();
//object on left and not too close
if(scan_angle < 600 && sharp_ir < 150)
{
robot_left();
}

//object on right and not too close
else if(scan_angle > 700 && sharp_ir < 150)
{
robot_right();
}
//object is centered and not too close
else if(sharp_ir < 150 && sharp_ir < 150)
{
robot_straight();
}
//object too close
else
{
robot_reverse();
}
//print data through usb to be read from hyperterminal
rprintf("Sharp_IR=%d, IR_Servo=%d%d, L_wheel=%d%d, R_wheel=%d%d\r\n",sharp_ir, scan_angle, wheel_left, wheel_right);

//these 2 things tell the code that wheel_left and wheel_right are the two servos that I defined in hardware.c
wheel_left(wheel_left);
wheel_right(wheel_right);
delay_ms(20);
}
}

Can someone please help?

I will add that I am very much an apprentice newbie.

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Help please, with coding errors.
« Reply #1 on: September 20, 2010, 11:48:45 AM »
Hi Kelpy.

What's in hardware.c?

Code: [Select]
wheel_left(wheel_left);
wheel_right(wheel_right);

It seems you are trying to call a function with the same name as a variable, which can't happen. What function are you trying to call here?

Also, you are trying to use some rather old code for the Axon (or Axon 2). The new standard to use is a library called Webbotlib. There's also a nice tool called Project Designer that let's you setup your project with all the code necessary to run your hardware, and gives you some examples on how to use the library functions.

I made a tutorial on how you use Project designer and Webbotlib.

Axon 2, Webbotlib and Project Designer Tutorial


So i would suggest scrapping what you have already and 'upgrading' to webbotlib. It's much more powerful then the code you are trying to use. IT wouldn't be that hard to port what you are trying to do to webbotlib.

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 82
  • Helpful? 0
Re: Help please, with coding errors.
« Reply #2 on: September 20, 2010, 12:01:54 PM »
Hi madsci1016, thanks for your reply.

I think you may be right for me to start with "a clean sheet". At least I know that the PD works and does all the hardware setting up for me.

This is the hardware.c

Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

/******define servo functions******/
//define electronics/motors/servos to specific hardware pins

#define servo_scan( position ) servo(PORTE,5,position)
#define wheel_left( position ) servo(PORTE,6,position)
#define wheel_right( position ) servo(PORTE,7,position)

/**********************************/


/***********define UART************/
/*int bluetooth=0;
int USB=1;
int uart2=2;
int black_fin=3*/

/**********************************/


/*********define positions*********/
/*long int arm_left_base=600;
long int arm_left_J1=600;
long int arm_left_J2=600;

long int wheel_left=600;
long int wheel_right=600;

long int camera_hor=600;
long int camera_ver=600;*/
/**********************************/

Cheers.

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Help please, with coding errors.
« Reply #3 on: September 20, 2010, 12:49:43 PM »
I think your original code was just missing a

Code: [Select]
#include 'hardware.c'
at the top, so the definitions were not coming through.
« Last Edit: September 20, 2010, 12:51:03 PM by madsci1016 »

 


Get Your Ad Here

data_list