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