Interfacing a robot arm with C++ in linux.

Asked By 260 points N/A Posted on -
qa-featured

Hi,

I recently built a Robotic Arm to move objects by human Control. The model was fine and effective. So my new partner who is an Image Processing expert wants to work as a team to expand it.

The problem is, he is on Linux. I don’t know much of Linux. So is there any way I can interface the controller with a PC running Linux, using C++?

The current design uses a small keypad, having 12 keys to control the arm(8) to move (4) to up/down/hold/leave . Each of them generating a 8 bit signal. All I need is to generate the signal from a PC rather than a Controller pad.

What is the method for these? Google doesn’t seem to help much. I would prefer C++, as my partner has better Image Processing experience in C++.

SHARE
Best Answer by softwaresynthesis
Answered By 0 points N/A #91981

Interfacing a robot arm with C++ in linux.

qa-featured

If you want to use USB, then the option is libusb.  But as you described the Controller and how you use the bit pattern to control the arm, I guess the most easiest and almost ready solution to your problem is by using a parallel port.

In GCC linux the function is outb(data,portaddress).  

Parallel port address is 0x378.

Note: You may have to set permission from the program, to control the port. And don't forget to revoke them after program exits.

Answered By 260 points N/A #91982

Interfacing a robot arm with C++ in linux.

qa-featured

Thanks for the sharp answer. I am going through the Documentation of LIBUSB but it seems that it would take time. Can you give me a short intro?

By the way, if it is easier to implement parallel port then it would be fine. I just need it badly, within this week.

Best Answer
Best Answer
Answered By 0 points N/A #91983

Interfacing a robot arm with C++ in linux.

qa-featured

If you don't have much time,  I guess you should go for parallel port.

Here is some code snippet to help you start up:


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>
#define BASEPORT 0x378 /* lp1 */
#define DELAY 1000000 /* lp1 */

using namespace std;

void init()
{
    int tem;
    //set permissions to access port
    if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
    tem = fcntl(0, F_GETFL, 0);
    fcntl (0, F_SETFL, (tem | O_NDELAY));
    }

void kill()
{

    int tem;
    fcntl(0, F_SETFL, tem);
    outb(0, BASEPORT);
    //take away permissions to access port
    if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
}

int a_function_to_move_motor() {
    init();
    // Do your port control here
    kill();
    return 0;
}

Answered By 260 points N/A #91984

Interfacing a robot arm with C++ in linux.

qa-featured

Thanks a lot, but I still have  a problem. I am using this to test:


void push(int pulse)
{
    for(int j=0;j<pulse*4;++j)
    {
        //write 'on' bit on all data pins and wait 1/4 second
        outb(00001011, BASEPORT);
        usleep(DELAY);
    }
        //write 'off' bit on all data pins and wait 1/4 second
    cout<<"nn";
    outb(00000000, BASEPORT);
    usleep(DELAY);
}

It's not giving an appropriate output as expected.

Answered By 0 points N/A #91986

Interfacing a robot arm with C++ in linux.

qa-featured

The outb() function takes an integer not binary. So you have to convert it first.

1011 becomes 11

1111 become 15.

Answered By 260 points N/A #91987

Interfacing a robot arm with C++ in linux.

qa-featured

Thanks synthesis.  Problem solved!!

That was quick.

Answered By 0 points N/A #91989

Interfacing a robot arm with C++ in linux.

qa-featured

You are most welcome.

Related Questions