Meet Petya, the six-legged three servos
I continue to publish articles from the Arduino Brain series. Petya is a very cheap (about ten bucks) hexapods. It can be a wonderful project for a rainy day off, which will entertain both adults and children. Since we're talking about entertainment, here's a video with Petya dancing to funk music:
Of course, I did not do any sound analysis, I simply programmed Petya to dance in a certain rhythm. Here is another video in which Petya shows his contempt for juggling balls:
In his current form, Petya can only walk, but at the same time he can see (measure the distance to) nearby obstacles. His brains, however, are productive enough to be able to digest data from many other sensors, send your suggestions!
How to clone Petya
Shopping list
3 , / . , :
- . , . - 10€ / 10 ( ), 2€ / 10 . , , . — , cheapduino - , .
- SG90 9G , 3 * 1.47€ /
- 4x AAA , 1.34€ /
- ATMega8A-AU (QFP-32), 1€ /
- IR LED + IR , 0.20€ /
- 1000uF 16V, 0.17€ /
- 2n3904 , 3 * 0.01€ /
- , , , 0805 . : hardware/motherboard/BOM.html.
, , . (, ), . . — . , ;)
NB: 9g , . . , , , SketchUp . , , , .

, 3 , hardware/body/. - ::

1, . - :

3 . , . :

. hardware/motherboard/. :

ATMega8 , . :

, , , . :

N.B. , ATMega8A 2.7-5.5, 6. — NiMH 1.2V . (6.4 ), , . , , !
( ):

, . ; . , , . , , , :

:

; , Q3 Q4 "" Vcc, , . :

, , , R6. 47 55 , ( ). , , (910 )!
( ). , CR2032, . ( , [] , , )
, , Q3 Q4 . , , , , , .
, . , . 2n3904, , , . , , .
, , , , :

.
, , :
- isf471 2n3904.
- Sharp GP2Y0A21YK0F:

- LM393:

, , , ATMega8. :
-
50 ; 1 (0 ), 2 (90 ). , 16 (timer1), (timer2). , Servo.h , , fast PWM.
8 , timer1 1 ( 8).
ICR1 TOP (20000), , 20 , 50 . OCR1A OCR1B ( ) .
. timer2, , , ICR1, , . , 50 , , - :
- timer2 128, , 4.096 ms = 256 * 128/(8 * 10^6).
- timer2, , .
- capture interrupt timer1 timer2 ( ).
4 2 , , 20 . , (1.5 ), :
OCR1A = 1500;
OCR1B = 1500;
OCR2 = 1500/16;
-, :
const uint8_t zero[3] = {45, 50, 40};
const uint8_t range[3] = {25, 25, 20};
zero[3]
, (. ). , 45° ( ), 45° , . , range[3]
. , i
zero[i]-range[i]
zero[i]+range[i]
.

( , 0°-90°) uint8_t pos[3]
. update_servo_timers()
- . pos[i]=zero[i]+range[i]
i=0,1,2
.
. pos_beg[3], pos_end[3], time_start[3]
duration[3]
. , . :
pos[0]
pos_beg[0]
, , ;pos_end[0]
(- );time_start[0]
(, );- , ,
duration[0]
( ). , (pos_end[0]-pos_beg[0])/duration[0]
/.
movement_planner()
, pos[]
, update_servo_timers()
, - pos[]
.
, , , ( ) . , . , . , :
- 1:
{zero[0]-range[0], zero[1]-range[1], zero[2]+range[2]}
- 2:
{zero[0]-range[0], zero[1]-range[1], zero[2]-range[2]}
- 3:
{zero[0]+range[0], zero[1]+range[1], zero[2]-range[2]}
- 4:
{zero[0]+range[0], zero[1]+range[1], zero[2]+range[2]}
2 ( ):
const int8_t advance_sequence[4][3] = {{-1, -1, 1}, {-1, -1, -1}, { 1, 1, -1}, { 1, 1, 1}};
, i
step
zero[i] + range[i]*advance_sequence[step][i]
.
:
uint8_t step = steps_per_sequence-1;
while (1) {
if (is_movement_finished()) {
step = (step + 1) % 4;
plan_next_movement(step, advance_sequence);
}
movement_planner();
_delay_ms(1);
}
, , 4 5 . , ( , ), adc_left_eye
adc_right_eye
, :
adc_left_eye = adc_left_eye *.99 + adc_read(5)*.01;
adc_right_eye = adc_right_eye*.99 + adc_read(4)*.01;
_delay_ms()
, .99
1-.99
.
:
uint8_t lobst = adc_left_eye < distance_threshold;
uint8_t robst = adc_right_eye < distance_threshold;
(, ) :
if (is_movement_finished()) {
if (!lobst && !robst) {
sequence = advance_sequence;
} else if (lobst && robst) {
sequence = retreat_sequence;
} else if (lobst && !robst) {
sequence = turn_right_sequence;
} else if (!lobst && robst) {
sequence = turn_left_sequence;
}
step = (step + 1) % steps_per_sequence;
plan_next_movement(step, sequence);
}
, !
! , , :
:
- "", . , , . , ?
- ( !) , , .
- , , avr-gcc . , - .
:
, V2 , ! , // :
- — , ;
- , RC- ;
- ;
- R6 ;
- ( ) ;
- — . — , ;
- Move the electrolyte slightly. I had to tilt it, because otherwise, the central left leg hurts him;
- Add test sites with easy access to them with an oscilloscope;
- Add a pair of debug LEDs for debugging without an oscilloscope;
- Add soldering pads for all unused microprocessor legs for debugging and further expansion of the robot.
Conclusion
Petya is terrible fun!
