viernes, 16 de octubre de 2015

qt c++ based - serial communications MeArm robotic arm controller

Sebastian Wolter
16-10-2015

Good morning everyone
This is my first publication so is very special because of that, and y hope to be clear in the explanations and to be able to help others which are starting into this fascinating arduino based electronics and robotics, which also covers some of C++ programming.

Today i will present a very little and simple QT C++ based program to control the OpenSource MeARM robotic Arm using serial communications library.





The MeARM sources and build instructions can be found in the following link:

Instructables - MeARM

Once your arm has been fully assembled and tuned for free proper motion, you need to wire it all agains your arduino board, which in my case is an Arduino UNO.

The next image shows the wiring between the meArm and the Arduino Board:




Base Servo connects to pin 11
Left Servo connects to pin 10
Right servo connects to pin 9
Claw servo connects to pin 6

You can also make the use of an arduino sensor shield to facilitate conections, if you can get one is ok.

Once you have everything wired, you have to upload the arduino sketch to the arduino board, the following is the arduino sketch code used:


#include <Servo.h>

//MeArm HAS 4 SERVOS
Servo xServo;  // create servo object, arm base servo - left right motion
Servo yServo;  // create servo object, left side servo - forward backwards motion
Servo zServo;  // create servo object, right side servo - forward backwards motion
Servo clawServo;  // create servo object, end of arm srevo - open,close the claw hand

//servo positions values, expects 1-180 deg.
int xPos;
int yPos;
int zPos;
int clawPos;

//*************** INIT AT STARTUP *******************************************************************

void setup() {        // the setup function runs once when you press reset or power the board

  // assign servo to pin numbers
  xServo.attach(11);  // attaches the servo on pin 11 to the servo object
  yServo.attach(10);  // attaches the servo on pin 10 to the servo object
  zServo.attach(9);  // attaches the servo on pin 9 to the servo object
  clawServo.attach(6);  // attaches the servo on pin 6 to the servo object

  // initialize serial port
  Serial.begin(9600);

  // Debug only send serial message to host com port terminal window in Arduino IDE
  //Serial.print("*** MeCom Test V04 ***.");   // send program name, uncomment for debug connection test

xServo.write(90);
yServo.write(90);
zServo.write(90);
clawServo.write(90);

}

// ******************************************************************************************************
// ********************************** MAIN PROGRAM LOOP START *******************************************
// ******************************************************************************************************


void loop() {
  //serial in packet patern = xVal,yVal,zVal,clawVal + end of packet char 'x'
  while (Serial.available() > 0) {
    xPos = Serial.parseInt();
    yPos = Serial.parseInt();
    zPos = Serial.parseInt();
    clawPos = Serial.parseInt();
   
    if (Serial.read() == 'x') { // Detect end of packet char 'x', go ahead and update servo positions
      // UPDATE SERVO POSITIONS
      xServo.write(xPos);
      yServo.write(yPos);
      zServo.write(zPos);
      clawServo.write(clawPos);
    }
  }
}


 sketch code can be downloaded here:  sketch ino

The arduino Sketch was not written by myself, it came along with the MeArm kit i bought from amazon.

The Sketch expects to receive a formatted string with a special character 'x' denoting the end of the string, as follows:

xPos,yPos,zPos,clawPosx

Which could be something like this:

90,90,90,40x

Last character 'x' tells the program the end of the string and to write down the vlaues to the corresponding servo motors.

In my particular case i have found that the claw fully opens and closes between 10 and 40 degrees positions in the servo, being 40 fully closed and 10 fully open, so this can be different in your own arm, you can easily modify the sketch to accomplish your particular setting in the following line:

clawServo.write(90);

And put it according to your arm claw close position, like this:

clawServo.write(40);

Final step is to open the QT project, i used QT with MinGW (gc++), the following version:


Which can be downloaded from here -> http://www.qt.io/download-open-source/#section-2

Once QT is installed, we may open the project: QT project Source



The program basically has 4 sliders to control each one of the servos, as stated before my particular claw setting are from 10 to 40 degrees only on Claw Servo, you can modifiy the program to suite your desing.


Once you run the program:


 Remember to connect your arduino board using the usb cable to your computer and select the correct COM port to use the applications.
The application is an in-progress work, but the basic arm functions are working great.

Hope it can help somebody.........



Sebastian Wolter
Octubre 2015

No hay comentarios.:

Publicar un comentario