Vous êtes sur la page 1sur 7

Documentation of Software ( code ) of embedded System of RC HoverCraft control and Algorithm.

Like every system, this system has input, processing and output, basic program structure is derscribed in the following flowchart

Initialization (power on)

Read input signal from RC transmitter( 3 PWM input)

Process (algorithm will be discussed later)

Output Signal (2 brushless DC motors and and one servo motor)

PWM from channel 3 PWM input copture zasis PWM from channel 1 PWM input copture xasis

PWM from channel 2 PWM input copture yasis

Decoding y-

axis
Forward thrust

Decoding Xaxis
Torque for steering

PROCESS

Encoding servo
PWM output compare servo PWM to servo

Encoding thrust
PWM output compare thrust fan

PWM output compare LIFT fan

PWM to Lift fan

PWM to EDF

Input capture
By using timer of the system, microcontroller have to read 3 signals generated by radio controller transmitter, these three signals correspond to three control sticks on the transmitter which is human interface, to be controlled by operator which in turn will control hovercraft according to data processing algorithm . these signals are in form of PWM ( pulse width modulation) of period of 20ms. It is done by using timer peripheral of the STM32f100 in input capture mode. Reading a PWM signal means that we are reading duty cycle of square wave.

DECODING of PWM and detail about RC transmitter


After reading signal, we have a number stored in a variable , which represents ON time of square wave in microseconds. We have three of these and needs to be processed to control hovercraft. This data depends of parameters on RC transmitter, parameters may change if RC transmitter is changed. So values of parameters are defined in the beginning of program, as meaning of input data depends on it. RC transmitter: there are to two sticks available on RC tx, and each can move in x and y axis, each axiss output is termed as channel of RC tx, on channel one and channel we have x axis and y axis respectively. these are related to speed and turning of hovercraft. While third channel Is y-axis of left stick. Which controls the lift of hovercraft. duty cycle time in microseconds is described in the following x_max_rc=1928; when stick is at rightmost x_mid_rc=1536; when stick is at mid in x axis x_min_rc=1210; when stick is at leftmost y_max_rc=1860; when stick is at upward y_mid_rc=1536; when stick is at mid in y axis y_min_rc=1184; when stick is at downward for any position of stick, for its x and y position, a PWM of a duty cycle is generated, who value is inbetween above described limits, with respect to these limits, relative position of stick is calculated by linear transformation, and x, y axis values are converted into a new scale ranging from -100 to 100, for example maximum value of x-axis corresponds to 100, mid value of x-axis corresponds to 0 and minmun x-axis value corresponds to -100, it is important to perform scaling, because RC duty cycle value is not distributed equally above and below the midpoint, as these two differences x_max_rc - x_mid_rc=392 and x_mid_rc - x_min_rc=326 are not equal. Slop above and below the midpoint is different. They are transform linearly by using following piece of code, and the result is also shown graphically if(pwm_x>x_mid_rc) { x=((100)/(x_max_rc-x_mid_rc))*(pwm_x-x_mid_rc); } else if(pwm_x<x_mid_rc) { x=((100)/(x_mid_rc-x_min_rc))*(pwm_x-x_mid_rc); } else { x=0; }

x-axis transformation 100

Output of DECODER

50

-50

-100 1200

1300

1400

1500 1600 1700 input of decoder from RC tx

1800

1900

2000

Slight change in slop can be observed. Transformation of y axis


y-axis transformation 100

Output of DECODER

50

-50

-100 1100

1200

1300

1400 1500 1600 input of decoder from RC tx

1700

1800

1900

Processing
Now we have proper Data in proper Scale to be processed further. We can process this information in our desired way and according to desired algorithm to make hovercraft stable and provide high level of stability, we term this process as DECODING of PWM

ENCODING of data
After processing we have information in variables which are OUTPUT of the system and requires to be modulated again, so to control speed of motors. We have three devices to be controlled , all of them requires PWM signals to be operated. These devices have their own parameters as described below. 1) brushless DC motor for LIFT 1000 us of +width corresponds to 0% speed 2000 us of +width corresponds to100% speed

2) brushless DC motor for ELECTRIC DUCT FAN 1000 us of +width corresponds to 0% speed 2000 us of +width corresponds to100% speed 3) Servo motor for rotating EDF 720 us of +width corresponds to -90 degrees 1520 us of +width corresponds to 0 degrees 2320 us of +width corresponds to +90 degrees These parameters are defined in the beginning of code, with some limitations #define min_servo 720 #define mid_servo 1520 #define max_servo 2320 #define min_thrust 1000 #define mid_thrust 1000 #define max_thrust 1500 #define mid_lift 1000 #define max_lift 1800 However value of Thrust can go upto 2000 us but we have limited it to 1500 us which is 50%, similarly we have limited lift to 80% of maximum After Processing, this data is modulated to PWM
ENCODING OF THRUST 1500 1450 1400 1350

ENCODED thrust

1300 1250 1200 1150 1100 1050 1000 -20 0 20 40 THRUST 60 80 100 120

Notice that when THRUST is below 0, it is limited to 1000 us, and when thrust goes above 100, it is limited to 1500. Similarly encoding of lift and servo is done.

Output Compare
Now a signal is to be generated depending upon encoded data, i.e encoded data represents the +width of PWM. It is done by using timer peripherals output compare mode.

Detail of Input Capture and Output Compare process


Pwmcapture.c pwmcapture.h Contains function for capturing a pwm. there are three functions defined for three PWM signals they utilize timer 3 and timer 4 in following configuration, Timer 3 channel 1 and Timer 3 Channel 2 are used to capture PWM A from GPIO pin A6, inpute capture code. Once the timer is turned on after configuration, channel one captures the value of counter when a rising edge is detected at input pin of channel, channel two captures the value of counter at falling edge and stores it in in CCR2 register of timer 3. Detection of falling edge followed rising edge means that ON time has been passed away of PWM, after the detection of positive edge or negative edge corresponding flags are raised by hardware indicating when function input_PWM_A() is called, it calculate the difference between CCR register of channel 1 and channel 2

using timer 3 PWM A:utilizing channel 1 and 2 for reading one pwm TIM3_ch1 channel 1: configured for rising edge (CCER |=0x0001) CC1P=0(rising polarity),CC1E=1. TIM3_ch2 channel 2: configured for falling edge (CCER |=0x0030) CC2P=1(falling polarity),CC2E=1. TI1 mapped on IC1 (CCMR1 |=0x0001 ) IC1=>TI1 TI1 mapped on IC2 (CCMR1 |=0x0200 ) IC2=>TI1 read PWM from A6 for PWM A ,so configure it as input floating

PWM B:utilizing channel 3 and 4 for reading one pwm TIM3_ch3 channel 3: configured for rising edge (CCER |=0x0100) CC3P=0(rising polarity),CC3E=1.

TIM3_ch4 channel 4: configured for falling edge (CCER |=0x3000) CC4P=1(falling polarity),CC4E=1 TI3 mapped on IC3 (CCMR2 |=0x0001 ) IC3=>TI3 TI3 mapped on IC4 (CCMR2 |=0x0200 ) IC4=>TI3 read PWM from B0 for PWM B ,so configure it as input floating CCMR1=0x0201; CCMR2=0x0201; CCER=0x3131; Mapping of channels of timer 3 on I/O pins TIM3_cH1->TI1-> Port A6 TIM3_cH2->TI2-> Port A7 TIM3_cH3->TI3-> Port B0 TIM3_cH4->TI4-> Port B1