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

이전 튜토리얼에서는 라즈베리 파이 피코 - 액추에이터에서 피드백 없이 리니어 액추에이터와 Raspberry Pi Pico를 함께 사용하는 방법에 대해 배웠습니다. 이번 튜토리얼에서는 피드백 기능이 있는 리니어 액추에이터와 Raspberry Pi Pico를 함께 사용하는 방법을 알아봅니다. 액추에이터의 피드백 신호는 움직임 중 자신의 위치를 제공하여 우리가 이동 경로를 제어하는 데 도움을 줍니다. 다음 내용을 살펴보겠습니다:

준비물

1×라즈베리 파이 피코 W 아마존
1×라즈베리 파이 피코 (또는) 아마존
1×마이크로 USB 케이블 아마존
1×12V 피드백 기능이 있는 선형 액추에이터 아마존
1×L298N 모터 드라이버 모듈 쿠팡 | 아마존
1×12V 전원 어댑터 아마존
1×DC 커넥터 전원 연결 잭 플러그 소켓 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 라즈베리 파이 피코용 스크루 터미널 확장 보드 아마존
공개: 이 섹션에서 제공된 링크 중 일부는 제휴 링크입니다. 이 링크를 통해 구매한 경우 추가 비용없이 수수료를 받을 수 있습니다. 지원해 주셔서 감사합니다.

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

피드백 선형 액추에이터는 직선으로 움직이는 장치로, 그 위치를 확인하고 조정하는 시스템이 포함되어 있습니다. 이 장치는 액추에이터의 위치와 관련된 전압 신호를 보내는 포텐쇼미터를 사용합니다.

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

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

  • Positive Wire: 이 와이어는 높은 전압(12V, 24V, 48V)을 사용하여 선형 액추에이터를 제어합니다.
  • Negative Wire: 이 와이어는 높은 전압(12V, 24V, 48V)을 사용하여 선형 액추에이터를 제어합니다.
  • 5V Wire: 이 와이어는 피드백 포텐셔미터를 5V 또는 3.3V에 연결합니다.
  • GND Wire: 이 와이어는 피드백 포텐셔미터를 접지(GND)에 연결합니다.
  • Potentiometer Wire: 피드백 또는 출력 와이어라고도 불리는 이 와이어는 스트로크 위치에 따라 전압 값이 변경됩니다.
피드백 선형 액추에이터 핀아웃

작동 방식

양극과 음극 전선에 고전압을 인가하면 액추에이터가 확장되거나 수축됩니다. 이를 설명하기 위해, 만약 연결하면:

  • 12V(또는 24V, 48V)를 양선에 연결하고 GND를 음선에 연결하면, 액추에이터는 최대 속도로 확장되어 완전히 확장됩니다.
  • 12V(또는 24V, 48V)를 음선에 연결하고 GND를 양선에 연결하면, 액추에이터는 최대 속도로 수축되어 완전히 수축됩니다.
  • 액추에이터가 확장 또는 수축 중일 때 전원이 꺼지면(두 선 모두에 GND를 연결하여) 동작이 멈춥니다.

※ 주의:

  • 액추에이터를 작동시키는 데 필요한 전압은 해당 기기의 특정 기능에 따라 달라집니다. 올바른 전압을 확인하려면 데이터시트나 매뉴얼을 참조하세요.
  • 액추에이터는 전기가 없어도 무게를 지탱하면서 제 위치를 유지할 수 있습니다.

액추에이터가 움직이면 포텐셔미터 와이어의 전압이 변화합니다. 이 전압을 측정하여 스트로크의 위치를 파악할 수 있습니다.

배선도

배선을 시작하기 전에 L298N 모듈에서 모든 세 개의 점퍼를 제거하십시오.

라즈베리 파이 피코 리니어 액추에이터 l298n 드라이버 배선도

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

선형 액추에이터 확장/축소 제어 방법

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

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

리니어 액추에이터의 스트로크 위치를 찾는 방법은 다음과 같습니다:

교정

  • 자를 사용하여 액추에이터가 얼마나 이동하는지 확인하거나 자세한 내용은 데이터시트를 참조하십시오.
  • 리니어 액추에이터가 완전히 열리거나 닫힌 상태일 때의 값을 확인하려면 이 코드를 실행하십시오.
/* * 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다 * 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-actuator-with-feedback */ from machine import Pin, ADC import time # Define pins ENA_PIN = 5 # The Raspberry Pi Pico pin GP5 connected to the EN1 pin of L298N IN1_PIN = 4 # The Raspberry Pi Pico pin GP4 connected to the IN1 pin of L298N IN2_PIN = 3 # The Raspberry Pi Pico pin GP3 connected to the IN2 pin of L298N POTENTIOMETER_PIN = 26 # The Raspberry Pi Pico pin GP26 (ADC0) connected to the potentiometer of the actuator # Initialize digital pins as outputs ena = Pin(ENA_PIN, Pin.OUT) in1 = Pin(IN1_PIN, Pin.OUT) in2 = Pin(IN2_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set ENA_PIN to HIGH to enable the motor driver ena.value(1) # Main loop to extend and retract the actuator with feedback while True: # Extend the actuator in1.value(1) in2.value(0) 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 in1.value(0) in2.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 ≡
  • 이 값들을 입력하십시오.
  • 최소 값이 최대 값보다 크면, IN1_PIN과 INI2_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 ENA_PIN = 5 # The Raspberry Pi Pico pin GP5 connected to the EN1 pin of L298N IN1_PIN = 4 # The Raspberry Pi Pico pin GP4 connected to the IN1 pin of L298N IN2_PIN = 3 # The Raspberry Pi Pico pin GP3 connected to the IN2 pin of L298N 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 ena = Pin(ENA_PIN, Pin.OUT) in1 = Pin(IN1_PIN, Pin.OUT) in2 = Pin(IN2_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set ENA_PIN to HIGH to enable the motor driver ena.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 in1.value(1) in2.value(0) # 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 ENA_PIN = 5 # The Raspberry Pi Pico pin GP5 connected to the EN1 pin of L298N IN1_PIN = 4 # The Raspberry Pi Pico pin GP4 connected to the IN1 pin of L298N IN2_PIN = 3 # The Raspberry Pi Pico pin GP3 connected to the IN2 pin of L298N 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 ena = Pin(ENA_PIN, Pin.OUT) in1 = Pin(IN1_PIN, Pin.OUT) in2 = Pin(IN2_PIN, Pin.OUT) # Initialize the potentiometer as an ADC pin potentiometer = ADC(Pin(POTENTIOMETER_PIN)) # Set ENA_PIN to HIGH to enable the motor driver ena.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(): in1.value(1) in2.value(0) def ACTUATOR_retract(): in1.value(0) in2.value(1) def ACTUATOR_stop(): in1.value(0) in2.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 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.