سلام از اساتید تقاضا دارم نگاهی به این کد که واسه تععقیب خطه و تیریپه الگوریتمه(کد کامل نیست فقط روشه ) یه نگاهی بیندازن و مشکلات رو بگن ممنون (من فقط از p استفاده کردم ) :wow: :wow: :wow: :wow: :applause: :applause: :applause: :applause:
کد:
void adc_all(void) { front=read_adc(0); right=read_adc(1); left_up=read_adc(2); right_up=read_adc(3); right_mohafez=read_adc(4); left=read_adc(5); left_mohafez=read_adc(6); } void eror_calculator(void) { if(front>=black)eror+=0; if(right>=black)eror+=20; if(right_up>=black)eror+=30; if(right_mohafez>=black)eror+=70; if(left>=black)eror+=-20; if(left_up>=black)eror+=-30; if(left_mohafez>=black)eror=-70; } void motor(void) { if(eror>=0&&eror<=120) { motor_right_pwm=1015; motot_left_pwm=1015-p; if(motot_left_pwm<0) { motor_left=back; motor_right=front; } else { motor_right=front; motor_left=front; } } else if(eror<0&&error<=-120) { motot_left_pwm=1015; motor_right_pwm=1015-p; if(motot_right_pwm<0) { motor_right=back; motor_left=front; } else { motor_left=front; motor_right=front; } } } void kp(void) { p=kp*eror; } void line(void) { adc_all(); eror_calculator(); kp(); motor(); }
