2014-11-01 5 views
2

저는 Node.js로 제어하려고하는 인텔 갈릴레오를 가지고 있지만 몇 가지 문제가 있습니다. 내가 사용하고있는 라이브러리에는 핀의 바이너리 및/또는 아날로그 값을 변경하는 예제가 있지만 서보 모터를 제어하는 ​​데 특별한 것은 없습니다. 현재 가지고있는 코드는 다음과 같습니다.노드 용 Galileo MRAA로 제어 서보

var B = 3975; 
var mraa = require("mraa"); 
var servo = new mraa.Aio(1);//connects to the servo 

문제는 서보를 제어하는 ​​방법을 모르고 있으며 MRAA에 대한 문서는 거의 존재하지 않습니다. 이전에 비슷한 일을 한 사람이 있었고 도움을 줄 수 있습니까?

감사합니다.

답변

0

일반적으로 Servos는 PWM (Pulse-Width Modulation) 제어를 사용합니다. 서보 제어 라인을 '~'표시가있는 디지털 핀 중 하나에 연결해야합니다. 이 기호는 핀이 PWM 데이터를 생성 함을 나타냅니다. 그런 다음 서보 유형을 Google로 받아 들여 PWM 매개 변수를 확인하십시오. 그런 다음 mraa PWM 예제를 따라 PWM 핀에 적절한 값을 설정할 수 있습니다. 에 mraa에 대한

0

PWM 예 (하지만 에디슨은 갈릴레오에 작동하지만 기간이 62500이어야 함)

mraa = require('mraa'); 
servo = new m.Pwm(3);//Pin 3 
servo.enable(true); 
servo.period_us(19000000) //PWM Period https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM 
servo.write(1); 
sleep(1000); 
servo.write(0); 
sleep(1000); 
servo.write(0.5); 
0

는 서보를 제어하려면, 당신은에있는 신호가 변조 신호 펄스 폭을 보내 주기적으로 반복합니다. 각 기간, 즉 신호 지점과 반복 지점 사이의 시간은 켜기와 끄기의 두 부분으로 구성됩니다. 온은 고전압 (예를 들어, 바이어스 전압과 동일)이고, 오프는 저전압 (예를 들면, 0 볼트와 동일)이다. 기간에는 시간 기간 인 시간이 있으며, 그 역수는 빈도입니다. 온 타임과 오프 타임의 비율을 듀티 사이클이라고하며, 듀티 사이클의 범위는 0.0에서 1.0 사이입니다. 서보 모터는 듀티 사이클에 해당하는 각도에 도달 할 때까지만 회전하여 정지합니다. https://iotdk.intel.com/docs/master/mraa/node/

그리고 말을 메모 : 여기에 아무것도하기 전에

는 mraa Node.js를 설명서에 대한 링크입니다 mraa는 낮은 수준의 프레임 워크입니다, 그래서 이것은 서보를 사용하여 처음 인 경우, 내가 것 나중에 mraa를 사용하는 것을 늦추고 CylonJS를 먼저 사용하십시오. 인텔 Eison에서 CylonJS를 사용하여 서보를 제어하는 ​​지침서는 Intel Galileo와 같습니다. http://slideplayer.com/slide/7959041/ 이전에 Intel Edison 키트에서 실행 한 아주 좋은 예입니다.

말하자면,이 튜토리얼을 끝내고 mraa node.js에서 서보를 시도하고 싶다면, Ctrl-C를 눌러서 프로그램을 종료 할 때까지 서보를 회전시키는 튜토리얼이 있습니다. 듀티 사이클을 0에서 시작하여 1까지 증가시킨 다음 0까지 감소시키고 다시 루프합니다. 이 코드는 C 코드를 https://navinbhaskar.wordpress.com/2016/02/21/cc-on-intel-edisongalileo-part3-pwm/으로 번역 한 것으로 번역을 테스트하지 않았습니다.

/*translation of C++ code at 
https://navinbhaskar.wordpress.com/2016/02/21/cc-on-intel-edisongalileo-part3-pwm/ 
mraa node.js documentation at: 
https://iotdk.intel.com/docs/master/mraa/node/ 
*/ 
"use strict"; 


const mraa = require("mraa"); 
const spawnSync = require('child_process').spawnSync; 

const PWM_PIN = 5 ;  /**< The pin where the LED is connected */ 

var keepRunning= false; 

///** Signal handler used to stop this application cleanly */ 
/* 
    * Associate ctrl+c with our handler that clears the 'keepRunning' 
    * flag that allows us to stop the PWM when exiting 
    */ 
process.on('SIGINT',() => { 
    keepRunning = false; 
}); 

//Step 1: Initialize the mraa system 

var result =mraa.init(); 
if(result == mraa.Result.SUCCESS) 
    console.log("mraa initialization succeded."); 
else 
    console.log("mraa initializtion failed.") 

/* Step2: Initialize D5 for PWM operation */ 
var pwm_interface = mraa.PWM; 

var owner =true; 
var chipid= 1; 
pwm_interface.Pwm(PWM_PIN,owner,chipid); 
/* 
    * Control the period with "mraa_pwm_period_us" 
    * 
    *  +----------------+    +----------------+    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  |    |    |    |    | 
    *  +    +----------------+    +----------------+ 
    *  ^        ^
    *  |         | 
    *  |<---------- Period ------------->| 
    *  |    ^    | 
    *  |    |     | 
    *      | 
    *  pwm_interface.period_us(5000); 
    */ 

    /* Step3: Set the period on the PWM pin */ 
    const PWM_Period_in_microseconds=5000; 
    pwm_interface.period_us(PWM_Period_in_microseconds);  // Set the period as 5000 us or 5ms 

    /* Step4: Enable the PWM pulse on the pin */ 
    var pwm_enabling_result= pwm_interface.enable(true); 

    var delta = 0.05; /* Variation on the duty cycle */ 
    var duty = 0.0;  /* 0% duty cycle */ 
    keepRunning = true; 
    const sleep_duration_in_Microsecond=50000; 

while (keepRunning){ 
     if (duty >= 1) 
     { 
      duty = 1;   // Intensity of LED at highest 
      delta = -0.05;  // Need to decrease the duty cycle 
     } 
     else if (duty <= 0) 
     { 
      duty = 0;   // Intensity of LED at the lowest 
      delta = +0.05;  // Need to increase the duty cycle 
     } 
     /* 
     * Control the duty cycle with "write" 
     * +------+       +------+        
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * |  |       |  |       
     * +  +----------------------------+  +---------------------------+ 
     * ^ ^
     * |  | 
     * |<---->| 
     *  ^
     *  |----------------- 
     *       | 
     * pwm_interface.write(0.2); 
     * 
     */ 

    /* Step5: Use the function 'mraa_pwm_write' to set the duty cycle */ 
    pwm_interface.write(duty); 
    /* Wait for some time */ 
    var sleep = spawnSync('usleep', [sleep_duration_in_Microsecond]); 

    duty = duty + delta; 
} 

    /* Step6: Stop the PWM when not required */ 
    pwm_interface.enable(false);