Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop in Arduino one with PID programming a circuit capable of controlling the speed of a motor, include reversal of rotation, attach the connection scheme.

image text in transcribedimage text in transcribedimage text in transcribed

Develop in Arduino one with PID programming a circuit capable of controlling the speed of a motor, include reversal of rotation, attach the connection scheme. I attach an example program with failure in speed control, without reversal of rotation and without speed control. TIT . CERO const int encoderPinA = 2; const int encoderPinB = 3; const int encoder StepsPerRevolution=16; int angle = 0; int encoder Pos = 0; bool encoder ALast = LOW: const int Pin1 = 7; const int Pin2 = 6; const int PinPWM = 5; long estadopre=0); int posant=0; //ControlPI //Interrupcion volatile long estadoant=0; volatile float velocidad=0; int refer=0); float error = 0; float I=0; float control; void setup Serial.begin(9600); pinMode(encoderPinA, INPUT_PULLUP); pinMode(encoderPinB, INPUT_PULLUP); pinMode(Pin, OUTPUT); pinMode(Pin2, OUTPUT); pinMode(PinPWM, OUTPUT); //Interrupcion attachInterrupt(digitalPinToInterrupt(encoderPinA),lectencoder,RISING): void loopo { l/error = referencia - medido 1/control = kp*error + ki*error_integral //velocidad -> control //analog Write(PinPWM map(analogRead(AO),0,1023,0,255)); digitalWrite(Pin1,HIGH): digital Write(Pin2,LOW); /*bool encoderA = digitalRead(encoderPinA); if ((encoderLast == HIGH) && (encoderA == LOW)) { if (digitalRead(encoderPinB) == LOW) encoder Pos-- else encoder Pos++; % //angle=(encoder Pos encoderStepsPerRevolution)*360/encoderStepsPerRevolution; Serial.println (encoder Pos): 1 encoder A Last = encoderA:*/ int pos = 0; float velocidad_1=0; noInterrupts(): pos = encoder Pos; velocidad_1=velocidad; interrupts(); long estadoact=micros(); float dt = ((float)(estadoact-estadopre))/1.06; float velocidad_2=(pos-posant)/dt: posant=pos; estadopre=estadoact: //velocidad_1=velocidad_1 Serial.print(velocidad_1); Serial.print(""); //Serial.println(velocidad_2); //Referencia 1/refer=map(analogRead(A0),0,1023,0,255); refer=map(analogRead(AO),0,1023,0,255); //Serial.println(refer); //parametros de control float kp = 50; float ki = 1.8; float vell = map(int)velocidad_1,0,1024,0,255); error = refer- vell; I+=error*dt: control=kp"error+ki*I; Serial.println(error); /$int dir=1; if(control255) control_pi=255: if(control_pi(0) control_pi=0; //Serial.println(control_pi): analogWrite(PinPWM control_pi); delay(1); } void lectencoder bool encoB = digitalRead(encoderPinB); int incremento = 0; if(encoB==HIGH) incremento = 1: else incremento = -1; 1 encoder Pos=encoder Pos+incremento: long estadoact = microso: float dt = ((float)(estadoact-estadoant)/1.0e6; velocidad = incremento/dt; estadoant = estadoact

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions