go_away

Author Topic: Controlling the Axon II via UART  (Read 1331 times)

0 Members and 1 Guest are viewing this topic.

Offline MtnbikerETTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Controlling the Axon II via UART
« 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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Controlling the Axon II via UART
« Reply #1 on: March 25, 2011, 03:08:59 PM »
Here is my ERP code:
http://www.societyofrobots.com/downloads/ERP_code_020110.zip

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

 


Get Your Ad Here