는 서보를 제어하려면, 당신은에있는 신호가 변조 신호 펄스 폭을 보내 주기적으로 반복합니다. 각 기간, 즉 신호 지점과 반복 지점 사이의 시간은 켜기와 끄기의 두 부분으로 구성됩니다. 온은 고전압 (예를 들어, 바이어스 전압과 동일)이고, 오프는 저전압 (예를 들면, 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);