Three-degree manipulator on Arduino

    There are many interesting articles about the Arduino platform , which you can safely order at the Ebay online auction . There are many modules and articles on the Internet for this platform, so I wanted to do something interesting, though not always useful in everyday life.
    image


    For work, there is experience in managing platforms with various degrees of freedom, so the first thing I wanted to do was a six-degree platform (Stewart Platform) , but unfortunately only four servo drives came, so for a start we will make a three-degree platform.

    Tools and materials


    So, to build this unit, we need the following components:
    Namingnumber
    Arduino mega1 PC.
    HXT900 Servo Drive3 pcs.
    Plywood1 PC.
    5V voltage regulator1 PC.
    Paper clip3 pcs.
    Wire holder3 pcs.
    USB Cord1 PC.
    Power Supply1 PC.
    Connecting wires13 pcs
    Styracosaurus1 PC.


    The cost of the board and controller Arduino Mega Kit at auction ranges from $ 50. With the purchase of servos from China, there should also be no problems, the cost of one piece is about $ 2. Plywood can be found in the country or in the store. Three paper clips at work. The most difficult thing is to get a styracosaurus, usually these species of animals can be seen at the post office or in the children's store.

    Platform manufacturing


    The main task of manufacturing the platform is to cut out the base of the platform and the platform itself from plywood. Control elements are placed inside the circle at angles of 120 degrees.

    1 Step - Sawing

    Sawing out the base of a platform measuring 10x10 cm, as well as the platform itself measuring 8x8 cm. The platform itself can be left square, but a triangle has been cut for convenience. Saws are made in the place of attachment of the supports.

    2 Step - Drilling

    For drilling, it is first necessary to draw a circle divided into three parts. In the rays under 120 degrees, it is necessary to apply servos, as well as mark the points for drilling.

    Drill holes according to the finished marking, depending on the method of fastening. For fastening with harnesses (best option), the holes should be 4 mm in diameter. In case of fastening with a wire (as in my case), holes with a diameter of 2 mm are enough.

    3 Step - Preparing the Anchorages

    Nothing was found for fastening except staples (after the demonstration at work, another option was proposed). Paper clips must be made in the form of the letter "G", which is fixed on the servo drive and inserted into the mount on the platform platform.

    At work, I was offered instead of staples to use a ball mount from a Trex 450 helicopter (already ordered from China). With this type of mount, the platform will be more rigid in construction.

    Step 4 - Build the platform

    The assembly of the platform is carried out in the following sequence:
    • threading the wire into the base of the platform;
    • mounting of servos on the base;
    • installation of fasteners for wires on the platform platform;
    • installation of fasteners in the form of the letter "G" on the servos.


    Summary

    The result is the base of the platform, as shown in the figure below. The lead time is 1 hour .
    image

    Circuit assembly


    To connect, the method described in the official documentation on the Arduino website was originally used . When connecting several servos, the power supply is not enough, so it is advisable to “power” the three drives separately through a 5V voltage regulator (a detailed description of the connection ).

    In the case of connecting three servos to the Arduino, the power will be insufficient and protection will be triggered. The connection of three drives through the stabilizer on the breadboard is shown in the figure below:
    image

    Control from Arduino will be carried out using 1, 2, 3 analog outputs (Analog Pins) from the board. In my case, the power is also connected from the board. An example of connection is shown in the figure:
    image
    where from left to right: blue - 5V, yellow - "ground", red - drive 1, black - drive 2, yellow drive 3.

    The whole connection diagram has the form:
    image

    Arduino Programming


    The platform is controlled from a computer via the serial port provided by Arduino. Work with the port is carried out by means of the Serial library, and control of servos by means of the SoftwareServo library.

    To parse the command from the serial port, the following structure is used in C language: Accordingly, three positions in integer form are indicated. The command byte is also indicated, in our case, the command for writing positions to the controller has the code 0xC1 . The position of the servos is set using the update_positions function, which maps the values ​​from the command to the values ​​of the angle of rotation of the servo shaft.
    struct _set_pos_cmd_t
    {
     char cmd;
     int pos1;
     int pos2;
     int pos3;
    };

    typedef _set_pos_cmd_t set_pos_cmd_t;

    * This source code was highlighted with Source Code Highlighter.





    void update_positions()
    {
      int val = map(servo_position1, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);
      myservo1.write(val);
      val = map(servo_position2, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);
      myservo2.write(val);
      val = map(servo_position3, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);
      myservo3.write(val);
     delay(5);
     SoftwareServo::refresh();
    }

    * This source code was highlighted with Source Code Highlighter.


    Final program for Arduino

    1. #include
    2.  
    3. #define SET_CMD    0xC1
    4.  
    5. #define COMMAND_ERROR 0x01
    6. #define FORMAT_ERROR  0x02
    7.  
    8. #define VALUE_MINIMUM 0
    9. #define VALUE_MAXIMUM 4096
    10.  
    11. #define SERVO_MINIMUM 0
    12. #define SERVO_MAXIMUM 90
    13.  
    14. SoftwareServo myservo1;
    15. SoftwareServo myservo2;
    16. SoftwareServo myservo3;
    17.  
    18. int servo_position1 = 0;
    19. int servo_position2 = 0;
    20. int servo_position3 = 0;
    21.  
    22. struct _set_pos_cmd_t
    23. {
    24.  char cmd;
    25.  int pos1;
    26.  int pos2;
    27.  int pos3;
    28. };
    29.  
    30. typedef _set_pos_cmd_t set_pos_cmd_t;
    31.  
    32. void setup()
    33. {
    34.  pinMode(13, OUTPUT);
    35.  myservo1.attach(A0);
    36.  myservo2.attach(A1);
    37.  myservo3.attach(A2);
    38.  Serial.begin(115200);
    39. }
    40.  
    41. boolean readBytes(char *bytes, int count)
    42. {
    43.  char data;
    44.  
    45.  for(int counter = 0; counter < count; ++counter)
    46.  {
    47.   data = Serial.read();
    48.   bytes[counter] = data;
    49.  }
    50.  
    51.  Serial.flush();
    52.  
    53.  return true;
    54. }
    55.  
    56. void set_positions(char *data)
    57. {
    58.   set_pos_cmd_t *command = (set_pos_cmd_t*)data;
    59.  
    60.   servo_position1 = command->pos1;
    61.   servo_position2 = command->pos2;
    62.   servo_position3 = command->pos3;
    63. }
    64.  
    65. void update_positions()
    66. {
    67.   int val = map(servo_position1, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);  
    68.   myservo1.write(val);
    69.   val = map(servo_position2, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);
    70.   myservo2.write(val);
    71.   val = map(servo_position3, VALUE_MINIMUM, VALUE_MAXIMUM, SERVO_MINIMUM, SERVO_MAXIMUM);
    72.   myservo3.write(val);
    73.   delay(5);        
    74.   SoftwareServo::refresh();
    75. }
    76.  
    77. void loop()
    78. {
    79.  int availableBytes = 0;
    80.  char buffer[128];
    81.  
    82.  if((availableBytes = Serial.available()) > 0)
    83.  {
    84.   if(!readBytes(buffer, availableBytes))
    85.   {
    86.    Serial.write(FORMAT_ERROR);
    87.   }
    88.   
    89.   switch(buffer[0])
    90.   {
    91.    case SET_CMD:
    92.     set_positions(buffer);
    93.     Serial.write(0xDA);
    94.     break;
    95.   } 
    96.  }
    97.  
    98.  update_positions();
    99. }
    * This source code was highlighted with Source Code Highlighter.


    Management program


    The three-stage platform management program is written in C #, which in its original form was simplified:
    image

    The latest version of the platform management program took the form:
    image

    UPD: source code of the management class

    Implementation video




    Thanks for attention!


    Also popular now: