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.phoenix6.StatusCode; 010import com.ctre.phoenix6.controls.jni.ControlJNI; 011import com.ctre.phoenix6.controls.jni.ControlConfigJNI; 012 013/** 014 * Follow the motor output of another Talon while ignoring the master's invert 015 * setting. 016 * <p> 017 * If Talon is in torque control, the torque is copied - which will increase the total torque applied. If 018 * Talon is in percent supply output control, the duty cycle is matched. Motor direction is strictly 019 * determined by the configured invert and not the master. If you want motor direction to match or oppose the 020 * master, use FollowerRequest instead. 021 * 022 * @deprecated Classes in the phoenixpro package will be removed in 2024. 023 * Users should instead use classes from the phoenix6 package. 024 */ 025@Deprecated(forRemoval = true) 026public class StrictFollower extends ControlRequest 027{ 028 private boolean applyConfigsOnRequest; 029 /** 030 * Device ID of the master to follow. 031 */ 032 public int MasterID; 033 034 035 /** 036 * The period at which this control will update at. 037 * This is designated in Hertz, with a minimum of 20 Hz 038 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms). 039 * <p> 040 * If this field is set to 0 Hz, the control request will 041 * be sent immediately as a one-shot frame. This may be useful 042 * for advanced applications that require outputs to be 043 * synchronized with data acquisition. In this case, we 044 * recommend not exceeding 50 ms between control calls. 045 */ 046 public double UpdateFreqHz = 100; // Default to 100Hz 047 048 /** 049 * The timeout when sending configs associated with this control 050 */ 051 public double configTimeout = 0.1; 052 053 /** 054 * Follow the motor output of another Talon while ignoring the master's 055 * invert setting. 056 * <p> 057 * If Talon is in torque control, the torque is copied - which will increase 058 * the total torque applied. If Talon is in percent supply output control, 059 * the duty cycle is matched. Motor direction is strictly determined by the 060 * configured invert and not the master. If you want motor direction to 061 * match or oppose the master, use FollowerRequest instead. 062 * 063 * @param MasterID Device ID of the master to follow. 064 * 065 * @deprecated Classes in the phoenixpro package will be removed in 2024. 066 * Users should instead use classes from the phoenix6 package. 067 */ 068 @Deprecated(forRemoval = true) 069 public StrictFollower(int MasterID) 070 { 071 super("StrictFollower"); 072 this.MasterID = MasterID; 073 } 074 075 @Override 076 public String toString() 077 { 078 String ss = "class: StrictFollower\n"; 079 ss += "MasterID: " + MasterID + "\n"; 080 return ss; 081 } 082 083 @Override 084 public StatusCode sendRequest(String network, int deviceHash, boolean cancelOtherRequests) 085 { 086 var ref = requestReference.getNameValues(); 087 ref.put("MasterID", String.valueOf(this.MasterID)); 088 String ss = ""; 089 090 ControlConfigJNI.JNI_RequestConfigApply(network, deviceHash, configTimeout, ss, applyConfigsOnRequest); 091 applyConfigsOnRequest = false; 092 return StatusCode.valueOf(ControlJNI.JNI_RequestControlStrictFollower( 093 network, deviceHash, UpdateFreqHz, cancelOtherRequests, MasterID)); 094 } 095 096 /** 097 * Modifies this Control Request's MasterID parameter and returns itself for 098 * method-chaining and easier to use request API. 099 * 100 * @param newMasterID Parameter to modify 101 * @return Itself 102 */ 103 public StrictFollower withMasterID(int newMasterID) 104 { 105 MasterID = newMasterID; 106 return this; 107 } 108 /** 109 * Sets the period at which this control will update at. 110 * This is designated in Hertz, with a minimum of 20 Hz 111 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms). 112 * <p> 113 * If this field is set to 0 Hz, the control request will 114 * be sent immediately as a one-shot frame. This may be useful 115 * for advanced applications that require outputs to be 116 * synchronized with data acquisition. In this case, we 117 * recommend not exceeding 50 ms between control calls. 118 * 119 * @param newUpdateFreqHz Parameter to modify 120 * @return Itself 121 */ 122 public StrictFollower withUpdateFreqHz(double newUpdateFreqHz) 123 { 124 UpdateFreqHz = newUpdateFreqHz; 125 return this; 126 } 127 /** 128 * Forces configs to be applied the next time this is used in a setControl. 129 * <p> 130 * This is not necessary in the majority of cases, because Phoenix will make sure configs are 131 * properly set when they are not already set 132 */ 133 public void forceApplyConfigs() { applyConfigsOnRequest = true; } 134} 135