Society of Robots - Robot Forum

Software => Software => Topic started by: Mastermime on November 09, 2012, 04:58:53 PM

Title: Help With Basic Directional Coding
Post by: Mastermime on November 09, 2012, 04:58:53 PM
Hello everyone,

First I want to premise that I am a complete newbie at coding and this is the first time I've coded a project not in the Arduino IDE. 

I am trying to write some simple directional code that I can test my tread configuration, but of course this will be the code I am going to use for my robot.  Here is my flow "data of transfer".  PS2 controller > Arduino > Xbee Pro > Xbee Pro > Axon > Electronics

I've used Webbotlib and a source file from Admin and then done a bit of editing myself.  With the code I have, how can I modify it/ add to it in order to get this to function properly.  I can write the program on the Arduino side.  Its the Axon I have trouble with.  If someone would be willing to help, I'd be more than grateful. 

Thanks

Code: [Select]
//C file using Axon, Xbee, and Sabertooth

#define Xbee_controlled


//WebbotLib includes
#include "sys/axon2.h" //defines your MCU (change to axon.h if you use the original Axon)
//#include "servos.h" //use for software servo PWM
//#include "a2d.h" //use for ADC
#include "rprintf.h" //use for UART

//user includes
#include "hardware.h"
#include "led.h"
#include actuators.h

// In my initialising code - pass the list of servos to control
void appInitHardware(void)
{
//initialize UART ports (see hardware.h to change baud/names)
uartInit(Xbee,9600); //UART0
uartInit(USB_UART, USB_BAUD); //USB
pin_make_output(L6,true);

// declare USB for output
#ifdef USB_controlled
rprintfInit(USB_ACTIVATE);
#endif
#ifdef Xbee_controlled
rprintfInit(WIRELESS_ACTIVATE);
#endif

//Initialise motor controller
sabertoothInit(&sabertooth);

led_off();//clear display
}

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
rprintf("\nAxon Initiated.\n\n");
return 0;
}

int tempbyte;

//vehicle speed
DRIVE_SPEED speed=30;
DRIVE_SPEED turn=80;

//define directions
void go_left(void)
{
act_setSpeed(&left,-turn);
act_setSpeed(&right,turn);
}

void go_right(void)
{
act_setSpeed(&left,turn);
act_setSpeed(&right,-turn);
}

void go_straight(void)
{
act_setSpeed(&left,speed);
act_setSpeed(&right,speed);
}

void go_reverse(void)
{
act_setSpeed(&left,-speed);
act_setSpeed(&right,-speed);
}

void stop_dumb_robot(void)
{
act_setSpeed(&left,0);
act_setSpeed(&right,0);
}


// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart)
{
#ifdef USB_controlled
tempbyte=USB_GET;//get a single character
#endif
#ifdef Xbee_controlled
tempbyte=WIRELESS_GET;
#endif

//control direction
if (tempbyte=='a')
go_left();
else if (tempbyte=='d')
go_right();
else if (tempbyte=='w')
go_straight();
else if (tempbyte=='x')
go_reverse();
else if (tempbyte=='s')
stop_stupid_robot();

//control speed by < and >
if (tempbyte==',')
{
speed-=10;
if (speed < 0)
speed=0;
rprintf("\nspeed=%d ",speed);
}
if (tempbyte=='.')
{
speed+=10;
if (speed > 100)
speed=100;
rprintf("\nspeed=%d ",speed);
}

return 2000; // wait for 2ms
}
Title: Re: Help With Basic Directional Coding
Post by: Admin on November 11, 2012, 08:17:32 AM
It looks fine to me on a quick glance. Did you try it?
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 11, 2012, 10:37:20 PM
When I try and compile in AVR Studio, I receive 30 errors saying that a term is undeclared (first use in this function').  I dont understand why this happening because I included the Webbotlib library in my AVR folder.
Title: Re: Help With Basic Directional Coding
Post by: Admin on November 12, 2012, 09:15:56 AM
Carefully go over the Getting Started instructions once more. 99% of those who have this problem missed a step.

And if still no luck, post the error messages you are getting.


btw, in your code, what is the difference between 'stop_stupid_robot();' and 'stop_dumb_robot();' ? ;)
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 12, 2012, 09:39:09 AM
Quote
stop_stupid_robot();' and 'stop_dumb_robot();

lol you caught me.  ;D
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 12, 2012, 11:41:04 AM
I just looked at the 'Getting Started' tutorial again and I noticed I clicked 'Build' instead of 'Rebuild all'.  Could that have been my issue?  Or did I name my files incorrectly?
Title: Re: Help With Basic Directional Coding
Post by: Admin on November 12, 2012, 12:53:19 PM
I just looked at the 'Getting Started' tutorial again and I noticed I clicked 'Build' instead of 'Rebuild all'.  Could that have been my issue?
nope

Quote
Or did I name my files incorrectly?
possibly :P
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 12, 2012, 05:11:26 PM
Ok I don't know what's going on.  I tried tinkering with it, but got nowhere.  I know it has something to do with the solutions explorer, but I just don't know what.  This is starting to get frustrating  >:(
Title: Re: Help With Basic Directional Coding
Post by: Admin on November 12, 2012, 10:08:37 PM
Looking at your screenshot, it's dead obvious you didn't follow the Getting Started instructions. :P

Let's start at the top . . . you have a folder named ERA, which has a folder named ERA inside of it, then it appears you put WebbotLib in that, and then your main file is called actuators.h - but it should be a .c file named ERA.c.

Next, variables such as 'left' and 'right' aren't defined, telling me that you didn't use Project Designer.

Start over, and follow the instructions *exactly* as written. Then compile the code without making any modifications to verify you did it right. :P
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 13, 2012, 06:51:36 PM
Sorry about that Admin.  I thought that I could just use your files and edit them a bit to my specs.  I guess not.

Anyways, I went through the getting started process again and received this error
Quote
make: *** No rule to make target `../lib/libWebbot-ATmega640.a', needed by `ERA3.elf'.  Stop.
I've searched the error and found a couple of foggy solutions, but none that are clear.. I checked the names of all my files and everything appears to be correct, so obviously it has to with the makefile, which is attached so you guys can read it.
Title: Re: Help With Basic Directional Coding
Post by: Mastermime on November 18, 2012, 01:44:40 PM
I solved my issue.  The problem was that initially I dragged the files instead of extracting them out the zip file