Author Topic: How to have computer communicate with Axon  (Read 8445 times)

0 Members and 1 Guest are viewing this topic.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
How to have computer communicate with Axon
« on: February 11, 2009, 05:06:12 PM »
I want to be able to communicate to my axon through the computer kind of like airmans axon bluetooth led lights. I want to be able to control servos connected to the axon by pressing a button on the computer or something along those lines. I plan to connect the axon to the computer through a uart port and have code on the axon so that when it detects a byte across the rx of the uart, and then it will do some predefined function depending on what that byte is.
1. Do I need to use a seperate uart port from the one I use with the bootloader if I still want the bootloader to be on the axon?
2. What program would I use to communicate to it?
« Last Edit: February 14, 2009, 04:54:16 PM by Jdog »

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: How to have computer communicate to Axon
« Reply #1 on: February 11, 2009, 05:09:49 PM »
In my robot's code I have something like, I can press 'r' and it will reset the MCU, press 'h' and the robot will hold its position. I could post that code when I get home from work in a few hours.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #2 on: February 11, 2009, 08:01:39 PM »
I don't quite understand that so could I see the code?

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: How to have computer communicate to Axon
« Reply #3 on: February 11, 2009, 10:53:25 PM »
Declare this in your variable section:
Code: [Select]
u08 myReceivedByte;


this goes in your while loop
Code: [Select]
         if (uartReceiveByte(&myReceivedByte)) {
               // if there are bytes waiting on the serial port
               char inByte = uartGetByte(); // read a byte
               if (inByte == 'r') {
             //if that byte is the desired character
                    hold_position();       // stop the robot
                    delay_cycles(336000);  //two second wait delay
                    resetChip(5);       // reset the chip after waiting for the specified # of seconds
               } // end if
       if (inByte == 'h' ) {
             hold_position();
               }
          }  // end if
 


make sure you initialize and setup UART in your SoR_Utils


This is just an example of how to make characters call other functions in your code


« Last Edit: February 11, 2009, 10:55:57 PM by pomprocker »

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #4 on: February 12, 2009, 08:17:36 AM »
Why do I reset the chip?

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #5 on: February 12, 2009, 07:01:56 PM »
Also, how do I do it on the computer side? Would I have to write my own program, and if so what would I have to do for that? Also, do I have to use a different uart port?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate to Axon
« Reply #6 on: February 12, 2009, 08:42:35 PM »
Quote
Why do I reset the chip?
You don't, he was just showing an example . . . pomprocker has code that can reset the Axon simply by typing 'r'.

Quote
Also, how do I do it on the computer side?
open up Hyperterminal, connect to the Axon, type 'r', press enter, done. :P

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #7 on: February 12, 2009, 08:58:41 PM »
Ok now I understand. Do I have to use a different uart port than the one I use to bootload? Also, how do I initialize that uart port in sor_utils?
I also don't understand the variable
Code: [Select]
u08 myReceivedByte;Right now my code looks like this:
Code: [Select]
u08 myReceivedByte;
int servo_1=600;

void control(void)
{
while(1)
{
         if (uartReceiveByte(&myReceivedByte)) // if there are bytes waiting on the serial port
{
char inByte = uartGetByte(); // read a byte
if (inByte == 'r') //if that byte is the desired character
{
servo_1=300;
} // end if
       if (inByte == 'h' ) {
             servo_1=1000;
               }
          }  // end if
}
}

Is that kind of what ponprocker is saying?
« Last Edit: February 12, 2009, 09:19:51 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate to Axon
« Reply #8 on: February 12, 2009, 09:38:08 PM »
For your UART questions:
http://www.societyofrobots.com/axon/axon_function_list.shtml#uart
And yeap, you can use USB for doing this (the USB is also used for bootloading).

u08 just means 8 bit int

You're code should work, but will only send a single pulse to your servos so you won't see anything happen. Try controlling the LED instead to test your code.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #9 on: February 13, 2009, 09:57:07 AM »
What if I hold down the letter, then will the servo move?

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #10 on: February 13, 2009, 10:07:04 AM »
Also when I try to compile I get these errors:
../control.c:24: warning: passing argument 1 of 'uartReceiveByte' makes integer from pointer without a cast
../control.c:24: error: too few arguments to function 'uartReceiveByte'

I don't even know  where "uartrecievebyte" came from. You only talk about UARTgetbyte

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #11 on: February 13, 2009, 11:04:57 AM »
I found u08 uartReceiveByte(u08 nUart, u08* data);
in uart4.h. The error is saying that I haven't provided enough parameters but I don't even know how to fill those in.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: How to have computer communicate to Axon
« Reply #12 on: February 13, 2009, 11:16:16 AM »
The compiler gives you this indication of where to look:

Quote
../control.c:24: warning: passing argument 1 of 'uartReceiveByte' makes integer from pointer without a cast
../control.c:24: error: too few arguments to function 'uartReceiveByte'

Open up your control.c file and go to line 24, take a look at that line: are you passing enough arguments? Are those the expected arguments?
Going by the code you posted I'd say this is the line that's causing the error:

Quote
if (uartReceiveByte(&myReceivedByte)) // if there are bytes waiting on the serial port

As you can see the call to uartReceiveByte only gets one parameter, the &myReceivedByte - the "&" translates to "the address of" - that's a pointer. Looking at the error message, it adds up:

Quote
../control.c:24: warning: passing argument 1 of 'uartReceiveByte' makes integer from pointer without a cast

This is your first warning, it was expecting an integer, yet it found an pointer! It's making an integer out of the pointer but the compiler doesn't really like the situation.

You probably want to change your code to:

Quote
if (uartReceiveByte(1, &myReceivedByte)) // if there are bytes waiting on the serial port

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #13 on: February 13, 2009, 11:39:38 AM »
Quote
Also, how do I do it on the computer side?
open up Hyperterminal, connect to the Axon, type 'r', press enter, done. :P

I've got it programmed so that when I hit l the led turns on. But when I try to type l in hyperterminal it doesn't show up and nothing happens on the axon.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate to Axon
« Reply #14 on: February 13, 2009, 08:37:09 PM »
Please show us your code :P

I'd just do this:
Code: [Select]
temp=uart1GetByte();//returns -1 if no data present
if (temp == r)//if data received
        do_stuff();

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #15 on: February 14, 2009, 09:39:20 AM »
Right now this is my code:
Code: [Select]
u08 myReceivedByte;

void control(void)
{
while(1)
{
if (uartReceiveByte(1,&myReceivedByte)) // if there are bytes waiting on the serial port
{
char inByte = uart1GetByte(); // read a byte
if (inByte == 'l') //if that byte is the desired character
{
LED_on();
} // end if
if (inByte == 'o' )
{
LED_off();
}
}  // end if
}
}

But the problem I'm having is I can't even type anything into hyperterminal.
« Last Edit: February 14, 2009, 09:40:45 AM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate to Axon
« Reply #16 on: February 14, 2009, 11:11:31 AM »
Quote
But the problem I'm having is I can't even type anything into hyperterminal.
Yes you can, just type and its automatically entered :P

I assume your problem is that by default you don't have it displaying what you type.

go to:
File -> Properties -> Settings tab -> ASCII Setup button -> check 'Echo typed characters locally'

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate to Axon
« Reply #17 on: February 14, 2009, 11:28:55 AM »
Ok, I changed the code so now I have the LED thing working. This is my current code:
Code: [Select]
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'l') // if character received is l then
{
LED_on();
}
if (cByte == 'o')
{
LED_off();
}
}
}
Could I modify this code so I could control a servo with it?
« Last Edit: February 14, 2009, 11:44:19 AM by Jdog »

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #18 on: February 14, 2009, 04:55:35 PM »
I tried modding the code with negative results. Right now this is it:
Code: [Select]
long unsigned int servo_1=700;

void servo_right(void)
{
servo_1=280;
}
void servo_left(void)
{
servo_1=1119;
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'r') // if character received is b then
{
servo_right();
LED_on();
}
if (cByte == 'l')
{
servo_left();
LED_off();
}
}
}

The Led turns on and off when they're supposed to but the servo doesn't react. Anybody know why, and how to fix it?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #19 on: February 15, 2009, 02:36:06 AM »
Quote
The Led turns on and off when they're supposed to but the servo doesn't react. Anybody know why, and how to fix it?
That's because your code only sends one single PWM pulse per button push. But a servo needs to get the command once every ~20ms.

You need to set up your code so it still runs the servo if you didn't push anything.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #20 on: February 15, 2009, 08:54:49 AM »
I fixed it but I didn't do that. I forgot this line:
Code: [Select]
servo_1(servo_1);I'm not sure what you're talking about but it works this way.

Offline Wizzard

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: How to have computer communicate with Axon
« Reply #21 on: February 15, 2009, 01:35:52 PM »
Thank you_Thank you_Thank you


void control(void)
   {
   while(1)
      {
      char cByte = uart1GetByte(); // get byte from UART1 on the axon
      if (cByte == 'r') // if character received is b then
         {
         servo_right();
         LED_on();
         }
      if (cByte == 'l')
         {
         servo_left();
         LED_off();
         }
   }
}

The Led turns on and off when they're supposed to but the servo doesn't react. Anybody know why, and how to fix it?

Seeing the above code (even though it did not do all you wanted) was exactly what I needed including all the right Brackets in the right places after I loaded my version of it to my Axon I think I startled the other people in the room when I mashed a key in Hyper term and that little Green light went on and I jumped up and yelled.

Thanks again for Showing what you are doing.

Wizzard

Offline Wizzard

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: How to have computer communicate with Axon
« Reply #22 on: February 15, 2009, 06:41:50 PM »
Jdog,

I used some of your code in the following and added a little feedback to the port. One issue I have is that I have to send the c 2 times to get the servo to center or move at all. while the led on and off work with a single character. The feedback works fine on every character sent. Any ideas??

Code: [Select]
void control(void)
{
//photovore();//run photovore algorithm, or comment out for your own code
while(1)
{

char cByte = uart1GetByte(); // get byte from UART1 on the axon

if (cByte == 'y') // if character received is "y" then
{
LED_on(); // turn on the green led
rprintf("\r\n Led on \r\n"); //send Led on to the USB port
}

if (cByte == 'c') // if it is "c"
{
servo(PORTA,7,700); // center the servo on port a7
delay_ms(20); // and pause for 20 milliseconds before repeating
rprintf("\r\n A7 centered \r\n"); //send A7 centered to the USB port
}

if (cByte == 'n') // if it is "n"
{
LED_off(); // turn off the green led
rprintf("\r\n led not on \r\n"); //send led not on to the USB port
}
}
}

Thanks Wizzard

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #23 on: February 16, 2009, 07:00:29 AM »
Jdog,

I used some of your code in the following and added a little feedback to the port. One issue I have is that I have to send the c 2 times to get the servo to center or move at all. while the led on and off work with a single character. The feedback works fine on every character sent. Any ideas??

Hmm, that is very odd. I honestly have no idea why it wouldn't work with just 1 press of 'c'.
Thanks again for Showing what you are doing.

Wizzard
Your welcome :).

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: How to have computer communicate with Axon
« Reply #24 on: February 16, 2009, 08:02:39 AM »
One thing to note about the UART thing

the uart0GetByte will return a -1 if no byte is received. I like to use this code to receive a byte:

Code: [Select]
int GetByte(void) {

//Syntax is variable= GetByte(); where variable is any variable capable of storing a byte

while((UCSR0A&(1<<RXC0)) == 0); // wait until a byte is received

return UDR0; // once a byte is received send back to the program the byte

}
// Just change the 0 of USCR0A, RXC0, and UDR0 to your UART port number
It does a 'while' loop until a byte is received.
« Last Edit: February 16, 2009, 08:03:33 AM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #25 on: February 28, 2009, 12:03:54 PM »
Using basically the same code as before I have my robot wired up to move with the wasd keys. I was wondering how I would do it with the arrow keys because you can't actually type the arrow key into avr studio or hyperterminal. Any ideas? Also I was wondering if there was a way to pass an array to the axon.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: How to have computer communicate with Axon
« Reply #26 on: February 28, 2009, 12:44:46 PM »
You can learn Visual Basic, create a computer program that can read whatever keystrokes you want and output them (including arrays) to the Axon.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #27 on: March 01, 2009, 12:50:55 AM »
You can learn Visual Basic, create a computer program that can read whatever keystrokes you want and output them (including arrays) to the Axon.
How would you have the axon receive an array from the computer.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #28 on: March 01, 2009, 01:06:38 AM »
You can learn Visual Basic, create a computer program that can read whatever keystrokes you want and output them (including arrays) to the Axon.
How would you have the axon receive an array from the computer.
code here:
http://www.societyofrobots.com/axon/axon_function_list.shtml#uart
(the part that mentions GPS and Blackfin)

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #29 on: March 01, 2009, 02:48:22 AM »
I just put up this video, maybe someone will find it useful!

[youtube]Rgjo_33rH0Y[/youtube]

 


Get Your Ad Here

data_list