Society of Robots - Robot Forum
Electronics => Electronics => Topic started 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.
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
-
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.
-
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:
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.
-
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.
-
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.
-
Use your serial to USB adaptor.
-
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
-
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
-
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.
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
-
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?
-
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:
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
-
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 ;)
-
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