rotate

xod-dev/servo/rotate

Rotates a servo shaft to the given angular position.
rotate
@/rotate
Rotates a servo shaft to the given angular position.
VALnumber
The target shaft rotation position in the [0; 1] range. The real angle/pulse values corresponding to the 0 and 1 boundaries are defined by the servo device node.
DEV@/servo-device
The servo device
DOpulse
Set the new target rotation value for the given device.
rotate
VAL
DEV
DO
ACK
DEV'
DEV'@/servo-device
The servo device
ACKpulse
Pulses to acknowledge the new target. It will take time for the servo to complete the order.
To use the node in your project you should have the xod-dev/servo library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_DO

node {
    void evaluate(Context ctx) {
        auto xservo = getValue<input_DEV>(ctx);

        if (isSettingUp()) {
            // Short-circuit DEV and DEV'
            emitValue<output_DEVU0027>(ctx, xservo);
        }

        if (!isInputDirty<input_DO>(ctx))
            return;

        auto angle = getValue<input_VAL>(ctx);
        xservo->write01(angle);
        emitValue<output_ACK>(ctx, 1);
    }
}