산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

아두이노 나노와 SG90 서보로 만드는 DIY 2축 모션 레이싱 시뮬레이터

프로젝트 개요

SimTools 모션 시뮬레이터 소프트웨어와 아두이노 나노, 저가 SG90 마이크로 서보 2개를 조합하여 2축(롤/피치) 모션 플랫폼을 구현합니다. 게임에서 전송되는 텔레메트리 데이터(가속도, 각도 등)를 SimTools가 시리얼로 아두이노에 전송하면, 아두이노가 서보를 구동해 플랫폼을 기울이는 방식입니다. 소규모 프로토타입이며, 실사용 시 대형 서보/모터 드라이버로 확장 가능합니다.

하드웨어 구성

부품수량비고
아두이노 나노 R31시리얼 수신 및 서보 PWM 제어
SG90 마이크로 서보 모터2롤(좌우), 피치(전후) 축 구동
납땜 도구, 브레드보드/퍼프보드, 점퍼 와이어-회로 구성용

소프트웨어 구성

SimTools 설정 요약

  1. SimTools 다운로드: xsimulator.net
  2. Live for Speed 데모 다운로드: lfs.net (SimTools 데모 모드에서 테스트 가능)
  3. SimTools에서 아두이노 시리얼 포트(COMx, 9600bps) 설정, 액추에이터 2개(R, L) 매핑
  4. 사용자 매뉴얼: PDF 다운로드

아두이노 펌웨어 전체 코드

//********************************************************************************************
// RC Model Servo for SimTools Motion Software
// Original by EAOROBBIE, Modified by aarondc
//********************************************************************************************
#include 
// #define DEBUG 1  // 디버그 출력 활성화 시 주석 해제

const int kActuatorCount = 2;
const char kActuatorName[kActuatorCount] = { 'R', 'L' };      // SimTools가 보내는 액추에이터 식별 문자
const int kPins[kActuatorCount] = { 4, 5 };                    // 서보 연결 핀
const int kActuatorScale[kActuatorCount][2] = {
  { 0, 179 },   // Right 액추에이터 스케일링 (입력 0~255 → 서보 0~179)
  { 179, 0 }    // Left 액추에이터 스케일링 (반전)
};
const char kEOL = '~';        // 값 구분자 (틸드)
const int kMaxCharCount = 3;  // 최대 3자리 숫자(0~255)

Servo actuatorSet[kActuatorCount];
int actuatorPosition[kActuatorCount] = { 90, 90 };
int currentActuator = 0;
int valueCharCount = 0;

enum TPortState { psReadActuator, psReadValue };
TPortState currentState = psReadActuator;

void setup() {
  for (int i = 0; i < kActuatorCount; i++) {
    actuatorSet[i].attach(kPins[i]);
    updateActuator(i);
  }
  Serial.begin(9600);
}

void loop() { }  // 모든 처리는 serialEvent()에서

void serialEvent() {
  char tmpChar;
  int tmpValue;
  while (Serial.available()) {
    // 1단계: 액추에이터 이름 문자 읽기
    if (currentState == psReadActuator) {
      tmpChar = Serial.read();
      #ifdef DEBUG
      Serial.print("read in "); Serial.println(tmpChar);
      #endif
      for (int i = 0; i < kActuatorCount; i++) {
        if (tmpChar == kActuatorName[i]) {
          currentActuator = i;
          currentState = psReadValue;
          actuatorPosition[currentActuator] = 0;
          valueCharCount = 0;
          #ifdef DEBUG
          Serial.print("which is actuator "); Serial.println(i);
          #endif
          break;
        }
      }
    }
    // 2단계: 숫자 값 읽기 (최대 3자리, '~'로 종료)
    if (currentState == psReadValue) {
      while (valueCharCount < kMaxCharCount && Serial.available()) {
        tmpValue = Serial.read();
        if (tmpValue != kEOL) {
          tmpValue -= 48;  // ASCII '0' 보정
          if (tmpValue < 0 || tmpValue > 9) tmpValue = 0;
          actuatorPosition[currentActuator] = actuatorPosition[currentActuator] * 10 + tmpValue;
          valueCharCount++;
        } else break;
      }
      // 값 수신 완료 시 서보 업데이트
      if (tmpValue == kEOL || valueCharCount == kMaxCharCount) {
        #ifdef DEBUG
        Serial.print("read in "); Serial.println(actuatorPosition[currentActuator]);
        #endif
        // 0~255 입력 범위를 서보 각도 범위로 매핑
        actuatorPosition[currentActuator] = map(actuatorPosition[currentActuator], 0, 255,
                                                 kActuatorScale[currentActuator][0],
                                                 kActuatorScale[currentActuator][1]);
        #ifdef DEBUG
        Serial.print("scaled to "); Serial.println(actuatorPosition[currentActuator]);
        #endif
        updateActuator(currentActuator);
        currentState = psReadActuator;
      }
    }
  }
}

void updateActuator(int thisActuator) {
  actuatorSet[thisActuator].write(actuatorPosition[thisActuator]);
}

회로도

아두이노 나노와 SG90 서보로 만드는 DIY 2축 모션 레이싱 시뮬레이터

제작 팁 및 확장

참고 커뮤니티

제조공정

  1. 라즈베리 파이용 DIY 적외선 모션 센서 만들기 – 단계별 가이드
  2. 나만의 LUMAZOID 만들기: DIY 아두이노 음악 비주얼라이저
  3. 아두이노와 스마트폰으로 만드는 스마트 전압계 – 초간단 DIY 프로젝트
  4. 아두이노, 구글 카드보드, 블루투스로 DIY VR 스케이트보드 만들기
  5. 아두이노 나노로 만든 스마트 모션 감지 물총
  6. DIY 아두이노 라디오닉스 EMR 치료 기기 제작
  7. 아두이노로 만드는 휴대용 RFID 도어락 - 단계별 완벽 가이드
  8. DIY 3축 CNC VMC: 정밀 밀링 머신 직접 제작하기
  9. 아두이노 나노와 GY-906으로 만드는 비접촉 적외선 온도계
  10. DIY 비행 시뮬레이터 러더 페달 제작: 단계별 완벽 가이드