Software > Software

Help With Basic Directional Coding

(1/3) > >>

Mastermime:
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: ---//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
}

--- End code ---

Admin:
It looks fine to me on a quick glance. Did you try it?

Mastermime:
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.

Admin:
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();' ? ;)

Mastermime:

--- Quote ---stop_stupid_robot();' and 'stop_dumb_robot();
--- End quote ---

lol you caught me.  ;D

Navigation

[0] Message Index

[#] Next page

Go to full version