라즈베리 파이 피코 피드백이 있는 액추에이터

라즈베리 파이 피코 - 액추에이터에서는 피드백이 없는 선형 액추에이터와 Raspberry Pi Pico를 함께 사용하는 방법을 배웠습니다. 이번 튜토리얼에서는 피드백이 있는 선형 액추에이터와 Raspberry Pi Pico를 함께 사용하는 방법을 배웁니다. 액추에이터의 피드백 신호는 움직이는 동안 자신의 위치를 알려주어, 어디로 갈지 제어하는 데 도움을 줍니다. 다음 내용을 살펴봅니다:

준비물

1×라즈베리 파이 피코 W 쿠팡 | 아마존
1×라즈베리 파이 피코 (또는) 쿠팡 | 아마존
1×마이크로 USB 케이블 아마존
1×12V 피드백 기능이 있는 선형 액추에이터 아마존
1×BTS7960 Motor Driver Module 아마존
1×12V 전원 어댑터 아마존
1×DC 커넥터 전원 연결 잭 플러그 소켓 쿠팡 | 아마존
1×브레드보드 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 라즈베리 파이 피코용 스크루 터미널 확장 보드 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

피드백 선형 액추에이터에 대하여

피드백 선형 액추에이터는 직선으로 움직이며, 자신의 위치를 확인하고 조정하는 장치를 갖춘 기기입니다. 액추에이터의 위치에 따라 전압 신호를 내보내는 전위차계(potentiometer)를 사용합니다.

피드백 선형 액추에이터 핀아웃

피드백 선형 액추에이터에는 다섯 개의 전선이 있습니다.

  • 양극선: 높은 전압(12V, 24V, 48V)으로 선형 액추에이터를 제어하는 전선입니다.
  • 음극선: 높은 전압(12V, 24V, 48V)으로 선형 액추에이터를 제어하는 전선입니다.
  • 5V 전선: 피드백 전위차계용 전선으로, 5V 또는 3.3V에 연결하세요.
  • GND 전선: 피드백 전위차계용 전선으로, 접지(GND)에 연결하세요.
  • 전위차계 전선: 피드백 전선 또는 출력 전선이라고도 하며, 스트로크 위치에 따라 전압 값이 바뀝니다.
피드백 선형 액추에이터 핀아웃

작동 방식

양극선과 음극선에 높은 전압을 가하면 액추에이터가 늘어나거나 줄어듭니다. 이를 설명하면, 다음과 같이 연결할 때:

  • 12V(또는 24V, 48V)를 양극선에, GND를 음극선에 연결하면: 액추에이터가 완전히 늘어날 때까지 최고 속도로 늘어납니다.
  • 12V(또는 24V, 48V)를 음극선에, GND를 양극선에 연결하면: 액추에이터가 완전히 줄어들 때까지 최고 속도로 줄어듭니다.
  • 늘어나거나 줄어드는 동안 액추에이터의 전원을 끄면(두 전선을 모두 GND에 연결), 움직임이 멈춥니다.

※ 주의:

  • 액추에이터를 동작시키는 데 필요한 전압은 액추에이터의 사양에 따라 다릅니다. 데이터시트나 설명서를 보고 알맞은 전압을 확인하세요.
  • 액추에이터는 무게를 지탱하고 있을 때에도 전기 없이 위치를 유지할 수 있습니다.

액추에이터가 움직이면 전위차계 전선의 전압이 바뀝니다. 이 전압을 측정하면 스트로크의 위치를 알아낼 수 있습니다.

BTS7960 드라이버

Pico는 BTS7960 드라이버 모듈(IBT-2)을 통해 액추에이터를 움직입니다. 그 안에서는 BTS7960B 하프 브리지 칩 두 개가 하나의 완전한 H-브리지를 이루며, 이는 액추에이터 하나에 딱 맞습니다. 강한 출력이 스트로크의 양 끝에서 액추에이터가 끌어가는 큰 전류를 감당하며, 전압 손실도 거의 없어서 액추에이터가 거의 12V 전체를 받습니다.

bts7960 드라이버 핀아웃
  • RPWM: 여기에 PWM 또는 HIGH = 액추에이터가 늘어납니다.
  • LPWM: 여기에 PWM 또는 HIGH = 액추에이터가 줄어듭니다. RPWM과 LPWM이 모두 0 = 브레이크.
  • R_EN 및 L_EN: Pico가 이 두 enable 핀을 모두 HIGH로 설정할 때까지 드라이버는 아무 일도 하지 않습니다.
  • VCC 및 GND: VCC는 보드에 있는 버퍼 칩을 위해 5V를 받습니다. 입력은 Pico의 3.3V 신호로 잘 동작합니다.
  • B+ 및 B-: 12V 액추에이터 전원입니다(5.5V부터 27V까지 허용).
  • M+ 및 M-: 액추에이터의 양극선과 음극선입니다.
  • R_IS 및 L_IS: 사용하지 않습니다.

배선도

라즈베리 파이 피코 피드백 선형 액추에이터 bts7960 드라이버 배선도

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

부품 핀 Raspberry Pi Pico 핀
BTS7960 RPWM GP16 (핀 21)
BTS7960 LPWM GP17 (핀 22)
BTS7960 R_EN GP19 (핀 25)
BTS7960 L_EN GP18 (핀 24)
BTS7960 VCC VBUS (핀 40)
BTS7960 GND GND
액추에이터 전위차계 전선 GP26 (핀 31)
액추에이터 5V 전선 3V3(OUT) (핀 36)
액추에이터 GND 전선 GND
  • 액추에이터의 5V 전선은 5V가 아니라 3.3V에 연결합니다. 그러면 전위차계 전선이 3.3V 아래로 유지되어 Pico의 아날로그 핀에 안전합니다.
  • 액추에이터의 모터 전선을 BTS7960에 연결하세요: 양극선은 M+에, 음극선은 M-에.
  • B+와 B-는 DC 전원 잭의 +와 - 단자(12V 전원 어댑터)에 연결합니다.
  • VBUS는 Pico가 USB로 전원을 받을 때만 5V를 줍니다.

선형 액추에이터의 늘이기/줄이기를 제어하는 방법

라즈베리 파이 피코 - 액추에이터를 클릭하여 Raspberry Pi Pico 액추에이터에 대해 알아보세요.

선형 액추에이터의 위치를 찾는 방법

선형 액추에이터의 스트로크 위치를 알아내는 방법은 다음과 같습니다:

보정

  • 자로 액추에이터가 움직이는 길이를 재거나, 자세한 내용은 데이터시트를 확인하세요.
  • 12V 전원 어댑터를 DC 전원 잭에 꽂으세요.
  • 선형 액추에이터가 완전히 열리거나 닫혔을 때의 값을 보려면 이 코드를 실행하세요.
/* * 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다 * 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-actuator-with-feedback */ from machine import Pin, ADC import time # Define pins RPWM_PIN = 16 # The Raspberry Pi Pico pin GP16 connected to the RPWM pin of BTS7960 (extend) LPWM_PIN = 17 # The Raspberry Pi Pico pin GP17 connected to the LPWM pin of BTS7960 (retract) R_EN_PIN = 19 # The Raspberry Pi Pico pin GP19 connected to the R_EN pin of BTS7960 L_EN_PIN = 18 # The Raspberry Pi Pico pin GP18 connected to the L_EN pin of BTS7960 POTENTIOMETER_PIN = 26 # The Raspberry Pi Pico pin GP26 (ADC0) connected to the potentiometer of the actuator # Initialize digital pins as outputs (full speed only, so no PWM is needed) rpwm = Pin(RPWM_PIN, Pin.OUT, value=0) lpwm = Pin(LPWM_PIN, Pin.OUT, value=0) r_en = Pin(R_EN_PIN, Pin.OUT) l_en = Pin(L_EN_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set R_EN and L_EN to HIGH to enable the motor driver r_en.value(1) l_en.value(1) # Main loop to extend and retract the actuator with feedback while True: # Extend the actuator lpwm.value(0) rpwm.value(1) time.sleep(20) # Wait for 20 seconds (20000 ms) # Read the potentiometer value after fully extending POTENTIOMETER_MAX = potentiometer.read_u16() print("POTENTIOMETER_MAX =", POTENTIOMETER_MAX) # Retract the actuator rpwm.value(0) lpwm.value(1) time.sleep(20) # Wait for 20 seconds (20000 ms) # Read the potentiometer value after fully retracting POTENTIOMETER_MIN = potentiometer.read_u16() print("POTENTIOMETER_MIN =", POTENTIOMETER_MIN)
  • 아래 예와 같이 Thonny 아래쪽의 Shell에 기록이 나타납니다.
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot POTENTIOMETER_MAX = 987 POTENTIOMETER_MIN = 13
MicroPython (Raspberry Pi Pico) • Board CDC @ COM29 ≡
  • 이 값들을 적어 두세요.
  • 최솟값이 최댓값보다 크면 RPWM_PIN과 LPWM_PIN을 서로 바꾸세요.
  • 다음 코드에서 세 값을 바꾸세요.

액추에이터의 위치를 계산하는 Raspberry Pi Pico 코드

/* * 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다 * 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-actuator-with-feedback */ from machine import Pin, ADC import time # Define pins RPWM_PIN = 16 # The Raspberry Pi Pico pin GP16 connected to the RPWM pin of BTS7960 (extend) LPWM_PIN = 17 # The Raspberry Pi Pico pin GP17 connected to the LPWM pin of BTS7960 (retract) R_EN_PIN = 19 # The Raspberry Pi Pico pin GP19 connected to the R_EN pin of BTS7960 L_EN_PIN = 18 # The Raspberry Pi Pico pin GP18 connected to the L_EN pin of BTS7960 POTENTIOMETER_PIN = 26 # The Raspberry Pi Pico pin GP26 (ADC0) connected to the potentiometer of the actuator # Define constants STROKE_LENGTH = 102 # Stroke length in millimeters POTENTIOMETER_MAX = 987 # Max potentiometer value POTENTIOMETER_MIN = 13 # Min potentiometer value # Initialize digital pins as outputs rpwm = Pin(RPWM_PIN, Pin.OUT, value=0) lpwm = Pin(LPWM_PIN, Pin.OUT, value=0) r_en = Pin(R_EN_PIN, Pin.OUT) l_en = Pin(L_EN_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set R_EN and L_EN to HIGH to enable the motor driver r_en.value(1) l_en.value(1) def map_value(x, in_min, in_max, out_min, out_max): # Map a value from one range to another. return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min) # Main loop to extend the actuator and read the stroke position while True: # Extend the actuator lpwm.value(0) rpwm.value(1) # Read the potentiometer value potentiometer_value = potentiometer.read_u16() # Map the potentiometer value to stroke position in millimeters stroke_pos = map_value(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH) # Print the stroke position print("The stroke's position =", stroke_pos, "mm") time.sleep(1) # Wait for 1 second before the next reading
  • 코드에서 바뀐 세 값을 수정하세요
  • 코드를 Raspberry Pi Pico에 업로드하세요
  • Thonny 아래쪽의 Shell에서 결과를 확인하세요
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot 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
MicroPython (Raspberry Pi Pico) • Board CDC @ COM29 ≡

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

/* * 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다 * 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-actuator-with-feedback */ from machine import Pin, ADC import time # Define pins RPWM_PIN = 16 # The Raspberry Pi Pico pin GP16 connected to the RPWM pin of BTS7960 (extend) LPWM_PIN = 17 # The Raspberry Pi Pico pin GP17 connected to the LPWM pin of BTS7960 (retract) R_EN_PIN = 19 # The Raspberry Pi Pico pin GP19 connected to the R_EN pin of BTS7960 L_EN_PIN = 18 # The Raspberry Pi Pico pin GP18 connected to the L_EN pin of BTS7960 POTENTIOMETER_PIN = 26 # The Raspberry Pi Pico pin GP26 (ADC0) connected to the potentiometer of the actuator # Define constants STROKE_LENGTH = 102 # Stroke length in millimeters POTENTIOMETER_MAX = 987 # Max potentiometer value POTENTIOMETER_MIN = 13 # Min potentiometer value TOLERANCE = 5 # Tolerance in millimeters targetPosition_mm = 50 # Target position in millimeters # Initialize digital pins as outputs rpwm = Pin(RPWM_PIN, Pin.OUT, value=0) lpwm = Pin(LPWM_PIN, Pin.OUT, value=0) r_en = Pin(R_EN_PIN, Pin.OUT) l_en = Pin(L_EN_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set R_EN and L_EN to HIGH to enable the motor driver r_en.value(1) l_en.value(1) def map_value(x, in_min, in_max, out_min, out_max): # Map a value from one range to another. return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min) def ACTUATOR_extend(): lpwm.value(0) rpwm.value(1) def ACTUATOR_retract(): rpwm.value(0) lpwm.value(1) def ACTUATOR_stop(): # Both 0 while R_EN and L_EN are HIGH = brake rpwm.value(0) lpwm.value(0) # Main loop to control the actuator while True: # Read the potentiometer value potentiometer_value = potentiometer.read_u16() # Map the potentiometer value to stroke position in millimeters stroke_pos = map_value(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH) # Print the stroke position print("The stroke's position =", stroke_pos, "mm") # Control the actuator based on the target position and tolerance if stroke_pos < (targetPosition_mm - TOLERANCE): ACTUATOR_extend() elif stroke_pos > (targetPosition_mm + TOLERANCE): ACTUATOR_retract() else: ACTUATOR_stop() time.sleep(0.1) # Small delay to avoid excessive CPU usage

동영상

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