2

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

0 Members and 1 Guest are viewing this topic.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #30 on: March 01, 2009, 01:38:54 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.

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)

Ok I understand the arrays part. But what if I want to control the robot with the arrow keys instead of wasd, how would I do that. Also in Admin's video when he is not holding down the keys the robot stops, whereas with my code I just hit the key once and it keeps going through that function until I hit a different key. I tried to do what admin has going but it didn't work.
Code: [Select]
char cByte;

void control(void)
{
robot_stop();
while(1)
{
cByte=uart1GetByte(); //get byte from UART0 on the axon
{
if (cByte == 'w')
robot_forward();
if (cByte == 'a')
robot_left();
if (cByte == 'd')
robot_right();
if (cByte == 's')
robot_backward();
while (cByte == '-1')
robot_stop();
wheel_left(left_wheel);
wheel_right(right_wheel);

rprintf("L_Wheel:%d%d R_Wheel:%d%d\r\n",left_wheel, right_wheel);
delay_ms(50);
}
}

}
« Last Edit: March 01, 2009, 04:44:32 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #31 on: March 01, 2009, 07:46:07 PM »
My gripper code is different because I want it to hold its position. Here is the code for the ERP as in that video:

Code: [Select]
//remote controlled ERP code
char cByte;
rprintfInit(uart3SendByte);
while(1)
{
cByte=uart3GetByte(); //get byte from UART0 on the axon
if(cByte!=-1)//no new data
{
if (cByte == 'w')
{
wheel_left(400);
wheel_right(1100);
}
if (cByte == 's')
{
wheel_left(1100);
wheel_right(400);
}
if (cByte == 'd')
{
wheel_left(400);
wheel_right(400);
}
if (cByte == 'a')
{
wheel_left(1100);
wheel_right(1100);
}
if (cByte == 'o')
{
LED_on();
}
if (cByte == 'p')
{
LED_off();
}
delay_ms(25);
}
}

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #32 on: March 01, 2009, 08:22:28 PM »
That doesn't work. For some reason even when I don't call the movement functions they still follow the last one called, or maybe it's that the axon doesn't recieve the -1. Also, how could it recieve a -1 if it's supposed to store cByte as a character?

EDIT:
I added print cByte and when I'm not pressing a key it's either printing a space or absolutely nothing. Does that mean that I should say if (cByte!='')?
« Last Edit: March 01, 2009, 08:26:45 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #33 on: March 01, 2009, 08:32:43 PM »
Quote
That doesn't work. For some reason even when I don't call the movement functions they still follow the last one called, or maybe it's that the axon doesn't recieve the -1.
But it *does* work, my video proves it :P

Quote
Also, how could it recieve a -1 if it's supposed to store cByte as a character?
Hmmmm good question! I guess this line is completely useless, lol:
Code: [Select]
if(cByte!=-1)//no new data

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #34 on: March 01, 2009, 09:00:36 PM »
Quote
That doesn't work. For some reason even when I don't call the movement functions they still follow the last one called, or maybe it's that the axon doesn't recieve the -1.
But it *does* work, my video proves it :P

Hmmmm. Maybe it's because we are using different servos? I'm using modified hs-311s and I know it doesn't stop unless I call my stop function. If I just don't call a function, the servos follow the last function. So knowing that I tried making an integer, iByte, and setting that equal to cByte before the if statements. Then I printed it and saw that when I wasn't pressing a key it was 255. You know what, just look at the code.
Code: [Select]
char cByte;
int iByte;

void control(void)
{
robot_stop();
while(1)
{
cByte=uart1GetByte(); //get byte from UART1 on the axon
iByte=cByte;
if (cByte!='255')
{
if (cByte == 'w')
robot_forward();
if (cByte == 'a')
robot_left();
if (cByte == 'd')
robot_right();
if (cByte == 's')
robot_backward();
wheel_left(left_wheel);
wheel_right(right_wheel);
}
else
robot_stop();

rprintf("L_Wheel:%d%d R_Wheel:%d%d cByte:%c iByte:%d\r\n",left_wheel, right_wheel, cByte, iByte);
delay_ms(50);

}

}
The wierd thing is, it's not calling the stop function even though hyperterminal says that iByte =255

EDIT:
I changed up the code here:
Code: [Select]
cByte=uart1GetByte(); //get byte from UART1 on the axon
iByte=cByte;
if (cByte!='255')
to
Code: [Select]
cByte=iByte=uart1GetByte();
if (iByte!='-1')
and now iByte prints as -1 when no key is pressed, but it still doesn't work.
« Last Edit: March 01, 2009, 09:24:43 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: How to have computer communicate with Axon
« Reply #35 on: March 01, 2009, 10:28:32 PM »
But . . . your code isn't the code I sent you . . . why not just use my code?

also, this line:
Code: [Select]
cByte!='255'should be this:
Code: [Select]
iByte!=-1

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #36 on: March 02, 2009, 12:01:12 AM »
That's what I have in the edit, unless you meant don't add the ' ' around the -1.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: How to have computer communicate with Axon
« Reply #37 on: March 22, 2009, 07:38:52 PM »
How would I write a program on the computer that communicates via usb to the robot that isn't hyperterminal (using visual basic probably)?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots

 


Get Your Ad Here