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 com.ctre.phoenix6.StatusCode;
010import com.ctre.phoenix6.controls.jni.ControlJNI;
011
012import java.util.HashMap;
013import java.util.Map;
014
015/**
016 * Request neutral output of actuator. The applied brake type is determined by
017 * the NeutralMode configuration.
018 */
019public class NeutralOut extends ControlRequest implements Cloneable
020{
021    
022
023    /**
024     * The period at which this control will update at.
025     * This is designated in Hertz, with a minimum of 20 Hz
026     * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
027     * <p>
028     * If this field is set to 0 Hz, the control request will
029     * be sent immediately as a one-shot frame. This may be useful
030     * for advanced applications that require outputs to be
031     * synchronized with data acquisition. In this case, we
032     * recommend not exceeding 50 ms between control calls.
033     */
034    public double UpdateFreqHz = 20; // Default to 20Hz
035
036    /**
037     * Request neutral output of actuator. The applied brake type is determined by
038     * the NeutralMode configuration.
039     * 
040     */
041    public NeutralOut()
042    {
043        super("NeutralOut");
044    }
045
046    @Override
047    public String toString()
048    {
049        String ss = "class: NeutralOut\n";
050        
051        return ss;
052    }
053
054    @Override
055    public StatusCode sendRequest(String network, int deviceHash, boolean cancelOtherRequests)
056    {
057        return StatusCode.valueOf(ControlJNI.JNI_RequestControlNeutralOut(
058                network, deviceHash, UpdateFreqHz, cancelOtherRequests));
059    }
060
061    /**
062     * Gets information about this control request.
063     *
064     * @return Map of control parameter names and corresponding applied values
065     */
066    @Override
067    public Map<String, String> getControlInfo()
068    {
069        var controlInfo = new HashMap<String, String>();
070        controlInfo.put("Name", getName());
071
072        return controlInfo;
073    }
074    
075    /**
076     * Sets the period at which this control will update at.
077     * This is designated in Hertz, with a minimum of 20 Hz
078     * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
079     * <p>
080     * If this field is set to 0 Hz, the control request will
081     * be sent immediately as a one-shot frame. This may be useful
082     * for advanced applications that require outputs to be
083     * synchronized with data acquisition. In this case, we
084     * recommend not exceeding 50 ms between control calls.
085     *
086     * @param newUpdateFreqHz Parameter to modify
087     * @return Itself
088     */
089    public NeutralOut withUpdateFreqHz(double newUpdateFreqHz)
090    {
091        UpdateFreqHz = newUpdateFreqHz;
092        return this;
093    }
094
095    @Override
096    public NeutralOut clone()
097    {
098        try {
099            return (NeutralOut)super.clone();
100        } catch (CloneNotSupportedException ex) {
101            /* this should never happen */
102            throw new RuntimeException(ex);
103        }
104    }
105}
106