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.configs; 008 009import com.ctre.phoenix6.StatusCode; 010import com.ctre.phoenix6.configs.jni.ConfigJNI; 011import com.ctre.phoenix6.spns.*; 012import com.ctre.phoenix6.signals.*; 013 014import edu.wpi.first.units.*; 015 016import edu.wpi.first.units.measure.*; 017import static edu.wpi.first.units.Units.*; 018 019/** 020 * Configs that affect the ToF sensor 021 * <p> 022 * Includes Update mode and frequency 023 */ 024public class ToFParamsConfigs implements ParentConfiguration 025{ 026 /** 027 * Update mode of the CANrange. The CANrange supports short-range and 028 * long-range detection at various update frequencies. 029 * 030 */ 031 public UpdateModeValue UpdateMode = UpdateModeValue.ShortRange100Hz; 032 /** 033 * Rate at which the CANrange will take measurements. A lower 034 * frequency may provide more stable readings but will reduce the data 035 * rate of the sensor. 036 * 037 * <ul> 038 * <li> <b>Minimum Value:</b> 5 039 * <li> <b>Maximum Value:</b> 50 040 * <li> <b>Default Value:</b> 50 041 * <li> <b>Units:</b> Hz 042 * </ul> 043 */ 044 public double UpdateFrequency = 50; 045 046 /** 047 * Modifies this configuration's UpdateMode parameter and returns itself for 048 * method-chaining and easier to use config API. 049 * <p> 050 * Update mode of the CANrange. The CANrange supports short-range and 051 * long-range detection at various update frequencies. 052 * 053 * 054 * @param newUpdateMode Parameter to modify 055 * @return Itself 056 */ 057 public ToFParamsConfigs withUpdateMode(UpdateModeValue newUpdateMode) 058 { 059 UpdateMode = newUpdateMode; 060 return this; 061 } 062 063 /** 064 * Modifies this configuration's UpdateFrequency parameter and returns itself for 065 * method-chaining and easier to use config API. 066 * <p> 067 * Rate at which the CANrange will take measurements. A lower 068 * frequency may provide more stable readings but will reduce the data 069 * rate of the sensor. 070 * 071 * <ul> 072 * <li> <b>Minimum Value:</b> 5 073 * <li> <b>Maximum Value:</b> 50 074 * <li> <b>Default Value:</b> 50 075 * <li> <b>Units:</b> Hz 076 * </ul> 077 * 078 * @param newUpdateFrequency Parameter to modify 079 * @return Itself 080 */ 081 public ToFParamsConfigs withUpdateFrequency(double newUpdateFrequency) 082 { 083 UpdateFrequency = newUpdateFrequency; 084 return this; 085 } 086 087 /** 088 * Modifies this configuration's UpdateFrequency parameter and returns itself for 089 * method-chaining and easier to use config API. 090 * <p> 091 * Rate at which the CANrange will take measurements. A lower 092 * frequency may provide more stable readings but will reduce the data 093 * rate of the sensor. 094 * 095 * <ul> 096 * <li> <b>Minimum Value:</b> 5 097 * <li> <b>Maximum Value:</b> 50 098 * <li> <b>Default Value:</b> 50 099 * <li> <b>Units:</b> Hz 100 * </ul> 101 * 102 * @param newUpdateFrequency Parameter to modify 103 * @return Itself 104 */ 105 public ToFParamsConfigs withUpdateFrequency(Frequency newUpdateFrequency) 106 { 107 UpdateFrequency = newUpdateFrequency.in(Hertz); 108 return this; 109 } 110 111 /** 112 * Helper method to get this configuration's UpdateFrequency parameter converted 113 * to a unit type. If not using the Java units library, {@link #UpdateFrequency} 114 * can be accessed directly instead. 115 * <p> 116 * Rate at which the CANrange will take measurements. A lower 117 * frequency may provide more stable readings but will reduce the data 118 * rate of the sensor. 119 * 120 * <ul> 121 * <li> <b>Minimum Value:</b> 5 122 * <li> <b>Maximum Value:</b> 50 123 * <li> <b>Default Value:</b> 50 124 * <li> <b>Units:</b> Hz 125 * </ul> 126 * 127 * @return UpdateFrequency 128 */ 129 public Frequency getUpdateFrequencyMeasure() 130 { 131 return Hertz.of(UpdateFrequency); 132 } 133 134 135 136 @Override 137 public String toString() 138 { 139 String ss = "Config Group: ToFParams\n"; 140 ss += " UpdateMode: " + UpdateMode + "\n"; 141 ss += " UpdateFrequency: " + UpdateFrequency + " Hz" + "\n"; 142 return ss; 143 } 144 145 /** 146 * 147 */ 148 public StatusCode deserialize(String to_deserialize) 149 { 150 UpdateMode = UpdateModeValue.valueOf(ConfigJNI.Deserializeint(SpnValue.CANrange_UpdateMode.value, to_deserialize)); 151 UpdateFrequency = ConfigJNI.Deserializedouble(SpnValue.CANrange_UpdateFreq.value, to_deserialize); 152 return StatusCode.OK; 153 } 154 155 /** 156 * 157 */ 158 public String serialize() 159 { 160 String ss = ""; 161 ss += ConfigJNI.Serializeint(SpnValue.CANrange_UpdateMode.value, UpdateMode.value); 162 ss += ConfigJNI.Serializedouble(SpnValue.CANrange_UpdateFreq.value, UpdateFrequency); 163 return ss; 164 } 165} 166