Freescale's Discrete Photoelectric Tube Path Identification

Publisher:机械梦想家Latest update time:2016-01-19 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Photoelectric tube path recognition algorithm
Resources:
1. Infrared photoelectric transmitting and receiving tube
2. Voltage comparator
3. IO port of HCS12
4. ATD module of HCS12
5. ECT module of HCS12
Principle:
1. Infrared transmitting tube transmits infrared signal, and when it encounters an obstruction, it will be reflected back. If it is partially black, it will not be transmitted back (black can absorb light, and infrared rays are absorbed when they encounter black obstructions). When the receiving tube receives the reflected infrared rays, the resistance at both ends of it changes, so that different voltage values ​​can be output, and finally the path is identified according to these voltage values.
2. The voltage comparator can convert continuous quantity into switch quantity. When it is greater than the set threshold, it outputs a high level, and when it is less than the set threshold, it outputs a low level.
3. ADC can convert analog quantity into digital quantity that can be recognized by the computer, but it can process these digital signals by itself and identify the path information.
Solution:
1. Discrete path recognition algorithm.
The voltage signal output by the infrared receiving tube is compared by the voltage comparator, and a switch quantity is output. The IO of HCS12 reads the switch quantity output by the voltage comparator. Install several photoelectric tubes in a row and read the information at the same time. When a 0 value is input to the IO port connected to the transmitting tube, it is judged that the black track is under the photoelectric receiving tube. The offset angle between the black track and the car can be calculated through a certain algorithm.
Advantages: simple and easy.
Disadvantages:
  a. There is a detection blind area, that is, the area between the receiving tubes.
  b. The road information is a discrete value, and the control information obtained by the road information through the control algorithm is a step-by-step rather than a continuous control quantity, which affects the stability of the car.
2. Continuous path recognition algorithm.
The voltage signal output by the infrared receiving tube is converted by AD to a digital voltage signal. By processing these digital lights, road information that is approximately continuous can be obtained.
Advantages: The path information is continuous and the path information is more accurate.
Disadvantages:
  a. The data processing algorithm is difficult to implement.
  b. Because the parameters of the photoelectric receiving tube itself are different, the output voltage may be different under the same conditions, which brings difficulty to the processing of digital signals.
Solution selection: Because it is the first time to use the path recognition algorithm, in order to ensure the car can drive stably, a discrete path recognition algorithm that is easier to implement is selected.
Description:
1. There are 16 photoelectric receiving tubes, which are arranged in a row at a distance of Hmm from the front wheel to detect road information at the same time. The distance between each photoelectric tube is 15mm.
2. The 16 photoelectric tubes are connected to the PORTB port and PORTE port of HCS12 respectively.
3. The detection time interval is 10MS.   
    The vertical distance between the wheel and the receiving tube is 500mm.
4. The variable iRoutPlace stores the path information.
5. The array iPLace stores the path position.
6. The array iplaceAngle stores the direction angle.
7. Position information data:
    When a certain infrared receiving tube detects a black line, the comparator outputs the bit as 0, and if it is not detected, it is 1.
  iPLace[28]={0x7fff,0x3fff,0xbfff,0x9fff,0xdfff,0xcfff,0xefff, 0xf7ff,0xf3ff
              ,0xfbff,0xf9ff,0xfdff,0xfcff,0xfeff, 0xff7f,
              0xff3f,0xffbf,0xff9f,0xffdf,0xffcf,0xffef,
              0xfff7,0xfff3,0xfffb,0xfff9,0xfffd,0xfffc,0xfffe}
8. The relationship between position and offset angle
is calculated by C program. The program is as follows:
#include
#include
void main()
{
int i;
long double h,n;
n=0.0;
h=500.0;
for(i=0;i<16;i++)
{
  printf("%d--%lf--",i,atan((15.0*n)/h));
  printf("%lfn",((atan((15.0*n)/h))*180.0)/3.14);
  n++;
}
}
Running results:
Position-radian angle-angle
0--0.000000--0.000000
1--0.029991--1.719230
2--0.059928--3.435372
3--0.089758--5.145373
4--0.119429--6.846244
5--0.148890--8.535093
6--0.178093--10.209149
7--0.206992--11.865795
8--0.235545--13.502579
9--0.2637 12--15.117239
10--0.291457--16.707714
11--0.318748--18.272153
12--0.345556--19.808919
13--0.371856--21.316590
14--0.397628--22.793961
15--0.422854--24.240034
The above table can be approximated that the angle increases by 1° for each offset.
9. Angle information:
iplaceAngle[]={-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,5,5,6,7,8,9,10,11,12,13}

CODE:
#include       
#include      
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
//============================================================//
//Phototube discrete path recognition algorithm
//PORTB and PORTE are connected to the output of the voltage comparator
//16-bit modulus down counter for counting
//author: Yangtze
//time:2009/4/19/15:15:45
//============================================================//
#define iSampling 10//Path sampling time setting
int iRoutPlace;   //Path position temporary variable
int Angle;     //Angle
int iPLace[28]={0x7fff,0x3fff,0xbfff,0x9fff,0xdfff,0xcfff,0xefff,   //Path position array
                0xf7ff,0xf3ff,0xfbff,0xf9ff,0xfdff,0xfcff,0xfeff, 0xff7f
                ,0xff3f,0xffbf,0xff9f,0xffdf,0xffcf,0xffef,
                0xfff7,0xfff3,0xfffb,0xfff9,0xfffd,0xfffc,0xfffe};
            
int iplaceAngle[]={-13,-12,-11,-10,-9,-8,       //Track deviation angle
                  -7,-6,-5,-4,-3,-2,
                  -1,0,1,2,3,5,5,6,
                  7,8,9,10,11,12,13};
void Init_MDC(void)
{
    MCCTL=0xDF; //Set the modulus counter working mode, interrupt enable, counter enable
              //Division factor is 16
    MCCNT=1000; //Timer initial value (1/16M)*16*1000= 1ms
}
void pllclk(void) //16MHz
{
    SYNR=0x01;     //PLLCLK =2*OSCCLK*(SYNR + 1)/(REFDV + 1)
    REFDV=0x01;
    CLKSEL=0x80;   //Select PLL clock
}
void IO_Init()   //PORTB and PORTE are set as input ports
{
  DDRB=0X00;
  DDRE=0X00;
}
void main(void)
{
  pllclk();
  Init_PT0_ICapture();
  IO_Init();
  EnableInterrupts;
  for(;;) {}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 26 MDC_ISR(void)
{
  static unsigned int count=0;
  count++;
  if(count==iSampling)         //Read once every 100MS
    {
      iRoutPlace=PORTB; //Store the information read from the IO port into the variable iRoutPlace, port B is in the high 8 bits, port E is in the bottom 8 bitsiRoutPlace
      =iRoutPlace<<8;
      iRoutPlace|=PORTE;
      
      for(i=0;i<28;i++)   //Get the offset angle between the black track and the center axis through loop comparison
      {
          if(iPLace ==iRoutPlace)
          {
            Angle=iplaceAngle ;
          }
      }
    }
  MCFLG = 0x80;   // Clear interrupt flag
}

  Postscript:
  This program is only a path recognition program for the black track. It detects the black path through the infrared receiving tube, and then outputs the angle of position offset. There is no control program. However, if the offset angle is obtained, the control program can be easily handled. Directly compare the angle with the corresponding PWM duty cycle, and output the duty cycle of the corresponding angle to control the servo.
  If the servo control program is added, an open-loop automatic control system can be formed, and the control algorithm is a fuzzy control algorithm. Many people say that the fuzzy control algorithm is difficult to understand and difficult to use, but from this program, the fuzzy control algorithm is quite simple. Just design some control quantity tables based on your own experience, detect the path information and then compare it with the control quantity table, and output the corresponding control quantity. This is the idea of ​​fuzzy control algorithm. Of course, this is just a little idea of ​​fuzzy control algorithm, and there are many shortcomings. The
  above program is only an early version, and there are still many defects to be improved. The defects are as follows:
  1. There is no driver for the transmitting tube, and the transmitting tube is always transmitting by default. As a result, the infrared receiving tube will be greatly interfered when detecting information, and the power consumption is very large, which has a great impact on the current supply and power output of the entire system.
  Improvement method: Detection is carried out by starting one by one from a certain direction. Suppose there are 4 pairs of infrared transmitting and receiving tubes ABCD. First turn on the transmitting tube of tube D, turn off the transmitting tubes ABC, and read the information of the receiving tube D. Then turn on the transmitting tube C, turn off the transmitting tube ABD, and read the information of the receiving tube C. Read the information of each receiving tube in turn. Reading at a speed of ns, it can be approximately considered that the receiving tubes read the information at the same time.
  2. No filtering is performed. When reading road information, it may be interfered by many aspects. In order to obtain information closer to the true value, it is necessary to perform filtering and eliminate the interference noise.
  Improvement method: The method of taking the average value by reading multiple times can reduce noise interference to a certain extent.
  3. When processing the position and outputting the angle, proper processing is not performed according to experience. For example, when the offset angle is very small, it can be approximately considered that it is driving on a straight line, and the 0° angle is directly output to allow the car to drive quickly.
  4. The sampling period in the above program is set arbitrarily, without scientific basis. When setting the sampling period, it is necessary to calculate the optimal period to ensure the stability and foresight of the car's driving.
  So many defects have been found for the time being, and more defects and improvements have to be discovered in actual use to find solutions.
  Completing this program has also taught me a lot. The summary is as follows:
  1. Pay attention to the preservation of source code. C language has strong portability. It can be ported on different platforms, and it is even easier to port on the same platform. In fact, most of the programs I wrote above were written in the ECT_SPEED program before. When I wrote the program this time, I didn’t need to rewrite it at all. I could just call the program in ECT_SPEED to complete the task.
  My program calls the functions in the ECT_SPEED file: Init_MDC(), pllclk(). If it is in a large software development project, this will greatly shorten the program development cycle and reduce the program development cost.
  2. Pay attention to the writing of program documentation. In the programming exercises these days, before programming, think carefully, consider the algorithm and process of the entire program clearly, and then write it out in the form of a description document. The advantage of this is that I can finish the program in one go, unlike before, when I wrote a slightly larger program and forgot the original idea before it was finished. Another advantage is that it is convenient to read the program later.
  3. When writing a program, you must think more and look for solutions to the problem from different angles. Before writing this program, I knew that a row of infrared detection tubes could detect the black track, but when dealing with the track position, I didn’t know how to deal with it, how to let the microcontroller know where the black line is. After thinking for a long time, I understood it from this angle and finally found a way to deal with the position.
  4. Pay attention to loops and use loops as much as possible. In the comparison of the above programs, my first feeling is to use switch statements for comparison. When the input matches a case in whitch, execute the corresponding statement. But in this case, you have to write 28 case statements and write corresponding output statements. This will greatly increase the size of the program, which is fatal when the microcontroller has little memory space.
  In order to save storage space, I began to seek other ways to solve this problem. This made me think of the method of successive comparison in the bubble program. The problem with my program can also be achieved by using multiple loops. If the comparison result is true, the corresponding statement is executed.
  So I got this comparison program:
      for(i=0;i<28;i++)   //Get the offset angle between the black track and the central axis through loop comparison
      {
          if(iPLace ==iRoutPlace)
          {
            Angle=iplaceAngle ;
          }
      }  
Keywords:Freescale Reference address:Freescale's Discrete Photoelectric Tube Path Identification

Previous article:Freescale's PWM output controls the direction of the servo motor
Next article:Freescale's ECT method for detecting speed

Recommended ReadingLatest update time:2024-11-16 17:29

Freescale MC9S08AW60 Assembly Learning Notes (Part 2)
  The road must be taken step by step, and the meal must be eaten bite by bite. After having a main framework, it is time to implement a simple program: add two numbers and check the changes in the memory.  org $0070 x1 ds.b 1 x2 ds.b 1 s1 ds.b 1  org $1860 main:   clra   clrx   mov #$04,x1 ;4T, send #$04 to x1   mo
[Microcontroller]
Freescale MCU AD module brief introduction (1)
The ATD module of the S12XS series MCU has a total of 27 registers, including 6 ATD conversion control registers, 2 ATD conversion status registers, 1 ATD comparison enable register, 1 ATD comparison mode register, 1 ATD conversion input enable register and 16 ATD conversion result registers (of which 7 registers ATDC
[Microcontroller]
Freescale MCU AD module brief introduction (1)
Freescale's Timed Interrupt (PIT)
Preface:         Last time I mentioned that due to fear of English, I did not read the English DATASHEET, and took it for granted that the timer module in the XS128 microcontroller was the same as the timer module in the DG128. As a result, a fatal error was caused, and the problem was finally detected during a crazy
[Microcontroller]
Freescale MCU PIT Assembly Programming (I)
Freescale MCU (XS128 series) MCU Assembly Programming (I) I am a novice, and I learned assembly programming from a novice; assembly is not as complicated and difficult to understand as imagined, and it is quite interesting to savor it carefully. Just treat it as a hobby, and learn assembly (this has always been a bi
[Microcontroller]
Freescale MC9S12X: CAN Receive Configuration
1. MSCAN receiving process Detect receive flag: The CANRFLG register is used here. Detect frame mode (standard frame/extended frame): The CANIDR register is used here. Read identifier: The CANIDR register is used here. Determine the frame format (remote frame/data frame): The CANIDR register is used here. Read data le
[Microcontroller]
Freescale MC9S12X: CAN Receive Configuration
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号