Control Requests#

Control Requests represent the output of a device. A list of control requests can be found in the API docs (Java, C++).

Note

Phoenix Pro utilizes the C++ units library when applicable.

Applying a Control Request#

Control requests can be applied by calling setControl() on the motor object. setControl() returns a StatusCode (Java, C++) enum that represents success state. A successful request will return StatusCode.OK.

// Command m_motor to 100% of duty cycle
m_motor.setControl(new DutyCycleOut(1.0));
// Command m_motor to 100% of duty cycle
m_motor.SetControl(controls::DutyCycleOut{1.0});

Modifying a Control Request#

Control requests are mutable, so they can be saved in a member variable and reused. For example, DutyCycleOut (Java, C++) has an Output member variable that can be manipulated, thus changing the output DutyCycle (proportion of supply voltage).

Note

Java users should reuse control requests to prevent excessive invocation of the Garbage Collector.

var motorRequest = new DutyCycleOut(0.0);

motorRequest.Output = 1.0;
m_motor.setControl(motorRequest);
controls::DutyCycleOut motorRequest{0.0};

motorRequest.Output = 1.0;
m_motor.SetControl(motorRequest);

Method Chaining API#

Control requests also supports modification using method chaining. This can be useful for mutating multiple values of a control request.

// initialize torque current FOC request with 0 amps
var motorRequest = new TorqueCurrentFOC(0);

// mutate request with output of 10 amps and max duty cycle 0.5
m_motor.SetControl(motorRequest.withOutputAmps(10).withMaxDutyCycle(0.5));
// initialize torque current FOC request with 0 amps
controls::TorqueCurrentFOC motorRequest{0_A};

// mutate request with output of 10 amps and max duty cycle 0.5
m_motor.SetControl(motorRequest.WithOutputAmps(10_A).WithMaxDutyCycle(0.5));

Changing Update Frequency#

Control requests are automatically transmitted at a fixed update frequency. This update frequency can be modified by changing the UpdateFreqHz (Java, C++) field of the control request before sending it to the device.

// create a duty cycle request
var motorRequest = new DutyCycleOut(0);
// reduce the update frequency to 50 Hz
motorRequest.UpdateFreqHz = 50;
// create a duty cycle request
controls::DutyCycleOut motorRequest{0};
// reduce the update frequency to 50 Hz
motorRequest.UpdateFreqHz = 50;