Saturday 31 August 2013

E-GLOVE Part-2 -- The Robotic Arm !

E-GLOVE 'n' THE ROBOTIC ARM

The last time I blogged here, I wrote about my project on the e-glove and how my team and I got around to using the glove as a wireless air-mouse using an accelerometer and an RF Transceiver system. But, not stopping there, we decided to move on and try to use it for it's more serious applications, like bomb defusal, remote object manipulation and maybe, if we have access to more sensitive equipment, a robotic surgery arm.


The first step, obviously, was to acquire the arm. Being poverty stricken engineering students, we had no funds to actually purchase the arm itself, so we approached the BioMedical Instrumentation department of out college who graciously provided us with not one, but TWO unused robotic arms. Since one of them was pre-assembled, we decided to use that one for our current prototype.

The arm, manufactured by Arexx, actually has an inbuilt Atmega Processor and an FTDI USB-to-Serial converter to program and control the servos on the arm independently. However, upon further perusal of the documentation, kindly written in German for better understanding, I found out that the coding would have to be done in Assembly or hex. (English Version, FINALLY). This promptly made me drop the idea and decided to proceed by individually connecting each motor to the Arduino Leonardo and trying to use the Servo library which comes built-in with the IDE. Well, that went well and I could now manually control the arm using the WASD keys on the keyboard.I even ordered a Sony CP-ELS PowerBank for the arm, which is basically a 2200 mAh rechargeable battery that will finally allow for some portability.

The input for each of the 5 motors (actually, there are 6 but one is broken) came from an old USB cable connected to the GND and +5V pins of each motor using a simple splitter on a PCB which gave me 5 parallel outputs from one battery input.

Block Diagram of arm with motors labelled accordingly
Then, once I got that part working, we came to the main task at hand, making it compatible with the existing glove so that we could move it around using hand movements.

Then came the real problem. Turns out that the VirtualWire Library that we used (mentioned here) uses an interrupt based system to get the RF communication working. Now, the Servo library ALSO uses the same interrupts in the Arduino and thus, no matter what, they are incompatible. Which basically meant, that for the moment, our project was doomed.

Library after alternative library was tried, but to no avail. The ServoTimer2 library promised to be compatible with the VirtualWire library, but even that, as it turned out, did not work. We even tried editing the library itself (a huge undertaking on our part, since we didn't know crap about the internal hardware structure of the Arduino) and we got the thing to compile, but the arm remained motionless as ever.

Then, at 5:00AM one morning, with an 8:00AM class in the horizon, I decided to bunk all libraries and try moving the servos using simple and old-school PWM control. And voila, that did the trick. Taking inspiration from this tutorial, I proceeded to fine-tune the pulse widths to match the rotations of each motor, which gave me a complete 0 to 180 degree turns with relative ease. Putting it into a function made it way easier to choose the motor to be turned.

On a tangent, here is a quick explanation of PWM
Basically, the servos have an internal chip/driver which reads signals in terms of HIGH and LOW and the amount of time a signal remains HIGH or LOW.
               _      __     ___    _____   _      _____   __     _   
               | |    |  |   |   |  |     | | |    |     | |  |   | | 
PWM Signal     | |    |  |   |   |  |     | | |    |     | |  |   | |  
             __| |____|  |___|   |__|     |_| |____|     |_|  |___| |_____
 So, as long as the signal is HIGH, the motor keeps turning. When it is at zero, it stops. When the signal falls below the mean value, i.e. LOW, it turns in the opposite direction. The length of the "plateau" in the above picture is basically the duratin for which the signal is kept HIGH or LOW.

Back on track
So, that was that. Once we got that working, it was just a matter of removing the Mouse( ) functions from the code and replacing it with the PWM Servo functions in order to get each motor working as intended.

The basic movement is as follows :

Normal Left-Right Movement : <base_rotate>
Normal Up-Down :  <bottom>
Left Click Up-Down : <middle>
Left Click Left-Right : <base_rotate>
Left+Right Click Up-Down : <claw_control>
Left+Right Click Left-Right : <claw_rotate>


Obviously, this being a prototype, we are still working out some kinks in the accuracy and control of the arm, but so far so good. Next step in this project will be most probably mounting it onto a rover of sorts, with an attached remote camera for total wireless control of the arm. Also in the pipeline is interfacing this arm with an EEG machine, to try and use brain-waves to give rudimentary control to the arm, which will be useful for handicapped people.