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.
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.
So, to build this unit, we need the following components:
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.
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.
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.
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.
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.
The assembly of the platform is carried out in the following sequence:
The result is the base of the platform, as shown in the figure below. The lead time is 1 hour .
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:
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:
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:
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.
The three-stage platform management program is written in C #, which in its original form was simplified:
The latest version of the platform management program took the form:
UPD: source code of the management class
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:
Naming | number |
Arduino mega | 1 PC. |
HXT900 Servo Drive | 3 pcs. |
Plywood | 1 PC. |
5V voltage regulator | 1 PC. |
Paper clip | 3 pcs. |
Wire holder | 3 pcs. |
USB Cord | 1 PC. |
Power Supply | 1 PC. |
Connecting wires | 13 pcs |
Styracosaurus | 1 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 .
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:
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:
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:
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
- #include
-
- #define SET_CMD 0xC1
-
- #define COMMAND_ERROR 0x01
- #define FORMAT_ERROR 0x02
-
- #define VALUE_MINIMUM 0
- #define VALUE_MAXIMUM 4096
-
- #define SERVO_MINIMUM 0
- #define SERVO_MAXIMUM 90
-
- SoftwareServo myservo1;
- SoftwareServo myservo2;
- SoftwareServo myservo3;
-
- int servo_position1 = 0;
- int servo_position2 = 0;
- int servo_position3 = 0;
-
- struct _set_pos_cmd_t
- {
- char cmd;
- int pos1;
- int pos2;
- int pos3;
- };
-
- typedef _set_pos_cmd_t set_pos_cmd_t;
-
- void setup()
- {
- pinMode(13, OUTPUT);
- myservo1.attach(A0);
- myservo2.attach(A1);
- myservo3.attach(A2);
- Serial.begin(115200);
- }
-
- boolean readBytes(char *bytes, int count)
- {
- char data;
-
- for(int counter = 0; counter < count; ++counter)
- {
- data = Serial.read();
- bytes[counter] = data;
- }
-
- Serial.flush();
-
- return true;
- }
-
- void set_positions(char *data)
- {
- set_pos_cmd_t *command = (set_pos_cmd_t*)data;
-
- servo_position1 = command->pos1;
- servo_position2 = command->pos2;
- servo_position3 = command->pos3;
- }
-
- 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();
- }
-
- void loop()
- {
- int availableBytes = 0;
- char buffer[128];
-
- if((availableBytes = Serial.available()) > 0)
- {
- if(!readBytes(buffer, availableBytes))
- {
- Serial.write(FORMAT_ERROR);
- }
-
- switch(buffer[0])
- {
- case SET_CMD:
- set_positions(buffer);
- Serial.write(0xDA);
- break;
- }
- }
-
- update_positions();
- }
* 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:
The latest version of the platform management program took the form:
UPD: source code of the management class