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