output

rcb. output

new output()

Output control interface functions.
Source:

Methods

(static) pwm(outputId, pulseWidth)

Controls the pwm signal outputs, effective immediatly.
Parameters:
Name Type Description
outputId string "esc", "servo1", "servo2", "servo3", "escA", "escB", "servoA", "servoB". escA, servoA, escB, servoB are for the Series 1780 coaxial channels. For the mono version of Series 1780, use the A side. Can also be an array of multiple outputs eg. ['escA','servoA'].
pulseWidth number Pulse width between 700 and 2300 microseconds. Must be an array if the first parameter is also an array.
Source:
Examples
//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);
}
//Shows how to use multiple outputs simultaneously 
rcb.console.print("Allow time to initialize ESC");
rcb.output.pwm(["escA","escB"],[1000,1000]);
rcb.wait(callback, 4);

function callback(){
    rcb.console.print("Run motor");
    rcb.output.pwm(["escA","escB"],[1300,1400]);
    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. To cancel/update a ramp in progress, simply call this function again with new parameters. For example if you want to stop the ramp with the output at 1000us, call: rcb.output.ramp("esc", 1000, 1000, 0, null); Note that only one control function can be used simultaneously. You must wait for the ramp/steps function to start another.
Parameters:
Name Type Description
outputId string outputId - "esc", "servo1", "servo2", "servo3", "escA", "escB", "servoA", "servoB". escA, servoA, escB, servoB are for the Series 1780 coaxial channels. For the mono version of Series 1780, use the A side. Can also be an array of multiple outputs eg. ['escA','servoA'].
from number Ramp starting value between 700 and 2300 microseconds. Must be an array if the first parameter is also an array.
to number Ramp finishing value between 700 and 2300 microseconds. Must be an array if the first parameter is also an array.
duration number The duration of the ramp in seconds.
callback rampDone Function to execute when the ramp is finished.
Source:
Examples
//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);
}
//Same as example above but with multiple outputs simultaneously.
rcb.console.print("Initializing ESC...");
var outputs = ["escA","escB"];
var minVal = [1000,1000];
var maxVal = [1400,1300];
rcb.output.pwm(outputs,minVal);
rcb.wait(callback, 4);

function callback(){
    var duration = 15;
    var done = rcb.endScript;
    rcb.output.ramp(outputs, minVal, maxVal, 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. Note that only one control function can be used simultaneously. You must wait for the steps/ramp function to finish to start another.
Parameters:
Name Type Attributes Description
outputId string outputId - "esc", "servo1", "servo2", "servo3", "escA", "escB", "servoA", "servoB". escA, servoA, escB, servoB are for the Series 1780 coaxial channels. For the mono version of Series 1780, use the A side. Can also be an array of multiple outputs eg. ['escA','servoA'].
from number Steps starting value between 700 and 2300 microseconds. Must be an array if the first parameter is also an array.
to number Steps finishing value between 700 and 2300 microseconds. Must be an array if the first parameter is also an array.
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.
Source:
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.motorElectricalSpeed.displayValue;
        var unit = result.motorElectricalSpeed.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();
    }
}