아두이노 피드백이 있는 액추에이터

이전 튜토리얼에서는 아두이노 - 구동기에 대해 배웠습니다. 이번 튜토리얼에서는 피드백이 있는 리니어 액추에이터(피드백 리니어 액추에이터라고도 함)에 대해 배웁니다. 리니어 액추에이터의 피드백은 스트로크의 위치를 알아낼 수 있는 정보를 제공하며, 이를 이용해 위치를 제어할 수 있습니다. 구체적으로 다음 내용을 배웁니다:

준비물

1×아두이노 우노 R3 쿠팡 | 아마존
1×USB 2.0 타입 A-to-B 케이블 (USB-A PC용) 쿠팡 | 아마존
1×USB 2.0 타입 C-to-B 케이블 (USB-C PC용) 아마존
1×12V 피드백 기능이 있는 선형 액추에이터 아마존
1×BTS7960 Motor Driver Module 아마존
1×12V 전원 어댑터 아마존
1×DC 커넥터 전원 연결 잭 플러그 소켓 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 아두이노 우노용 스크루 터미널 블록 쉴드 쿠팡 | 아마존
1×(추천) Sensors/Servo Expansion Shield for Arduino Uno 쿠팡 | 아마존
1×(추천) 아두이노 우노용 브레드보드 쉴드 쿠팡 | 아마존
1×(추천) 아두이노 우노용 케이스 쿠팡 | 아마존
1×(추천) 아두이노 우노용 프로토타이핑 베이스 플레이트 & 브레드보드 키트 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

피드백 리니어 액추에이터에 관하여

피드백 리니어 액추에이터는 위치를 알아내고 제어할 수 있는 피드백 신호를 가진 리니어 액추에이터입니다. 피드백은 스트로크 위치에 비례하는 전압 값을 출력하는 포텐쇼미터입니다.

피드백 리니어 액추에이터 핀배열

피드백 리니어 액추에이터는 5개의 전선이 있습니다:

  • 액추에이터 양극(+) 전선: 이 전선은 높은 전압(12V, 24V, 48V...)으로 리니어 액추에이터를 제어하는 데 사용됩니다.
  • 액추에이터 음극(-) 전선: 이 전선은 높은 전압(12V, 24V, 48V...)으로 리니어 액추에이터를 제어하는 데 사용됩니다.
  • 5V 전선: 이 전선은 피드백 포텐쇼미터용입니다. 이 전선을 5V 또는 3.3V에 연결하세요
  • GND 전선: 이 전선은 피드백 포텐쇼미터용입니다. 이 전선을 GND에 연결하세요
  • 포텐쇼미터 전선: (피드백 전선 또는 출력 전선이라고도 함) 이 전선은 스트로크 위치에 비례하는 전압 값을 출력합니다.
피드백 리니어 액추에이터 핀배열

작동 원리

양극 전선과 음극 전선에 높은 전압을 공급하면 액추에이터의 스트로크가 확장되거나 축소됩니다. 구체적으로 다음과 같이 연결하면:

  • 12V(12V, 24V, 48V...)와 GND를 각각 양극 전선과 음극 전선에 연결: 리니어 액추에이터가 한계에 도달할 때까지 최대 속도로 확장됩니다.
  • 12V(12V, 24V, 48V...)와 GND를 각각 음극 전선과 양극 전선에 연결: 리니어 액추에이터가 한계에 도달할 때까지 최대 속도로 축소됩니다.
  • 확장하거나 축소하는 동안 액추에이터에 전원 공급을 멈추면(양극과 음극 전선 모두에 GND 연결) 액추에이터의 확장/축소가 멈춥니다

※ 주의:

  • 액추에이터를 제어하는 전압 값은 액추에이터의 사양에 따라 다릅니다. 데이터시트나 설명서를 읽고 해당 전압 값을 확인하세요.
  • 액추에이터는 부하를 지고 있는 상태에서 전원을 끊어도 위치를 유지할 수 있습니다.

포텐쇼미터 전선의 전압 값은 액추에이터의 스트로크 위치에 비례합니다. 이 전압을 측정하면 스트로크의 위치를 알 수 있습니다.

배선도

액추에이터의 두 전원 전선은 BTS7960 모듈로 구동합니다. 이 드라이버에는 강력한 H-브리지가 하나 있습니다. RPWM은 스트로크를 밖으로 밀어내고, LPWM은 스트로크를 안으로 당기며, 드라이버를 켜려면 R_EN과 L_EN이 HIGH여야 합니다. 액추에이터용 12V는 B+와 B- 나사 단자로 들어가고, 액추에이터 전선은 M+와 M-에 연결합니다. 포텐쇼미터의 작은 전선 세 개는 아두이노에 바로 연결합니다.

bts7960 드라이버 핀배열
아두이노 피드백 리니어 액추에이터 bts7960 드라이버 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

출발 도착
BTS7960 RPWM 아두이노 9번 핀
BTS7960 LPWM 아두이노 10번 핀
BTS7960 R_EN 아두이노 12번 핀
BTS7960 L_EN 아두이노 11번 핀
BTS7960 VCC 아두이노 5V
BTS7960 GND 아두이노 GND
BTS7960 B+, B- 12V 전원 어댑터의 +와 - (DC 전원 잭을 통해)
BTS7960 M+, M- 액추에이터의 양극과 음극 전선
액추에이터 5V 전선 아두이노 5V
액추에이터 GND 전선 아두이노 GND
액추에이터 포텐쇼미터 전선 아두이노 A0 핀

이제 아두이노의 5V 핀과 GND 핀은 각각 두 개의 전선에 연결됩니다. Arduino Uno에 Screw Shield V2 또는 Proto Screw Terminal Block Shield를 끼우면 쉽게 연결할 수 있습니다: 각 나사 단자가 해당 핀의 전선들을 단단히 잡아 줍니다. 배선은 위와 같습니다.

아두이노 피드백 리니어 액추에이터 bts7960 드라이버 나사 실드 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

리니어 액추에이터의 확장/축소를 제어하는 방법

아두이노 - 구동기 튜토리얼을 참조하세요

리니어 액추에이터의 위치를 찾는 방법

아래는 리니어 액추에이터에서 스트로크의 위치를 알아내는 방법을 보여줍니다.

캘리브레이션

  • 액추에이터 스트로크의 길이(밀리미터 단위)를 자로 측정하거나 데이터시트를 읽어서 확인합니다
  • 아래 코드를 실행하여 리니어 액추에이터가 완전히 확장되었을 때와 완전히 축소되었을 때의 출력 값을 확인합니다
/* * 이 아두이노 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-actuator-with-feedback */ // the code for getting the feedback when the actuator fully extended and retracted #define RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } void loop() { // extend the actuator analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); delay(20000); // wait for actuator fully extends. It will stop extending automatically when reaching the limit // read the analog in value: int POTENTIOMETER_MAX = analogRead(POTENTIOMETER_PIN); Serial.print("POTENTIOMETER_MAX = "); Serial.println(POTENTIOMETER_MAX); // retract the actuator analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255); delay(20000); // wait for actuator fully retracts. It will stop retracting automatically when reaching the limit int POTENTIOMETER_MIN = analogRead(POTENTIOMETER_PIN); Serial.print("POTENTIOMETER_MIN = "); Serial.println(POTENTIOMETER_MIN); }
  • 아래 예시처럼 시리얼 모니터에서 로그를 볼 수 있습니다
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
POTENTIOMETER_MAX = 987 POTENTIOMETER_MIN = 13
Ln 11, Col 1
Arduino Uno on COM15
2
  • 이 값들을 적어 둡니다
  • 최솟값/최댓값이 서로 바뀌었다면 코드에서 RPWM_PIN과 LPWM_PIN을 바꿉니다(또는 M+와 M- 전선을 바꿉니다)
  • 아래 코드에서 세 가지 값을 업데이트합니다
  • 액추에이터의 위치를 계산하는 아두이노 코드

    /* * 이 아두이노 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-actuator-with-feedback */ #define RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator #define STROKE_LENGTH 102 // PLEASE UPDATE THIS VALUE (in millimeter) #define POTENTIOMETER_MAX 987 // PLEASE UPDATE THIS VALUE #define POTENTIOMETER_MIN 13 // PLEASE UPDATE THIS VALUE void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } void loop() { // extend the actuator analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); int potentiometer_value = analogRead(POTENTIOMETER_PIN); int stroke_pos = map(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH); Serial.print("The stroke's position = "); Serial.print(stroke_pos); Serial.println(" mm"); }
    • 캘리브레이션한 세 가지 값을 코드에 업데이트합니다
    • 코드를 아두이노에 업로드합니다
    • 시리얼 모니터에서 결과를 확인합니다
    ∞
    Newbiely | Arduino IDE 2.3.8
    ──
    ☐
    ✕
    File
    Edit
    Sketch
    Tools
    Help
    Arduino Uno
    Newbiely.ino
    ···
    8 Serial.println("Hello World!");
    Output
    Serial Monitor
    Message (Enter to send message to 'Arduino Uno' on 'COM15')
    New Line
    9600 baud
    The stroke's position = 2 mm The stroke's position = 35 mm The stroke's position = 43 mm The stroke's position = 60 mm The stroke's position = 68 mm The stroke's position = 79 mm The stroke's position = 83 mm The stroke's position = 96 mm The stroke's position = 100 mm
    Ln 11, Col 1
    Arduino Uno on COM15
    2

    리니어 액추에이터를 특정 위치로 제어하는 방법

    /* * 이 아두이노 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-actuator-with-feedback */ #define RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator #define STROKE_LENGTH 102 // PLEASE UPDATE THIS VALUE (in millimeter) #define POTENTIOMETER_MAX 987 // PLEASE UPDATE THIS VALUE #define POTENTIOMETER_MIN 13 // PLEASE UPDATE THIS VALUE #define TOLERANCE 5 // in millimeter int targetPosition_mm = 50; // in millimeter void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver ACTUATOR_stop(); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } void loop() { int potentiometer_value = analogRead(POTENTIOMETER_PIN); int stroke_pos = map(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH); Serial.print("The stroke's position = "); Serial.print(stroke_pos); Serial.println(" mm"); if (stroke_pos < (targetPosition_mm - TOLERANCE)) ACTUATOR_extend(); else if (stroke_pos > (targetPosition_mm + TOLERANCE)) ACTUATOR_retract(); else ACTUATOR_stop(); } // extend: PWM on RPWM, LPWM is 0 void ACTUATOR_extend() { analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); } // retract: PWM on LPWM, RPWM is 0 void ACTUATOR_retract() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255); } // stop (brake): RPWM and LPWM are 0 void ACTUATOR_stop() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); }

    동영상

    비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.

    관련 튜토리얼