API reference

Java methods for controlling, configuring, and monitoring a Cyclone.

Java 0.33.0 / firmware 2.6.6: zero duty coasts; brake is unsupported. Stator and supply current-limit settings are inactive compatibility fields and do not limit amperes. Supply current is observational; stator current is unavailable. The speed-based duty governor can reduce applied output.

After each DS enable, firmware 1.6.9 requires robot control to return to neutral before motion. Java 0.31.0 provides NeutralStartInterlock to check individual sticks, triggers and motion buttons. Follow the complete controller example; do not prepend an automatic zero to every command.

Motor commands and setup

CallPurpose
new SwyftCyclone(id)Create the controller object; use a unique device number.
setDutyCycle(duty) / set(duty)Signed duty fraction, −1…+1.
setVelocity(rpm)Mechanical rotor RPM.
setPosition(rad)Rotor radians; requires configured gains.
configureMechanism(configs)Set host-side ratio and wrapping behavior.
setMechanismPosition(rotations)Command mechanism turns through that ratio.
setControl(Follower)Follow a leader through the host library.
stopFollowing()Return to direct control.
disable()Drop motion and coast.
estop() / releaseEstop()Latch / release emergency stop; enable conditions still apply.
close()Release the transport and object resources.

Duty, velocity, and position requests

Create one controller object at startup, as shown in the complete first program. In these snippets motor is that existing object. Choose one control mode and repeat its command from enabled periodic code; do not paste all three requests into the same loop.

Java
motor.setDutyCycle(0.10); // 10% output. Negative requests the other direction.
Java
motor.setVelocity(1500); // Rotor RPM; requires usable velocity gains.
Java
// Only after configuring position gains and establishing a known reference.
motor.setPosition(Math.PI / 2); // Quarter rotor turn from that reference.

Convert mechanism turns

A 5:1 ratio means five motor turns for one mechanism turn. Configure it when robot code starts. The target call belongs in periodic code, after homing and position-gain setup.

Java
MechanismConfigs mechanism = new MechanismConfigs();
mechanism.SensorToMechanismRatio = 5.0;
mechanism.ContinuousWrap = false;
motor.configureMechanism(mechanism);
// In enabled periodic code, once the reference and gains are valid:
motor.setMechanismPosition(0.25); // Quarter mechanism turn; 1.25 motor turns.

Follower and stop

Configure both motors’ limits. Here follower is a separate controller object and device 1 is the leader. Choose the alignment that matches the mechanism.

Java
follower.setControl(new Follower(1, MotorAlignmentValue.Opposed));
// Later, before sending direct commands to the follower:
follower.stopFollowing();
Java
motor.disable(); // Normal stop: remove the request and coast.
// On a separate emergency-stop event:
motor.estop();
// Release only after the cause is resolved and it is safe to re-enable.
// motor.releaseEstop();

Settings

CallImportant constraint
getConfigurator().apply(CurrentLimitsConfigs)Inactive compatibility settings; accepted storage range stator 0.001–70 A, supply 0.001–45 A.
setVelocityGain(KP, KI or KD, value)Legacy direct velocity writer. Prefer apply(Slot0Configs) for confirmed kP/kI/kD writes with Java 0.29.0 and firmware 0.167.0.
getConfigurator().apply(ClosedLoopGeneralConfigs)PositionKP, PositionKI and PositionKD configure real position PID on firmware 1.7.4 with Java 0.31.0. Check StatusCode and read back before saving.
setVelocityDerivativeGain(kD) / getVelocityDerivativeGain()Write/read velocity kD; firmware 0.165.0+, library 0.28.0+. Range 0 to 0.001; check StatusCode. Read returns NaN if unavailable.
setNeutralMode(COAST)COAST supported; BRAKE is refused before transmission.
saveConfigurationConfirmed()Save supported device settings while stopped; not every overlay is persistent.

For all supported numeric team settings, names, units, ranges and save behavior, see Team settings from Java. Use getConfigurator().setSetting(name, value) and check its returned StatusCode.

Apply configuration and check the result

Apply while stopped. The values below demonstrate compatibility storage only; they do not provide current protection on 2.6.6.

Java
CurrentLimitsConfigs limits = new CurrentLimitsConfigs()
    .withStatorCurrentLimit(30)
    .withSupplyCurrentLimit(20);
StatusCode result = motor.getConfigurator().apply(limits);
if (!result.isOK()) {
    motor.disable();
    System.err.println(result.describe());
}
Java
StatusCode neutral = motor.setNeutralMode(SwyftCyclone.NeutralMode.COAST);
if (!neutral.isOK()) System.err.println(neutral.describe());
// Set neutral mode again after restart; it is not saved to flash.

Use the supported Java gain writer for velocity. Replace kP and kI with the gains selected for your mechanism, within the accepted ranges.

Java
Slot0Configs velocityGains = new Slot0Configs();
velocityGains.kP = kP;
velocityGains.kI = kI;
StatusCode gainResult = motor.getConfigurator().apply(velocityGains);
if (!gainResult.isOK()) System.err.println(gainResult.describe());
StatusCode derivative = motor.setVelocityDerivativeGain(0.00001); // Example only.
if (!derivative.isOK()) System.err.println(derivative.describe());
Java
ClosedLoopGeneralConfigs gains = new ClosedLoopGeneralConfigs();
gains.PositionKP = positionKp; // Your selected, positive position gain.
StatusCode result = motor.getConfigurator().apply(gains);
if (!result.isOK()) System.err.println(result.describe());
Java
// Save deliberately after checking accepted settings on a stopped motor.
// Do not put this in periodic code or save the same values on every boot.
motor.saveConfiguration();

Signals and lights

CallPurpose
getLatest()Decoded record with frame timestamps.
getVelocityRpm() / getPositionRad()Mechanical motion.
getSupplyVoltage() / getSupplyCurrent()Electrical measurements.
getDeviceTemp()Board temperature.
isAlive(maxAgeSec)Connection freshness.
hasLikelyRebooted()Detect a likely reset before using relative position.
hasNewRefusal() / describeRefusal()Inspect command refusal.
setLEDs(r,g,b) / setLED(index,r,g,b)Five user LEDs; RGB components 0–255.
clearLEDs() / identify()Release the user override / identify the physical device.

Read measurements and faults

Measurements arrive asynchronously. A recent connection does not guarantee every cached signal is fresh. Check the relevant timestamps when a control decision depends on a measurement.

Java
double rpm = motor.getVelocityRpm();
double rotorRadians = motor.getPositionRad();
double volts = motor.getSupplyVoltage();
double supplyAmps = motor.getSupplyCurrent();
double boardCelsius = motor.getDeviceTemp();
boolean connectedRecently = motor.isAlive(0.25);
SwyftCycloneData data = motor.getLatest();
double motionReceivedAtSeconds = data.motionTimestampSec;
Java
if (motor.hasNewRefusal()) {
    System.err.println(motor.describeRefusal());
}
if (motor.hasHardFault()) {
    motor.disable();
    System.err.println(motor.getPowerStageFaultString());
}
if (motor.hasLikelyRebooted()) {
    motor.disable();
    // Invalidate your saved home/reference and re-establish it before position control.
}

Identify and set user lights

The five user LEDs use red, green, and blue values from 0 to 255. The two end status lights remain controlled by the firmware.

Java
motor.identify();           // Flash the physical motor's identify indication.
motor.setLEDs(0, 80, 255);   // Set all five user lights.
motor.setLED(1, 255, 0, 0);  // Change user LED 1 to red.
// Later, release the user-colour override:
motor.clearLEDs();

Call motor.close() when permanently disposing of the object, not after each command. See the first program for object lifetime and Status signals for measurement validity.

Unsupported operations

SurfaceCurrent behavior
setCurrent()Deprecated compatibility method; throws UnsupportedOperationException.
Slots 1 and 2Not selectable on the public gain path.
SoftwareLimitSwitchConfigsRefused by the public configurator; no claimed mechanism protection.
BrakeCurrent / BrakeMaxRpmRefused; the neutral brake is not an adjustable current regulator.
disarmDriverStationGate()Refused. The safety gate is non-disarmable.