AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Line follower arduino while loop1/16/2024 Y_Static(Setpoint) can be ommited, but you will need a PI-regulator, anyway with a P-regulator you will never reach the exact velocity, but close enough for the needed application.Make a Line Fan Robotic Automobile Based on Microcontroller Then do noramlization, convert 0 to 100% into your registers numbers, by multiplying/dividing, rounding. Y_static.this is a stored curve, in your case you have set this to 75% Y_regulator=(Setpoint-ProcessValue)*Kp + Y_static(Setpoint) Not I am not C or C++ programmer so the pseudocode for simple P-regulator is as follows, all numbers are float type: Also a limiting of output value is needed 0-100%. Also you will need some rearangement on number types, you should use floating point math to calculate error, Kp.then to truncate in integer, then add or subtract. The problem is that you compute erorL,R in PID() presumably at timed interrupt (flag=1), but then you set everything to zero once returned from PID(). OCR1A=-192-Kp*erorL //75% Dut圜ycle for Left Motor. OCR0A=192+Kp*erorR //75% Dut圜ycle for Right Motor. MeasuredLeftRpm_value=(events1/n2)*60000/50 ////speed in Rpm from Left/encoder/Motor.ĮrorL= setpoint - measuredLeftRpm_value ////Erorr From_Left Encoder. MeasuredRightRpm_value=(events0/n1)*(60000/50) //speed in Rpm from Right/encoder/Motor.ĮrorR= setpoint - measuredRightRpm_value //Erorr From_Right Encoder. Serial.print ("the speed (RPM) for Right Motor = ") Serial.print ("I counted for the second Motor ") Serial.print ("the speed (RPM) for the Left Motor = ") Timer/Counter 2 Interrupt(s) initialization end of Timers setup for generating PWM and interrupts. TCCR2A=0x00 //timer 2 overflow interrupt to calculate RPM from Encoder TCCR1A=0xB1 // set Timer 1 to clk/8 HZ ,fast PWM mode,tow signal inverted to each other. TCCR0B=0x02 // set Timer 0 to clk/8 HZ ,fast PWM mode,tow signal inverted to each other. setup Timer 0 and Timer 1 to generate Pwm signals Volatile signed long erorL //Eror from Left Encoder Volatile signed long erorR //Eror from Right Encoder Volatile unsigned long events1 //the number of pulses from Right Motor in 50 ms ĭouble n1=540 //the number of pulses in one turn for the Right Encoder ĭouble n2=540 //the number of pulses in one turn for the Left Encoder ĭouble measuredRightRpm_value //speed in RPM from Right encoder/Motor ĭouble measuredLeftRpm_value //speed in RPM from Left encoder/Motor Volatile unsigned long events0 //the number of pulses from Left Motor in 50 ms Is there any problem in my code or the way I do the controlling loop or understanding the controlling loop. I changed the Kp constant But my Encoder Output still Give me about 80 RPM (no change). I measured The RPM for the Left Motor by using Tachometer it is 100 RPM, I used Timer 0 and Timer 1 to generate pwm signals with a VARIETY duty-cycle=75 % to control the tow motors speed, I am working to control the speed in my line following Robot (using arduino uno),by using proportional constant Kp in a closed loop, in my code I calculate the RPM from The Right Motor and the Left Motor,I used Timer2 interrupt every 50ms to calculate the speed (Rpm) from these Encoders.
0 Comments
Read More
Leave a Reply. |