Methods
(static) pwm(outputId, pulseWidth)
Controls the pwm signal outputs.
Parameters:
| Name | Type | Description |
|---|---|---|
outputId |
string | "esc", "servo1", "servo2", or "servo3" |
pulseWidth |
number | Pulse width between 1000 and 2000 microseconds. Set to 0 to disable the output signal. |
Example
//Sets the motor at throttle 1300
rcb.console.print("Allow time to initialize ESC");
rcb.output.pwm("esc",1000);
rcb.wait(callback, 4);
function callback(){
rcb.console.print("Run motor");
rcb.output.pwm("esc",1300);
rcb.wait(rcb.endScript, 5);
}
(static) ramp(outputId, from, to, duration, callback)
Smoothly ramps up or down the pwm signal. For safety reasons, will only work if the output was previously activated using the pwm function.
Parameters:
| Name | Type | Description |
|---|---|---|
outputId |
string | "esc", "servo1", "servo2", or "servo3" |
from |
number | Ramp starting value between 1000 and 2000 microseconds. |
to |
number | Ramp finishing value between 1000 and 2000 microseconds. |
duration |
number | The duration of the ramp in seconds. |
callback |
rampDone | Function to execute when the ramp is finished. |
Example
//Illustrates the use of the ramp function
rcb.console.print("Initializing ESC...");
rcb.output.pwm("esc",1000);
rcb.wait(callback, 4);
function callback(){
var from = 1000;
var to = 1400;
var duration = 15;
var done = rcb.endScript;
rcb.output.ramp("esc", from, to, duration, done);
}
(static) steps(outputId, from, to, steps, callbackopt)
Steps up or down the pwm signal allowing you to perform tasks between each step. For safety reasons, will only work if the output was previously activated using the pwm function.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
outputId |
string | "esc", "servo1", "servo2", or "servo3" | |
from |
number | Steps starting value between 1000 and 2000 microseconds. | |
to |
number | Steps finishing value between 1000 and 2000 microseconds. | |
steps |
integer | Number of steps to perform. | |
callback |
stepDone |
<optional> |
Function to execute when a step finishes. This function should introduce some sort of delay for the steps function to be effective. |
Example
//Illustrates the use of the steps function
rcb.console.print("Initializing ESC...");
rcb.output.pwm("esc",1000);
rcb.wait(callback, 4);
var sensorPrintId;
function callback(){
var from = 1000;
var to = 1400;
var steps = 10;
rcb.output.steps("esc", from, to, steps, stepFct);
}
//Function called at every step
function stepFct(lastStep, nextStepFct){
if(lastStep){
rcb.endScript();
}else{
rcb.console.setVerbose(false);
rcb.wait(function(){ //2 seconds settling time
//Do stuff here... (record to log file, calculate something, etc...)
rcb.sensors.read(readDone);
}, 2);
}
//Function called when read complete
function readDone(result){
var speed = result.motorSpeed.displayValue;
var unit = result.motorSpeed.displayUnit;
if(sensorPrintId === undefined) sensorPrintId = rcb.console.print("");
rcb.console.overwrite("Motor Speed: " + speed + " " + unit, sensorPrintId);
//When done working, go to the next step
rcb.console.setVerbose(true);
nextStepFct();
}
}