📜 ⬆️ ⬇️

Arduino: Robo-arm on two servos

I have never dealt with microcontrollers before, so I decided to start my acquaintance with Arduino. It took a basic knowledge of C / C ++ and a bit of electronics.

Purpose: “Using Arduino Uno and two servos ( 9g SG90 Mini Micro Servo ), write any phrase on a piece of paper”


There were such tasks:


1) I did not have to install the development environment for Linux under Fedora, but I didn’t have to suffer for a long time. There was a bug with the search for “Serial Port”, but Google and patience did their job.

2) Understand what a servo is for a miracle, the “serv” in the people. Since I originally had servos with counterclockwise rotation, the whole code was written under them, but when it came time to change them for new “cheap” SG90s, it suddenly turned out that the new ones rotate clockwise! The problem is solved simply: with the help of a soldering iron, the wires are interchanged: on the engine, and the extreme (1st and 3rd) wires on the potentiometer.

')
3) Assemble the technical design of the “hand”, the name “hand” sounds loud of course, but the main thing is that it differs from the “plotter” .
For this:
• I got a mock-up board and a handful of twisted-pair wires, I soldered the legs from old electronic components at both ends of the wire, in my case I donated capacitors.
• I sawed out of the Getinax , found at the radio factory dump in the 90s, “shoulder” and “forearm”, their length is 80mm, and the distance from the attachment to the servo to the other attachment and the rod is 50mm.

• To remove astrakhan fur, at first I used a rod from a gel pen, but behind a thin line it was difficult to hide minor twitches of the serv, I stopped at the version with a felt-tip pen.
• Secured the first “servu” in a metal can.

Everything, the design is ready, but unfortunately without a program filling, it only shudders a little when power is applied to Arduin.


4) Programming:
Pulling up my knowledge in C / C ++, I started writing code ...

  1. As expected, on a piece of paper, I derived two small formulas for determining the angles of rotation for “serv” at a given coordinate (X, Y). The starting point (0; 0) - is the attachment of the shoulder to the first servo.

  2. After a series of experiments, I realized that until the end of my idea is still far away, and the servos, with each of my bugs, all suffered and suffered from stupid variable values. Therefore, it was decided to first write the rendered model in graphics.h of the good old BorlandC. Who cares what I svizualiziroval there, write in person.
  3. Now, no longer fearing for the safety of the property, I continued to write code.
    With the help of graph paper, he calibrated the system for determining the coordinates and proceeded to draw straight lines, since it was planned to create the font for the letters using lines. It looks like this:
    //      (x,y)   void ServoLine::PrintLine(double x, double y, double x1, double y1 , int A, int C){ int i=0; int r1=50,r2=50; double a,b; a=(x1-x)/(A); b=(y1-y)/(A); while(i<=A){ x=x+a; y=y+b; i++; servo1.attach(10); // Servo1   10  servo2.attach(9); // Servo2   9  servo2.writeMicroseconds(FindBeta(x,y,r1,r2)*8.88889+700); servo1.writeMicroseconds(FindAlpha(x,y,r1,r2)*8.88889+700); delay(C); } } 

  4. Then I asked myself: “How would you like to place words in an original way?”, I came up with the idea that the user would ask the middle and angle of the word, which in the end turned only into the angle of inclination. That's great, there is nothing unnecessary input data brain people puff.
  5. I thought how not to reinvent the wheel and use FreeType to use the method of displaying vector text on the screen, but I didn’t have the patience to understand the structure of the font libraries. As a result, I wrote my own library Alphabet.h, which creates a template from points, and I have already built straight lines for each Latin letter on these points.
      //   "" void Alphabet::print_A (double X00, double Y00,int V,int S) { // V - -   1  // S -      ServoLine1.PrintLine(X00,Y00,X12,Y12,V,S ); ServoLine1.PrintLine(X12,Y12,X24,Y24,V,S ); ServoLine1.PrintLine(X24,Y24,X32,Y32,V,S ); ServoLine1.PrintLine(X32,Y32,X12,Y12,V,S ); ServoLine1.PrintLine(X12,Y12,X32,Y32,V,S ); ServoLine1.PrintLine(X32,Y32,X40,Y40,V,S ); } 

  6. Having written a cycle for reading characters, I ran into the task: “How can I not compare each ASKII code of an IF symbol, but do it right away so that the read letter is perceived as a function?”. Then I used to ask questions on the GIK forums, while waiting for them to register, at random I hoped and posted my question on “Question and answer” from Google, did not have time to pass 15 minutes, the problem was solved by an array of function pointers.
     void (Alphabet::*fArray[26])(double X00, double Y00,int V ,int S)= { &Alphabet::print_A, &Alphabet::print_B, &Alphabet::print_C, &Alphabet::print_D, &Alphabet::print_E, &Alphabet::print_F, &Alphabet::print_G, &Alphabet::print_H, &Alphabet::print_I, etc... }; 

  7. I will not describe how I created libraries, this is well written on the site .
    I will say one thing that created them for good reason, since the code was reduced from 600 lines to 60, and this is visually more pleasant! True, by creating libraries I increased the weight of the sketch by 2K, 6% - noticeably!

Compilation was successful! I was afraid for memory on Arduino and for good reason, despite the fact that in Uno 32Kb, a sketch larger than 29 will not work, since 3Kb is occupied by the loader:
Binary sketch size: 29972 bytes (of a 32256 byte maximum)
Slightly rewriting the letter "R" through "P", and "Q" through "O", reduced the weight and it all worked as it should!
Binary sketch size: 28468 bytes (of a 32256 byte maximum)

Sources to download libraries HERE >> "Alphabet.h" , "Alphabet.cpp" , "ServoLine.h" , "ServoLine.cpp" and the sketch itself "robo_arm.pde"

***VIDEO***







5) Financial expenses are small, I ordered everything on ebay.com: “Arduino Uno” ( ~ 30 $ ) + 2x “Micro Servo SG90” ( ~ 3 $ ) Total: $ 36 + risks, you never know, “Russian Post” will not inform!

A loan board was lent to me; in some places it comes bundled with the Arduino. The fee is free from soldering, but you can easily do without it.

6) Conclusion: It turned out to be an interesting device with which you can: surprise guests, spoil important documents with obscene inscriptions, frighten a cat, sign documents (having added your signature to the library), draw.
I met Arduino, I saw a lot of creative ideas, I realized that I should study Assembler.

If I don’t lose interest, I’ll order the Arduino Ethernet Shield and have the “hand” write Twitter the name of the person who sent me a Reply.

7) If I started something like that now, so that I would do it differently?
1) I wouldn’t have steamed with a graphic model of a hand in graphics.h, but would have used “ Google Sketchup + plugin SketchyPhysics “
2) To create a model design, I would use “polycaprolactone” .



I hope my experience will be useful to someone, because it is so great when you revive the “unlived” with your work and ideas! Good luck!

Source: https://habr.com/ru/post/167441/


All Articles