Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: vidam on September 14, 2008, 04:27:46 PM

Title: Axon UART Protocol problem?
Post by: vidam on September 14, 2008, 04:27:46 PM
Hello,

My setup involves the Axon micro-controller, the Dimension Engineering Sabertooth speed controller, and 1 DC brushless motor.

I'm trying to control motor direction and speed via the Axon UART0 port and the Dimension Engineering Sabertooth speed controller in Simplified Serial Mode.

I am able to send only one command to the motors to initialize the speed and direction.

Code: [Select]
int main(void){

int left_side = 0;
int go_back = 45;
int go_forward = 90
int stop = 64;

uartInit();
rprintfInit(uart0SendByte);
uartSetBaudRate(left_side, 38400);
while(1){
uart0SendByte(go_forward);
delay_ms(60000); //delay 1 minute
uart0SendByte(stop);
delay_ms(60000); // 1 minute delay
uart0SendByte(go_back);
delay_ms(60000); // 1 minute delay
} // end while

return 0;

} // end main

The problem is that only the first command "go_forward" actually runs. The commands to stop and go_back are ignored. So this means the wheels are always turning forward at the same speed.

I tried restarting the program in "go_back" mode and the motors reverse but ignores the stop and go_forward command.

So it is like the sabertooth is *not* able to recogniize the Axon UART protocol.

Looking at the datasheet for the sabertooth in simplified serial mode it says the following:

"Simplified Serial operates with an 8N1 protocol – 8 data bytes, no parity bits and one stop bit."

Is the UART0 on the Axon not set up for 8N1 protocol?

I checked the baud rate and both devices are configured for 38400. So this is not the problem.

I also tried shorter delays like delay_ms(5000). That didn't work either.

in effect this means I have to download a new program to the Axon in order to change motor speed and direction.

I also tried to take take the code above out of loop and do it to do once and then finish but that didn't work either.

I tried changing to UART3 but I encounter the same issues.

I even have a spare Dimension Engineering Sabertooth that I tested. The same behavior occurs for both speed controllers. So I know there is nothing wrong with the speed controllers.

Can anyone help me, please? Is there a way to clear the buffer in between motor commands?

Thanks,

Melanie
Title: Re: Axon UART Protocol problem?
Post by: Ro-Bot-X on September 14, 2008, 06:29:14 PM
Melanie, I am not completly sure how delay_ms work in C, but in Arduino C the max value is 1000 (one second). If you need to delay for a minute, you should use a repeat 60 times one second loop to delay one minute. Your code sends the first serial command but then gets stuck with a overwhelming parameter and never gets to execute the second serial command.
Title: Re: Axon UART Protocol problem?
Post by: vidam on September 14, 2008, 06:38:51 PM
Ro-Bot-X,
I tried delay_ms(500) and delay_ms(5000).

Did not work either.

edit

Just for kicks I tried the following code:

Code: [Select]
int i=0;

uartInit();

rprintfInit(uart2SendByte);

uart2SendByte(go_forward);

while(i<10){i++;}

uart2SendByte(stop);
i=0;
while(i<10){i++;}

uart2SendByte(go_back);
i=0;
while(i<10){i++;}



I get the same issue. The motors stay in the go-forward mode. They never stop or reverse.
Title: Re: Axon UART Protocol problem?
Post by: Admin on September 15, 2008, 05:56:59 AM
Instead of 'go_forward', 'stop', and 'reverse', try using numbers.


Also, its a good idea to attach uart0 to Hyperterminal and see what it outputs.
Title: Re: Axon UART Protocol problem?
Post by: vidam on September 15, 2008, 06:12:11 AM
Instead of 'go_forward', 'stop', and 'reverse', try using numbers.


Also, its a good idea to attach uart0 to Hyperterminal and see what it outputs.

I tried using numbers instead of variables. Didnt work

How do I attach uart0 to hyperterminal? I'm using that USB to uart cable for hyperterminal.
Title: Re: Axon UART Protocol problem?
Post by: Admin on September 15, 2008, 06:28:28 AM
Use your serial to USB adaptor.
Title: Re: Axon UART Protocol problem?
Post by: airman00 on September 15, 2008, 07:54:03 AM
or perhaps have the USB uart be a "copy" of the uart you are using.

For example if your uart is outputing "1" then the USB uart  should also be transmitting "1"
Then just open up Hyperterminal( or Bray Terminal, my favorite ) and see whats really getting sent out
Title: Re: Axon UART Protocol problem?
Post by: vidam on September 15, 2008, 06:19:43 PM
Use your serial to USB adaptor.

Hyperterminal is showing a series of repeating
(P across the screen. It looks like this:

(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P
(P(P(P(P(P(P(P

Admin, could you explain your UART initialization routines?

Mike B on AVRFreaks posted a question that I do not know how to answer since i did not design the Axon.

Here you go Admin.

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=489478#489478

Title: Re: Axon UART Protocol problem?
Post by: vidam on September 15, 2008, 07:03:55 PM
or perhaps have the USB uart be a "copy" of the uart you are using.

For example if your uart is outputing "1" then the USB uart  should also be transmitting "1"
Then just open up Hyperterminal( or Bray Terminal, my favorite ) and see whats really getting sent out


Airman,

Tried it. No dice.
Code: [Select]
uartSetBaudRate(0, 38400);
uartSetBaudRate(1, 38400);

while(1)
{

rprintfInit(uart0SendByte);
uart0SendByte(80);
i=0;
while(i<120){i++;}
i=0;
rprintfInit(uart1SendByte);
uart1SendByte(80);
while(i<120){i++;}
i=0;
}


I'm still seeing the repeating characters

(P(P(P(P(P

Title: Re: Axon UART Protocol problem?
Post by: vidam on September 15, 2008, 07:48:27 PM
Airman and I realized the '(P' is 40 and 80 in decimal in the ASCII conversion table. The same byte commands I sent to the motors and the hyperterminal.

Airman and I also tried adding a carriage return after each motor command. From the ascii table that is decimal 13 for CR.

See the http://www.asciitable.com/

However this didn't cause the motors to recognize the commands. They still do not change speed or direction unfortunately.

Any other ideas out there?
Title: Re: Axon UART Protocol problem?
Post by: vidam on September 15, 2008, 08:57:58 PM
Many thanks --- Brijesh discovered the solution to the problem as to why the motors only turn one direction and speed.

In the code there needs to be a timer0Init();

This is to initialize TCNT0 such that delay_ms(500) might work.

Don't know why the while(i<1200000){i++;} didnt' work.

Oh well, I can move on to the next problem now.  :D

Here is the final code:

Code: [Select]
int main(void)
{

int go_back, go_forward, stop;
go_back = 45;
go_forward = 80;
stop = 64;

uartInit();
uartSetBaudRate(0, 38400);

timer0Init(); // very important to initialize timers

while(1) {

rprintfInit(uart0SendByte);
uart0SendByte(go_forward);
delay_ms(500);
delay_ms(500);
delay_ms(500);

rprintfInit(uart0SendByte);
uart0SendByte(stop);
delay_ms(500);
delay_ms(500);
delay_ms(500);

rprintfInit(uart0SendByte);
uart0SendByte(go_back);
delay_ms(500);
delay_ms(500);
delay_ms(500);

}//end while

return 0;

}//end main





Title: Re: Axon UART Protocol problem?
Post by: Admin on September 15, 2008, 09:32:13 PM
Quote
while(i<1200000){i++;} didnt' work
Your i was probably initialized as an int, meaning it can't go higher than 255.

Remember to *always* output with USB to debug your problem, even before posting here. You would have easily found the timing problem when you saw no delay in the output to hypterminal ;)
Title: Re: Axon UART Protocol problem?
Post by: vidam on September 16, 2008, 05:50:05 AM
Quote
while(i<1200000){i++;} didnt' work
Your i was probably initialized as an int, meaning it can't go higher than 255.

Remember to *always* output with USB to debug your problem, even before posting here. You would have easily found the timing problem when you saw no delay in the output to hypterminal ;)

ok