본문 바로가기
개발/arduino

ARDUINO POSITION CONTROL (Slide Pot&TB6612FNG)(PID control)

by 킹감자1 2018. 4. 25.

아두이노를 이용한


dc 모터 위치 제어






핀 연결 방법




부품 리스트 :


-Arduino

-Slide Pot

https://www.sparkfun.com/products/10976

-TB6612FNG

https://www.sparkfun.com/products/14450

-6127V1A180L

(analog output)








소스코드 (Source Code)



#include <SparkFun_TB6612.h>


#define AIN1 2

#define BIN1 7

#define AIN2 4

#define BIN2 8

#define PWMA 5

#define PWMB 6

#define STBY 9


#define criticalSection 2


const int offsetA = 1;

const int offsetB = 1;


Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);

Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);


/////pid set

double Kp = 1.2;

double Ki = 2.5;

double Kd = 3.2;


double error;

double error_previous;


double desired_angle = 10;

double current_angle;


double P_control, I_control, D_control;


double Time = 0.004;

double PID_control;

////


void setup()

{

  Serial.begin(115200);

}


int analogA0, analogA1;


void loop()

{

  analogA0 = analogRead(A0);

  analogA1 = analogRead(A1);

  analogA1 = changeValue(analogA1);


  if(-criticalSection < (analogA1-analogA0) &&

    (analogA1-analogA0) < criticalSection){

    motor1.brake();

  }else{

    int ret = PID_iterate(analogA1, analogA0);

    motor1.drive(ret,1);

  }

}




728x90
300x250
그리드형

'개발 > arduino' 카테고리의 다른 글

Arduino - HY-DIV268N-5A (Stepping Motor)  (0) 2018.04.20
Arduino - MicroStep Driver (Stepping Motor)  (0) 2018.04.20

댓글