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.phoenixpro.controls; 008 009import com.ctre.phoenixpro.StatusCode; 010import com.ctre.phoenixpro.controls.jni.ControlJNI; 011import com.ctre.phoenixpro.controls.jni.ControlConfigJNI; 012 013/** 014 * Applies full neutral-brake by shorting motor leads together. 015 */ 016public class StaticBrake extends ControlRequest 017{ 018 private boolean applyConfigsOnRequest; 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 = 100; // Default to 100Hz 034 035 /** 036 * The timeout when sending configs associated with this control 037 */ 038 public double configTimeout = 0.1; 039 040 /** 041 * Applies full neutral-brake by shorting motor leads together. 042 * 043 */ 044 public StaticBrake() 045 { 046 super("StaticBrake"); 047 048 } 049 050 @Override 051 public String toString() 052 { 053 String ss = "class: StaticBrake\n"; 054 055 return ss; 056 } 057 058 @Override 059 public StatusCode sendRequest(String network, int deviceHash, boolean cancelOtherRequests) 060 { 061 062 String ss = ""; 063 064 ControlConfigJNI.JNI_RequestConfigApply(network, deviceHash, configTimeout, ss, applyConfigsOnRequest); 065 applyConfigsOnRequest = false; 066 return StatusCode.valueOf(ControlJNI.JNI_RequestControlStaticBrake( 067 network, deviceHash, UpdateFreqHz, cancelOtherRequests)); 068 } 069 070 /** 071 * Sets the period at which this control will update at. 072 * This is designated in Hertz, with a minimum of 20 Hz 073 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms). 074 * <p> 075 * If this field is set to 0 Hz, the control request will 076 * be sent immediately as a one-shot frame. This may be useful 077 * for advanced applications that require outputs to be 078 * synchronized with data acquisition. In this case, we 079 * recommend not exceeding 50 ms between control calls. 080 * 081 * @param newUpdateFreqHz Parameter to modify 082 * @return Itself 083 */ 084 public StaticBrake withUpdateFreqHz(double newUpdateFreqHz) 085 { 086 UpdateFreqHz = newUpdateFreqHz; 087 return this; 088 } 089 /** 090 * Forces configs to be applied the next time this is used in a setControl. 091 * <p> 092 * This is not necessary in the majority of cases, because Phoenix will make sure configs are 093 * properly set when they are not already set 094 */ 095 public void forceApplyConfigs() { applyConfigsOnRequest = true; } 096} 097