001/*
002 * Copyright (C) Cross The Road Electronics.  All rights reserved.
003 * License information can be found in CTRE_LICENSE.txt
004 * For support and suggestions contact support@ctr-electronics.com or file
005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
006 */
007package com.ctre.phoenix6.controls;
008
009import java.util.Map;
010
011import com.ctre.phoenix6.StatusCode;
012
013import edu.wpi.first.units.measure.*;
014
015/**
016 * Abstract Control Request class that other control requests extend for use.
017 */
018public abstract class ControlRequest {
019    protected final String name;
020
021    /**
022     * Constructs a new Control Request with the given name.
023     *
024     * @param name Name of the control request
025     */
026    public ControlRequest(String name) {
027        this.name = name;
028    }
029
030    /**
031     * Sets the period at which this control will update at.
032     * This is designated in Hertz, with a minimum of 20 Hz
033     * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
034     * <p>
035     * If this field is set to 0 Hz, the control request will
036     * be sent immediately as a one-shot frame. This may be useful
037     * for advanced applications that require outputs to be
038     * synchronized with data acquisition. In this case, we
039     * recommend not exceeding 50 ms between control calls.
040     *
041     * @param newUpdateFreqHz Parameter to modify
042     * @return Itself
043     */
044    public abstract ControlRequest withUpdateFreqHz(double newUpdateFreqHz);
045    /**
046     * Sets the period at which this control will update at.
047     * This is designated in Hertz, with a minimum of 20 Hz
048     * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
049     * <p>
050     * If this field is set to 0 Hz, the control request will
051     * be sent immediately as a one-shot frame. This may be useful
052     * for advanced applications that require outputs to be
053     * synchronized with data acquisition. In this case, we
054     * recommend not exceeding 50 ms between control calls.
055     *
056     * @param newUpdateFreqHz Parameter to modify
057     * @return Itself
058     */
059    public abstract ControlRequest withUpdateFreqHz(Frequency newUpdateFreqHz);
060
061    /**
062     * Gets the name of this control request.
063     *
064     * @return Name of the control request
065     */
066    public String getName() {
067        return name;
068    }
069
070    public abstract StatusCode sendRequest(String network, int deviceHash);
071
072    /**
073     * Gets information about this control request.
074     *
075     * @return Map of control parameter names and corresponding applied values
076     */
077    public abstract Map<String, String> getControlInfo();
078}