Author Topic: Pc Interfacing with a Axon  (Read 4220 times)

0 Members and 1 Guest are viewing this topic.

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Pc Interfacing with a Axon
« on: May 11, 2011, 10:17:55 AM »
Im looking at taking my axon and connecting it to a laptop so i can build a robot that has on board visual processing. Dose any one know the best way to connect them? Also what kind of parts/programming software would i need? Thank you

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Pc Interfacing with a Axon
« Reply #1 on: May 11, 2011, 12:40:00 PM »
This question gets asked a lot...and it depends on a lot of stuff.  I assume that the setup is like this:

CAMERA -> PC -> Axon -> PC

and not like this:

Camera -> Axon -> PC -> Axon (which would drastically limit how good a camera you can use...)

Ultimately, it's just UART and serial port programming.  It depends entirely on the programming language you're using.  I did it in C#, but it's all handled in buffers (both on the Axon and on the PC), so the language itself is irrelevant.

Since you probably have the programming cable for the axon, you have sufficient hardware.  Start with making this program:

ON THE PC:

Open a serial port that is attached to the Axon
write a string of bytes to the serial port
LOOP:
wait for the axon to respond by listening on the serial port
print the axon's output to the screen

ON THE AXON:

LOOP:
Check if the UART has new data
print the data back to the PC

Once you can do that you can do anything with serial communications.  If you want code, and are doing this in C# (and using webbotlib),  I can provide it.

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #2 on: May 11, 2011, 02:24:00 PM »

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #3 on: May 11, 2011, 06:15:02 PM »
What kind of laptop should I use. I have a toshiba with 3 usb ports at home. Would that work as my computer. Keep in mind I want to build a pc based robot overtime.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #4 on: May 11, 2011, 06:24:13 PM »
Expect your robot to run into walls and jostle your harddrive (very bad).

You want a laptop that can take a lot of shock without breaking (read reviews), is very light weight, and a battery lifetime of 2+ hours. At least 2 USB ports, one for webcam and one for your Axon.

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #5 on: May 11, 2011, 06:31:04 PM »
Would I need only one axon or 2 if I want the axon to control the drive train sensors and arms of the robot. Also head tilting will be part of it.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #6 on: May 11, 2011, 06:39:23 PM »
Just one is needed for that (and it can do plenty more, so no worries).

(but I encourage you to buy many :P)

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #7 on: May 11, 2011, 06:52:04 PM »
Ok then my current laptop should be enough because ill be trying stereo vision so ill have two cameras and the axon all connected to it.

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #8 on: May 13, 2011, 04:24:19 PM »
Mstacho I do plan on using webbot. As for language I can use c#. If you would be kind to share your code I would be very happy to give credit to you. Thankyou for the help.

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Pc Interfacing with a Axon
« Reply #9 on: May 14, 2011, 06:45:27 AM »
No problem.  I'm at home right now and it's saturday, and all my code is at work, so it might have to wait until Monday :-P But I'll definitely upload it once i'm in the office.

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #10 on: May 14, 2011, 05:45:05 PM »
Once the axon is connected to the pc what kind of software should I use to run the camera and send commands to the axon? Would I use robo realm and microsoft robotics studio together. Or do you do you have suggestions for doing this.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #11 on: May 14, 2011, 06:30:16 PM »
Just RoboRealm is fine.

Microsoft Robotics Studio doesn't really do anything other than have 'robot' in it's name . . . even when they give it away for free no one wants it. :P

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #12 on: May 14, 2011, 06:43:42 PM »
Ok so roborealm process vidoe information and send commands to the axon? Will it send the commands to drive and take information from the axon like sensor input. Im planing on useing it to build a pc based robot.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #13 on: May 14, 2011, 09:16:52 PM »
Ok so roborealm process vidoe information and send commands to the axon? Will it send the commands to drive and take information from the axon like sensor input. Im planing on useing it to build a pc based robot.
You can really have it to whatever you want.

http://www.roborealm.com/help/SOR_Axon.php

Offline KylepowersTopic starter

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Pc Interfacing with a Axon
« Reply #14 on: May 14, 2011, 10:11:48 PM »
after reading that i see it can control the servos for the axon but what about sensor input and motors?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Pc Interfacing with a Axon
« Reply #15 on: May 15, 2011, 05:53:18 PM »
You can have RoboRealm output whatever you want by serial to the Axon, and the Axon can also send data to RoboRealm for use. You'll have to read the docs on the RoboRealm site for more info, but for the Axon side just use the USB control demo code.

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Pc Interfacing with a Axon
« Reply #16 on: May 16, 2011, 07:17:40 AM »
As promised, this is the C# code that sends commands to the axon.  As you can see it's just as simple as writnig an array of Bytes.  In my case, I'm dealing with a two-motor robot finger with a force sensor at the tip. I'm sending the command: [MOTOR1, MOTOR2, FORCE], where MOTOR1 is the position of motor 1, MOTOR 2 is for motor 2, and FORCE is the force I want at the tip in case contact happens.  In another post I'll show my axon code.

Code: [Select]
using System;
using System.Threading;
using System.IO.Ports; //Where you find SerialPort
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HandMainProgram
{
    class Program
    {
        static void Main(string[] args)
        {

           
            Console.WriteLine("Hit enter to start");
            Console.ReadLine(); //Don't start immediately, as the Axon/Hand may not yet be powered
           
            //Prepare the serial port
            SerialPort serialPort1 = new SerialPort();

            //Have to initialize on my own here
            serialPort1.BaudRate = 115200;
            serialPort1.DataBits = 8;
            serialPort1.Parity = Parity.None;
            serialPort1.StopBits = StopBits.One;
            serialPort1.PortName = "COM3"; //My COM port is COM3.  Others may have different COM ports.

            //This just makes sure that no other program does something to break mine
            if (serialPort1.IsOpen)
                serialPort1.Close();
            serialPort1.Open();

            //Generate the command array
            Byte[] ST = new Byte[3];
            int d = 0;
            ST[2] = 125;
            ST[1] = 0;
            ST[0] = 0;
            serialPort1.Write(ST, 0, 3); //send the whole array

            System.Threading.Thread.Sleep(2000); //Not strictly necessary, but if you want to send multiple    //commands you might need to sleep
           
            Console.WriteLine("All commands were sent.  Hit ENTER to close the program");
            Console.ReadLine();
            serialPort1.Close();
           
        }

[\code]
Current project: tactile sensing systems for multifingered robot hands

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Pc Interfacing with a Axon
« Reply #17 on: May 16, 2011, 07:22:15 AM »
And here's the axon code. Sorry it's so long, but the read code is sort of useless without the actions that it does.  What you're most interested in is how I initialize the UART and how I read from it (the reading actually happens in the last 10 lines).  The rest of the code is showing how to integrate the data that we've read into a real program.  If I wanted to SEND from the UART, I'd just rprintf the array of Bytes, and read in C#.

I'd be happy to explain this code in more detail :-P I DID write it for myself, so I probably know what's going on way better than anyone else.  Also, as a disclaimer, I make no claims that this is the BEST way to do this, but it does work really well.

Code: [Select]
//These next two lines setthe UART transmit and receive buffer size.
#define UART_TX_BUFFER_SIZE 80
#define UART_RX_BUFFER_SIZE 80

#include "sys/axon.h" //always needed
#include "uart.h"
#include "rprintf.h"
#include "pwm.h"
#include "pid.h"
#include "a2d.h"
#include "iopin.h"
#include "Sensors/Encoder/Generic/quadrature.h" //the quadrature encoder

 //Make the encoder
QUADRATURE quad1 = MAKE_GENERIC_QUADRATURE(K1,E3,false,1368,false); //reads from H3 and H4
QUADRATURE quad2 = MAKE_GENERIC_QUADRATURE(K0,E2,false,1368,false); //the top motor
PID bottomPID = MAKE_PID(2.5,0,1,0,-100,100); //bottom motor PID
PID topPID = MAKE_PID(2.0,0,1,0,-100,100); //top motor PID
PID forcePID = MAKE_PID(2.25,0,1,0,-100,100); //PID for the forces
//So what the PID code does: MAKE_PID(KP,KI,KD,MAXINTEGRATE,outMin,outMax)

/*
Now, webbot works in a slightly odd way.  There is no MAIN function,
that is included in the library.  So you have three functions you
have to have in your code.  These are below.
*/


//
//This is called only once, and is used to set up any hardware
void appInitHardware(void)
{
//set UART1 to 115200 baud
uartInit(UART1,115200);

//tell rprintf to output to UART1
rprintfInit(&uart1SendByte);

//initialize
encoderInit(quad1);
encoderInit(quad2);

//I guess we initialize PWM here?
pwmInitHertz(H6,1000,0,null); //bottom motor
pwmInitHertz(H3,1000,0,null); //top motor
//
}

//This is also called once.  It is used to set any software variables
TICK_COUNT appInitSoftware(TICK_COUNT loopStart)
{

return 0; //we're not doing much right now
}

//This is called repeatedly, and it is the main function.
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart)
{
float enc1 = 0.; //bottom motor
float enc2 = 0.; //top motor
int forPos = 0; //position is 0, force is 1
int reBy = -10; //the byte we're reading from the UART
float instructions[3]; //the array of instructions (needs to be more general, but w/e)
int count = 0;

pin_make_output(H4,false); //top motor direction
pin_make_output(H5,false); //bottom motor direction


//
//ultimately, if we read nothing from the UART, we do the actual code here
if(uartReceiveBufferIsEmpty(UART1))
{
//read the encoders
encoderRead(quad1);
encoderRead(quad2);
//set the encoder stuff anyway.
enc1 = pidSetActual(&bottomPID,quad1.encoder.value);
enc2 = pidSetActual(&topPID,quad2.encoder.value); //for position control

pin_low(H5);
pin_low(H4);

//check the force threshold
if(a2dConvert8bit(3) > 75)
forPos = 1;

if(forPos == 1)
{
enc1 = pidSetActual(&forcePID,a2dConvert8bit(3));
enc2 = pidSetActual(&forcePID,a2dConvert8bit(3));
}

if(enc1 < 0)
{

if(forPos == 0)
{
//we're doing position control
pin_high(H5);
enc1 = -enc1;
}
else
{
//For force control, the bottom PID cannot go negative
enc1 = 0;
}
}
if(enc2 < 0)
{
pin_high(H4);
enc2 = -enc2;
}


pwmSetDutyCycle(H6,(int)enc1); //bottom motor
pwmSetDutyCycle(H3,(int)enc2); //top motor

}
else //the UART has something to say
{
//Now it's time for PID set points
reBy = uartGetByte(UART1);
while(reBy >= 0) //don't forget that "=", or else you can't send a position of zero...apparently
{
instructions[count] = (float)reBy;
count = count + 1;
reBy = uartGetByte(UART1);
}

{
pidSetTarget(&bottomPID,instructions[0]); //set the PID targets according to the message
pidSetTarget(&topPID,instructions[1]);
pidSetTarget(&forcePID,instructions[2]);

}

//flush the UART buffer
uartFlushReceiveBuffer(UART1);
}
return 10000; //wait for n uS before calling again.
//So the return statement is how you wait before it is called again.
}
[\code]
Current project: tactile sensing systems for multifingered robot hands

 

SMF spam blocked by CleanTalk