Friday 21 December 2012

Robot Arm: Writing The Controller

     Since my understanding of programming isn't overly advanced yet, the best approach to building a program for the arm would be to find a program that has a similar function, and modifying it for my needs. After browsing the apple forums, we found a program that someone had developed that could output signals from the serial port. 


       Using a programming environment called XCode, we opened up the program and examined it to figure out how it worked. We then stripped out all of the code we didn't need, leaving us with a solid foundation that we could build upon.



     


       From there, we built a simple interface consisting of six sliders that controlled each of the six servos. The program had to be written in a language called Objective C, which has some similarities to the Java programming language we used in my Grade 11 Programming course, so it wasn't that hard for me to understand.





       Here is a look at a portion of the code that handles the interface. The very first line basically waits for any of the sliders to be changed, and when one is, it activates the code within the curly brackets. The next line creates the format for the signal that will be sent to the robot(the red text). Normally, the signal that is sent to the robot is "#(servo) P(desired servo position) S(speed)". For instance, if you wanted to send the shoulder to position 1700 at a low speed, you'd type "#1 P1700 S100" and then hit enter. So in our program, you'll notice the same format, except the servo number and servo position have been replaced by a "%d", which is used in Xcode as a substitution, so you can get the program to replace that "%d" with any set of symbols, letters, or numbers. 

        The next few lines get somewhat complicated, but all they really do is take the decimal data received from the slider and convert it to ASCII, so the arm understands it. Finally, the last line outputs the ASCII command through the serial port.

No comments:

Post a Comment