Society of Robots - Robot Forum

Software => Software => Topic started by: MtnbikerET on March 24, 2011, 09:20:49 PM

Title: Controlling the Axon II via UART
Post by: MtnbikerET on March 24, 2011, 09:20:49 PM
Basically, I am trying to control a two wheeled one armed robot via basic serial commands (forwards, backwards, etc). I can't figure out how to use the serial commands that come with webbotlib.
Here is part of my current non-working code:
Code: [Select]
#include "hardware.h"
#include "stdbool.h"

#define CMD UART0

bool waitForArmValue; //After 'A' is typed, it waits for the arm position value
char currentCommand; //The current command character
int rightCommandValue=128, leftCommandValue=128, armCommandValue=128; //These values are used to control servos. They range from 0 to 255
// Initialise the hardware
void appInitHardware(void) {
initHardware();
uartSetBaudRate(UART0, (BAUD_RATE)9600); //I think this is where you put this
uartSetBaudRate(UART1, (BAUD_RATE)9600);
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

//UART
while(!uartReceiveBufferIsEmpty(CMD))
{
if(waitForArmValue)
{ //Waits for arm position
waitForArmValue=false;
armCommandValue=(int)uartGetByte(CMD);
uartFlushReceiveBuffer(CMD);
}
else
{
currentCommand=(char)uartGetByte(CMD); //Gets the current command character
if(currentCommand!='A')
{ //'A' is the arm command
if(currentCommand=='s') //Stop
{
leftCommandValue=128; //i know my servos are working fine
rightCommandValue=128;
}
else if(currentCommand=='f') //Forwards
{
leftCommandValue=255;
rightCommandValue=255;
}
else if(currentCommand=='b') //Backwards
{
leftCommandValue=0;
rightCommandValue=0;
}
else if(currentCommand=='l') //Left
{
leftCommandValue=0;
rightCommandValue=255;
}
else if(currentCommand=='r') //Right
{
leftCommandValue=255;
rightCommandValue=0;
}
uartFlushReceiveBuffer(CMD);
}
else
{
waitForArmValue=true; //Waits for the arm value
}
}
}

Any advice or code that I can implement into my own project would be very appreciated. I'm new to uart.
Thanks,
Evan
Title: Re: Controlling the Axon II via UART
Post by: Admin on March 25, 2011, 03:08:59 PM
Here is my ERP code:
http://www.societyofrobots.com/downloads/ERP_code_020110.zip (http://www.societyofrobots.com/downloads/ERP_code_020110.zip)

In it you'll find code to control your robot by UART using WebbotLib.