1、 Overall frame:

(1) Design function:

① It can complete multi-directional walking and other custom actions. (advance, retreat, turn left and right, avoid obstacles);

② Automatic obstacle avoidance;

③ He orders his next move through Bluetooth on his mobile phone.

(2) Functional framework:

Control design of Hexapod Robot Based on 51 single chip microcomputer

(3) Equipment used:

① STC89C52 single chip microcomputer, 74LS04 (inverter);

② Bluetooth serial communication module;

③ Ultrasonic ranging module;

④ 18 9g steering gears;

⑤ Several PVC trunking (molds);

⑥ PCB transfer board;

⑦ Several screws and nuts.

⑦ Keil3 software

2、 Working principle:

(1) Bluetooth serial communication module:

The Bluetooth serial communication module receives the string signal sent by the Bluetooth software of the mobile phone. The single chip microcomputer processes the information received by the Bluetooth module through the serial communication protocol, and then judges the next action of the robot according to the content of the information.

(2) Ultrasonic ranging module:

The ultrasonic module emits ultrasonic waves in a certain direction and starts timing at the same time as the launch time (low level). When the ultrasonic waves propagate in the air, they will return immediately when they encounter obstacles on the way. When the ultrasonic receiver receives the reflected wave, it will stop timing immediately (return to high level), and calculate the measurement distance according to the length of low level. (the propagation speed of ultrasonic wave in the air is 340m / s. according to the time t recorded by the timer, the distance (s) between the starting point and the obstacle can be calculated, that is, s = 340t / 2)

(3) Steering gear control:

The control circuit board receives the control signal from the signal line to control the rotation of the motor. The motor drives a series of gear sets and transmits them to the output rudder plate after deceleration. The output shaft of the steering gear is connected with the position feedback potentiometer. While the steering wheel rotates, it drives the position feedback potentiometer. The potentiometer will output a voltage signal to the control circuit board for feedback, and then the control circuit board determines the rotation direction and speed of the motor according to the position, so as to achieve the target stop. The control signal cycle of the steering gear is a pulse width modulation (PWM) signal of 20ms, in which the pulse width ranges from 0.5-2.5ms and the corresponding rudder disc position is 0-180 degrees, which changes linearly. In other words, if a certain pulse width is provided to it, its output shaft will maintain a certain corresponding angle. No matter how the external torque changes, it will not change the output angle to a new corresponding position until a pulse signal of another width is provided to it.

In our work, the 18 channel steering gear is divided into two groups, which are controlled by an internal timer to generate the PWM signal corresponding to the steering gear (first, timer 1 generates the pulse width of the first steering gear, then the pulse width of the second steering gear until the ninth steering gear, and then timer 2 generates the PWM signals of the remaining 9 steering gears in the same way, so as to reciprocate).

3、 Production process:

(1) Simulation schematic diagram:

Control design of Hexapod Robot Based on 51 single chip microcomputer

(2) PCB fabrication:

Control design of Hexapod Robot Based on 51 single chip microcomputer

(3) Hardware construction:

《a》 Limb making:

Material: PVC trunking, PVC board

① Model making: (cut by hand)

Control design of Hexapod Robot Based on 51 single chip microcomputer

② Steering gear Transformation:

Control design of Hexapod Robot Based on 51 single chip microcomputer

③ Overall:

Control design of Hexapod Robot Based on 51 single chip microcomputer

4、 Commissioning and problem solving:

① Structural issues:

We believe that the overall shape and structure is the key to the success or failure of the work. After testing a variety of materials, we finally chose the PVC trunking that is easy to cut and basically meets the hardness to refit the splicing limbs, and the body uses thicker plastic plates. After a week of pure manual processing and transformation, the production of the whole model was completed.

② Power supply problem:

Because we use 9g steering gear, which has poor performance and insufficient torque, we can’t support the power supply and voltage stabilizing module we designed. Finally, we give up the embedded power supply and use the adjustable power box in the laboratory to supply power through wires. It’s our only regret that we can’t separate it.

③ Machine jitter problem

Because 89C52 has only 6 internal interrupts, it is far from meeting the control of 18 steering gears, and other functional modules also need to use internal interrupts. Therefore, we divided the 18 channel actuators into two groups. Initially, one actuator after another (20ms cycle of each actuator) sent PWM, but the total cycle length of sending 18 channel PWM once is too large (18 * 20 = 360ms), which is enough to produce jitter perceived by human eyes. After repeated research, the PWM signal of the current steering gear starts to generate a high level at the low level of the previous PWM signal (after the high level of the previous PWM) as shown in the figure below, which greatly shortens the total cycle length of one action of the 18 channel steering gear (after 18 channels, the total cycle length is about 20ms of the cycle length of a PWM), so that the jitter can not be observed by human eyes.

There are a lot of codes. The main steering gear control codes are given. It doesn’t matter if you don’t understand the codes. It’s explained later:

#include《reg52.h》

#include《intrins.h》

#include《dongzuo.h》

#define ucharunsigned char

#define uintunsigned int

//PWM

sbit PWM0 = P1^0;

sbit PWM1 = P1^1;

sbit PWM2 = P1^2;

sbit PWM3 = P1^3;

sbit PWM4 = P1^4;

sbit PWM5 = P1^5;

sbit PWM6 = P3^4;

sbit PWM7 = P3^5;

sbit PWM8 = P3^6;

sbit PWM9 = P3^7;

sbit PWM10 = P2^0;

sbit PWM11 = P2^1;

sbit PWM12 = P2^2;

sbit PWM13 = P2^3;

sbit PWM14 = P2^4;

sbit PWM15 = P2^5;

sbit PWM16 = P2^6;

sbit PWM17 = P2^7;

//Ultrasonic ranging

sfr T2MOD = 0XC9; // Timer 2 mode control register address

sbit Trig =P3^2;

sbit Echo =P3^3;

unsigned intdistance;

uchar DZCS =0x11; // Control action

uchar buf;

uchar sd=3;

bit flag=0; // Send character

bit CSB =0; // Ultrasonic start control bit

bit HZ=0; // Backward left turn control position

uchar PWMscan =0;

uchar PWMscan1 =0;

Uchar pwmval [] = {/ / initial attitude

0xf8,0x8f,0xf7,0x05,0xf9,0x8c,/*5*/ 0xfa,0x0d,0xf8,0x0b,0xf9,0x67,/*b*/ 0xfa,0xd4,0xf7,0x94,0xf9,0xcb,/*11*/

0xfa,0xad,0xfc,0xdd,0xfb,0x58,/*17*/ 0xfa,0xe9,0xfc,0xfc,0xfb,0x39,/*1d*/ 0xfc,0x18,0xfc,0xca,0xfb,0x00/*23*/

};

void delay(uint a)

{

uchar j;

for(a;a》0;a–)

for(j=0;j《112;j++)

;

}

void task00()

{

If (pwmscan = = 1) / / Channel 1 PWM.

{

PWM0=1;

TH0=PWMval[0];

TL0=PWMval[1];

}

Else if (pwmscan = = 2) / / Channel 2 PWM.

{

PWM0=0;

PWM1=1;

TH0=PWMval[2];

TL0=PWMval[3];

}

Else if (pwmscan = = 3) / / the third PWM.

{

PWM1=0;

PWM2=1;

TH0=PWMval[4];

TL0=PWMval[5];

}

Else if (pwmscan = = 4) / / Channel 4 PWM.

{

PWM2=0;

PWM3=1;

TH0=PWMval[6];

TL0=PWMval[7];

}

Else if (pwmscan = = 5) / / Channel 5 PWM.

{

PWM3=0;

PWM4=1;

TH0=PWMval[8];

TL0=PWMval[9];

}

Else if (pwmscan = = 6) / / Channel 6 PWM.

{

PWM4=0;

PWM5=1;

TH0=PWMval[10];

TL0=PWMval[11];

}

Else if (pwmscan = = 7) / / Channel 7 PWM.

{

PWM5=0;

PWM6=1;

TH0=PWMval[12];

TL0=PWMval[13];

}

Else if (pwmscan = = 8) / / Channel 8 PWM.

{

PWM6=0;

PWM7=1;

TH0=PWMval[14];

TL0=PWMval[15];

}

Else if (pwmscan = = 9) / / the 9th PWM.

{

PWM7=0;

PWM8=1;

TH0=PWMval[16];

TL0=PWMval[17];

}

Else if (pwmscan = = 10) / / give a certain low level and lengthen the cycle

{

PWM8=0;

TH0=0xFF;

TL0=0xd2;

PWMscan=0;

TR0 = 0; // Off timer 0, on timer 1

TR1 = 1;

}

PWMscan++;

}

void task01()

{

If (pwmscan1 = = 1) / / the 10th PWM.

{

PWM9=1;

TH1=PWMval[18];

TL1=PWMval[19];

}

Else if (pwmscan1 = = 2) / / 11th PWM.

{

PWM9=0;

PWM10=1;

TH1=PWMval[20];

TL1=PWMval[21];

}

Else if (pwmscan1 = = 3) / / the 12th PWM.

{

PWM10=0;

PWM11=1;

TH1=PWMval[22];

TL1=PWMval[23];

}

Else if (pwmscan1 = = 4) / / the 13th PWM.

{

PWM11=0;

PWM12=1;

TH1=PWMval[24];

TL1=PWMval[25];

}

Else if (pwmscan1 = = 5) / / the 14th PWM.

{

PWM12=0;

PWM13=1;

TH1=PWMval[26];

TL1=PWMval[27];

}

Else if (pwmscan1 = = 6) / / the 15th PWM.

{

PWM13=0;

PWM14=1;

TH1=PWMval[28];

TL1=PWMval[29];

}

Else if (pwmscan1 = = 7) / / the 16th PWM.

{

PWM14=0;

PWM15=1;

TH1=PWMval[30];

TL1=PWMval[31];

}

Else if (pwmscan1 = = 8) / / the 17th PWM.

{

PWM15=0;

PWM16=1;

TH1=PWMval[32];

TL1=PWMval[33];

}

Else if (pwmscan1 = = 9) / / the 18th PWM.

{

PWM16=0;

PWM17=1;

TH1=PWMval[34];

TL1=PWMval[35];

}

Else if (pwmscan1 = = 10) / / give a certain low level and lengthen the cycle

{

PWM17=0;

TH1=0xFf;// B1 / / this is an approximate value. Because the sum of pwmval of each group (the sum of timer intervals in pwmval is one cycle) is inconsistent,

//Therefore, the cycle may not be 20ms, but it can be controlled at about 20ms. It is also necessary because the cycle is not fixed

TL1=0xd2;// E0 / / adjust the actual duty cycle of each steering gear.

PWMscan1=0;

TR0 = 1;// On timer 0

TR1 = 0;// Off timer 1

}

PWMscan1++;

}

void TImer0()interrupt 1

{

task00();// Front 9-way PWM control

}

void TImer1()interrupt 3

{

task01();// Control rear 9-way PWM

}

In the actual process, perhaps due to the quality problem of the steering gear or other problems, the angle control of the steering gear is always difficult to use the formula in principle to control the angle. It is all practical operation. Manually adjust the width of the high level. When the appropriate value is reached, then record the corresponding code.

The high-level width of the single chip microcomputer is controlled by the two registers of the timer, so the rotation of the operating steering gear becomes the register of the operating timer. To be more specific, we need to get the two values of th and TL. (the difference between the high and low bits of the timer corresponds to the width of the high level)

In the code, when controlling the third steering gear, the values of th and TL have been determined as which pwmval [?], For example, route 18:

TH1=PWMval[34];

TL1=PWMval[35];

This will determine the rotation angle of the 18th steering gear at this time, so how to control the rotation angle of the steering gear next time? The answer is very simple, that is, pwmval [34]; PWMval[35]; It is OK to modify the value of, and the same is true for other steering engines. Therefore, a posture of the robot can be changed into this: robot posture → angle of 18 steering gear → 18 th and TL values → the value of a 36 element array pwmval.

Therefore, an action attitude can be determined by such a function:

Void DZ (ucharpwm []) / / action

{

uchar i;

for(i=0;i《36;i++)

PWMval[i]=PWM[i];

}

After understanding this, I collected data for each pose. During the production process, I displayed the two values of th and TL on the nixie tube and recorded them.

Later, Bluetooth control module and ultrasonic ranging are added. It is found that the timer of 51 single chip microcomputer is not enough. It is changed to 52 series single chip microcomputer. There is also a timer, that is, Bluetooth module and ultrasonic ranging. Now I really admire myself. Give the control code and study it by yourself:

//***************************Interrupt initialization**************************

void Init()

{

TMOD |= 0x11;// Timer 0, 1

ET0 = 1;// Enable timer 0 interrupt

TR0 = 1;// Start timer 0, timer 1 is interrupted, and it will not open until timer 0 starts

ET1 = 1;// Enable timer 1 interrupt

IT1 = 0;// External interrupt 1, low level trigger (edge high to low)

EX1 = 1;// Open external interrupt 1

//Timer 2 is used for baud rate generation

SCON=0x50;

PCON=0x00;

RCAP2H=0xFF;

RCAP2L=0xDC;// Set the baud rate to 9600

T2CON=0x34;// Set timer 2 as baud rate generator (timer2 is used for both reception and transmission) / / start T2 is included here

ES=1; // Serial port interrupt

EA = 1;// On total interrupt

}

void TImer0()interrupt 1

{

task00();// Front 9-way PWM control

}

void TImer1()interrupt 3

{

task01();// Control rear 9-way PWM

}

void serial() interrupt 4

{

EA=0; // All other interruptions

if(RI)

{

RI=0; // Clear the serial accept flag bit

flag=1;

buf=SBUF; // Obtain data (i-0x30) from the serial port buffer and convert the ASCL code into a number

switch(buf)

{

case 0x00: DZCS=0x00; break; // Move on

case 0x01: DZCS=0x01; break; // Go back to

case 0x02: DZCS=0x02; break; // Turn left

case 0x03: DZCS=0x03; break; // Turn right

case 0x04: DZCS=0x04; break; // Cross left

case 0x05: DZCS=0x05; break; // Across the right

case 0x06: DZCS=0x06; break; // Swing your paw

case 0x07: sd++; break; // Deceleration is actually the delay in each attitude is different

case 0x08: sd–; break; // accelerate

case 0xff: CSB=! CSB; break; // Start and close ultrasonic barrier

default:

DZCS=0x11; break; //

}

}

EA = 1; // Open total interrupt

}

Void start() / / ultrasonic ranging start function

{

uchar i;

Trig=1;

for(i=0;i《20;i++)

{

_ nop_ ();

}

Trig=0;

}

Void count() / / ultrasonic ranging function

{

unsigned int time,timeH,timeL;

timeH=TH1;

timeL=TL1;

time=timeH*256+timeL;

distance=time*1.7/100;

}

Void inter() interrupt 2 / / the external interrupt completes ranging and corresponding subsequent operations 1 time

{

EA =0;

ET0=0; // Off timer interrupt 0

TH1=0;

TL1=0;

TR1 =1; // Distance start timer 1 detected

while(!Echo); // When the echo is zero, the interrupt flag jumps out of the wait

TR1 =0; // Turn off timer 1

count(); // Calculate distance

If (((10 “distance” & & (distance “30)) |hz) / / when the distance is less than 5cm, change the action (change the plane induction in the interrupt

{

DZCS=0x02; // towards the left

HZ=0;

}

If (distance 10) / / when the distance is less than 10cm, change the action (change the surface during interruption)

{

DZCS=0x01; // back off

HZ=1; // Backward left turn sign

}

If (distance “30) / / when the distance is less than 40cm, change the action (change in interrupt)

{

DZCS=0x00; // forward

HZ=0;

}

TR1=1;

ET0=1;

EA = 1;

}

void main()

{

Init();

while(1)

{

uchar DZCST;//, i;

if(CSB)

start();

If (dzcst! = dzcs) / / if the action changes, it returns to balance

DZ(PH1);

if(sd==0)

sd=1;

switch(DZCS)

{

case0x00:DZXQ(sd); break;

case0x01:DZXH(sd); break;

case0x02:DZXZ(sd); break;

case0x03:DZXY(sd); break;

case0x04:DZHZZ(sd); break;

case0x05:DZHZY(sd); break;

case0x06:DZZZ(sd); break;

default:

DZ(PH1);

}

DZCST=DZCS;

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *