Methods
(static) read(callback, averageQtyopt)
Gets new sensor readings. Automatically averages a few readings for reducing noise. Please run the script in the second example to know the structure of the returned parameter.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback |
readSensorsReady | The function to execute when readings are ready. | ||
averageQty |
integer |
<optional> |
5 | The number of samples to average before returning the result. |
Examples
//Read 10 samples averaged, and print thrust on screen
rcb.sensors.read(callback,10);
function callback(result){
var thrust = result.thrust.displayValue;
var unit = result.thrust.displayUnit;
rcb.console.print("Thrust: " + thrust.toPrecision(3) + " " + unit);
rcb.endScript();
}
//This sample script prints the content of the structure
//returned by the rcb.sensors.read callback
rcb.sensors.read(callback);
function callback(result){
//print structure content
result.print();
rcb.endScript();
}
(static) readOhm(callbackopt)
Reads the ohmmeter. If verbose mode is active, the reading will be displayed on the console.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback |
readOhmReady |
<optional> |
The function to execute when the reading is ready. |
Example
//Gets the ohmmeter reading
rcb.sensors.readOhm(callback);
function callback(reading){
rcb.console.print("Ohm reading: " + reading.toPrecision(4));
rcb.endScript();
}
(static) setMotorPoles(numberOfPoles)
Changes the number of motor poles. The correct number of poles is required to obtain a correct rpm reading.
Parameters:
| Name | Type | Description |
|---|---|---|
numberOfPoles |
integer | The motor number of poles. Must be an multiple of 2. |
Example
rcb.sensors.setMotorPoles(6);
(static) setSafetyLimit(sensorId, min, max)
Changes the safety limit for a sensor. Units are internal working units (A, V, RPM, g, and N·m) regardless of the user display units. It is not possible to set limits beyond hardware limits.
Parameters:
| Name | Type | Description |
|---|---|---|
sensorId |
string | "current", "voltage", "rpm", "thrust", or "torque". |
min |
number | Minimum sensor value before cutoff activates. |
max |
number | Maximum sensor value before cutoff activates. |
Example
rcb.sensors.setSafetyLimit("current",10,20);
//rcb.endScript -> the safety cutoff should stop the script
(static) tareLoadCells(callbackopt)
Performs a tare function on the load cells.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback |
tareComplete |
<optional> |
The function to execute when the tare is complete. |
Example
//Simple script that only tares the load cells and finishes when tare is complete.
rcb.sensors.tareLoadCells(rcb.endScript);