Servo control of bionic robot fish based on PIC18F452 microcontroller

Publisher:学富五车Latest update time:2011-11-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The bionic robot fish experimental platform is a "National Undergraduate Innovative Experimental Program" project jointly funded by the Ministry of Education and Beijing University of Posts and Telecommunications. It is an experimental platform integrating light, machinery, electricity, fluid and intelligence. The research content includes: research on the mechanical structure of bionic robot fish, research on recommended efficiency and research on control performance.
1 Introduction to the bionic robot fish platform:
The designed and manufactured robot fish imitates the appearance of the croaker fish, and the head is made of rigid plastic material. Its shape is streamlined, imitating the shape and size ratio of the head of a real fish. The power supply and control circuit are installed in the internal space of the fish head, and 3 infrared sensors are installed at the fish eyes on both sides of the fish head and on the lower side of the front of the head, forming a sensor network that detects the left, front and right directions, so that the fish has the function of self-help obstacle avoidance. The
fish skeleton made of aluminum alloy is used to connect the three servos in series. The fish skeleton supports the rubber fish skin on the outside of the servo, which constitutes the three-joint drive system of the robot fish body. The fish body is fixed to the rigid fish head by threaded connection using a connector made of aluminum alloy, and the rubber fish skin of the fish body is glued to the fish head using hot melt adhesive, thus forming the overall result of the robot fish. The details are shown in Figure 1. Experiments have shown that this method is simple and easy to disassemble and assemble.

Technical indicators of the robot fish: cruising speed: 1.2~1.5m./s; cruising distance with full power: 4.5~5.5 kilometers; turning radius: 15~20cm.


2. System composition and working principle:

From a functional point of view, the entire fish system can be divided into three major parts: perception area, decision area, and behavior area. The perception area corresponds to the multi-infrared sensor network and the infinite transmission module, while the decision area refers to the main control chip (MCU), and the action area corresponds to the three-joint drive system composed of servos in series. See Figure 2 for details. The most important work of this system is concentrated on the coordinated control of multiple servos, so the control work of the servos is mainly introduced in detail.

[page]

3.1
Working principle of servo:
The servo is mainly composed of the following parts: steering wheel, reduction gear set, proportional potentiometer (position feedback potentiometer), DC motor (motor), control circuit board, etc. Its working principle: The control circuit board receives the control signal from the signal line, controls the rotation of the DC motor, and the DC motor drives a series of gear sets. The output shaft of the gear set is connected to a linear proportional potentiometer, which converts the angle θ of the output shaft into a proportional voltage feedback to the control circuit. The control circuit compares it with the input control pulse signal, generates a correction pulse, and drives the motor to rotate forward or reverse, so that the output position of the gear set matches the expected value, and the correction pulse tends to 0, so as to achieve the purpose of precise positioning of the servo. The servo is a typical closed-loop feedback system, and its working principle is shown in Figure 3.

There are three input lines for the servo. The red one in the middle is the power line, and the black one on the side is the ground line. These two lines provide the most basic energy guarantee for the servo, mainly for the rotation consumption of the motor. There are two specifications of power supply, one is 4.8V and the other is 6.0V, which correspond to different torque standards respectively. The other line is the control signal line, which is generally white.
3.2 Angle control of single servo and multiple servos
3.2.1 Angle control of single servo:
According to the working principle of the servo, a periodic pulse signal with a period of about 20ms and a pulse width between 0.5ms and 2.5ms is input to the servo, driving the output shaft of the servo to reach an angle between -90° and 90°, which changes linearly. And no matter how the external torque changes, the output shaft of the servo will remain at a corresponding angle until it is provided with a pulse signal of another width, and then the output angle will be changed to a new corresponding position. Through programming, the required periodic pulse signal is obtained with the help of the output port of the single-chip microcomputer.
Program example: (Crystal oscillator: 4MHZ, pulse output from PORTDbits.RD0)
void delay(int j) //This function is used to generate a delay of 0.25ms*j
{
for(i=0;i {

INTCONbits.TMR0IF=0; //Clear TMR0 interrupt flag
T0CON=0XCF; //Set TMR0L to work in 8-bit timer mode, internal clock,
TMR0 does not need frequency division
TMR0L=0X14; //Set TMR0 to generate an interrupt every 0.25ms
L1: if(INTCONbits.TMR0IF==1)
{
INTCONbits.TMR0IF==0; //Clear TMR0 interrupt flag, turn off timer
T0CON=0X4F;
}
else goto L1;
}
}
PORTDbits.RD0=1; //Output a pulse signal with a pulse width of 2ms and a period of 20ms
delay(8);
PORTDbits.RD0=0;
delay(72);
From the above program, we can see that by changing the parameter j of the delay function, we can get a pulse signal with the corresponding pulse width and period as needed. For example, change the 1st to 4th line of the above program segment:
PORTDbits.RD0=1;
delay(4);
PORTDbits.RD0=0;
delay(76);
to get a pulse signal with an output pulse width of 1ms and a period of 20ms. Then, with the help of a for loop, the required periodic pulse signal can be obtained to drive the output shaft of the servo to a rotation angle between -90° and 90°.
3.2.2 Control of multiple servos at different angles:
By controlling multiple servos at different angles, several servos can be controlled to rotate to different angles at the same time to achieve the desired control purpose.
The specific implementation method is: set a timing value t in the timer delay function (the value of t is 0 when initialized in the program), so that t increases by 1 each time the timer is finished. For example, the timing time of a timer cycle is 0.25ms, then each increase of t value is equivalent to 0.25ms. When the representative value of t reaches 20ms, that is, when t is equal to 80, it is cleared to zero. In this way, the pulse period can be controlled at 20ms. Then, by using the if statement query method, the pulse width of the same period pulse can be adjusted, which can make multiple servos rotate to different angles at the same time.
Program example: (the crystal oscillator is 4MHZ, and the pulses are output from the three ports PORTDbits.RD0, PORTDbits.RD1, and PORTDbits.RD2)
if(t=0) //Port initialization
{
PORTDbits.RD0=1
PORTDbits.RD1=1
PORTDbits.RD2=1
}
INTCONbits.TMR0IF=0; //Clear TMR0 interrupt flag
T0CON=0XCF; //Set TMR0L to work in 8-bit timer mode, internal clock, and TMR0 without frequency division
TMR0L=0X14; //Set TMR0 to generate an interrupt every 0.25ms
L1: if(INTCONbits.TMR0IF==1)
{
INTCONbits.TMR0IF==0; //Clear TMR0 interrupt flag, turn off timer
T0CON=0X4F;
t++
}
else goto L1;
if(t=4)
PORTDbits.RD0=0; //Pulse width is: 1ms
else if(t=6)
PORTDbits.RD1=0; //Pulse width is: 1.5ms
else if(t=8)
PORTDbits.RD2=0; //Pulse width is: 2ms
else(t=80)
t=0; //Pulse period is: 0.25ms*80=20ms

[page]

Through the above program combined with the for loop, three periodic pulse signals with pulse widths of 1ms, 1.5ms, and 2ms and a period of 20ms can be obtained at the three ports PORTDbits.RD0, PORTDbits.RD1, and PORTDbits.RD2, thereby achieving the requirements of different simultaneous control of three servos. Of course, using the above method, it is easy to control more than 3 servos at the same time.
3.3 Speed ​​control of servos
Through the characteristics of the servo, it can be understood that the instantaneous movement speed of the servo is determined by the cooperation of its internal DC motor and the speed change gear set. Under constant voltage drive, its value is constant. However, the average movement speed of the servo can be changed by the control method of segmented pauses. For example, the rotation with an action amplitude of 90° is subdivided into 128 pause points, and the average speed of the change from 0° to 90° is achieved by controlling the length of time of each pause point. That is to say, the continuous one-step rotation of 90 degrees is changed into a step rotation of 128 pauses. The purpose of deceleration can be achieved by the short pause between each step. Because the pause time is very short, it can be regarded as a continuous rotation of 90 degrees. Due to the limitation of space, the corresponding program examples are no longer given here. Interested readers can refer to the above program examples to write them by themselves.
4. Conclusion
The PWM waveform generated by the method introduced in this article has high accuracy and can well complete the control work of the servo. The servo works stably. The robot fish we designed and manufactured successfully realized some basic movements of fish, such as swimming forward, accelerating, stopping, turning while moving forward, etc. This also verifies that the multi-joint drive method and the control method of multiple servos are effective. This article uses the bionic robot fish as a carrier to write an article, hoping to help other servo control applications.
The author's innovation: The article
uses the bionic robot fish as the application background, uses the PIC18F452 microcontroller as the control unit of the servo, and uses the microcontroller's timer to generate a periodic pulse signal from the microcontroller's port.
References:
[1] Liu Heping. PIC 18Fxxx MCU Principle and Interface Program Design. Beijing: Beijing University of Aeronautics and Astronautics Press, 2004
[2] Li Xuehai. PIC MCU Practical Tutorial - Advanced Edition (2nd Edition). Beijing: Beijing University of Aeronautics and Astronautics Press, 2007
[3] Wang Zhiliang, Zhou Zhuo, Jin Song, Zhao Jichun. Competition Robot Manufacturing Technology. Beijing: Machinery Industry Press, 2007
[4] Zhou Zhiqiang, Wang Zhiliang, Zhang Xueyuan, Huang Haihuan. Design of Bionic Robot Fish and Research on Its Motion Control. Microcomputer Information, Vol. 22, No. 17, 2006

Reference address:Servo control of bionic robot fish based on PIC18F452 microcontroller

Previous article:PIC microcontroller AD conversion data storage and serial port efficiency
Next article:Application of PIC microcontroller in automobile electric window controller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号