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.*; 012 013import edu.wpi.first.units.*; 014 015import edu.wpi.first.units.measure.*; 016import static edu.wpi.first.units.Units.*; 017 018/** 019 * Configs for Pigeon 2's Mount Pose configuration. 020 * <p> 021 * These configs allow the Pigeon2 to be mounted in whatever 022 * orientation that's desired and ensure the reported Yaw/Pitch/Roll 023 * is from the robot's reference. 024 */ 025public class MountPoseConfigs implements ParentConfiguration 026{ 027 /** 028 * The mounting calibration yaw-component. 029 * 030 * <ul> 031 * <li> <b>Minimum Value:</b> -360 032 * <li> <b>Maximum Value:</b> 360 033 * <li> <b>Default Value:</b> 0 034 * <li> <b>Units:</b> deg 035 * </ul> 036 */ 037 public double MountPoseYaw = 0; 038 /** 039 * The mounting calibration pitch-component. 040 * 041 * <ul> 042 * <li> <b>Minimum Value:</b> -360 043 * <li> <b>Maximum Value:</b> 360 044 * <li> <b>Default Value:</b> 0 045 * <li> <b>Units:</b> deg 046 * </ul> 047 */ 048 public double MountPosePitch = 0; 049 /** 050 * The mounting calibration roll-component. 051 * 052 * <ul> 053 * <li> <b>Minimum Value:</b> -360 054 * <li> <b>Maximum Value:</b> 360 055 * <li> <b>Default Value:</b> 0 056 * <li> <b>Units:</b> deg 057 * </ul> 058 */ 059 public double MountPoseRoll = 0; 060 061 /** 062 * Modifies this configuration's MountPoseYaw parameter and returns itself for 063 * method-chaining and easier to use config API. 064 * <p> 065 * The mounting calibration yaw-component. 066 * 067 * <ul> 068 * <li> <b>Minimum Value:</b> -360 069 * <li> <b>Maximum Value:</b> 360 070 * <li> <b>Default Value:</b> 0 071 * <li> <b>Units:</b> deg 072 * </ul> 073 * 074 * @param newMountPoseYaw Parameter to modify 075 * @return Itself 076 */ 077 public MountPoseConfigs withMountPoseYaw(double newMountPoseYaw) 078 { 079 MountPoseYaw = newMountPoseYaw; 080 return this; 081 } 082 083 /** 084 * Modifies this configuration's MountPoseYaw parameter and returns itself for 085 * method-chaining and easier to use config API. 086 * <p> 087 * The mounting calibration yaw-component. 088 * 089 * <ul> 090 * <li> <b>Minimum Value:</b> -360 091 * <li> <b>Maximum Value:</b> 360 092 * <li> <b>Default Value:</b> 0 093 * <li> <b>Units:</b> deg 094 * </ul> 095 * 096 * @param newMountPoseYaw Parameter to modify 097 * @return Itself 098 */ 099 public MountPoseConfigs withMountPoseYaw(Angle newMountPoseYaw) 100 { 101 MountPoseYaw = newMountPoseYaw.in(Degrees); 102 return this; 103 } 104 105 /** 106 * Helper method to get this configuration's MountPoseYaw parameter converted 107 * to a unit type. If not using the Java units library, {@link #MountPoseYaw} 108 * can be accessed directly instead. 109 * <p> 110 * The mounting calibration yaw-component. 111 * 112 * <ul> 113 * <li> <b>Minimum Value:</b> -360 114 * <li> <b>Maximum Value:</b> 360 115 * <li> <b>Default Value:</b> 0 116 * <li> <b>Units:</b> deg 117 * </ul> 118 * 119 * @return MountPoseYaw 120 */ 121 public Angle getMountPoseYawMeasure() 122 { 123 return Degrees.of(MountPoseYaw); 124 } 125 126 /** 127 * Modifies this configuration's MountPosePitch parameter and returns itself for 128 * method-chaining and easier to use config API. 129 * <p> 130 * The mounting calibration pitch-component. 131 * 132 * <ul> 133 * <li> <b>Minimum Value:</b> -360 134 * <li> <b>Maximum Value:</b> 360 135 * <li> <b>Default Value:</b> 0 136 * <li> <b>Units:</b> deg 137 * </ul> 138 * 139 * @param newMountPosePitch Parameter to modify 140 * @return Itself 141 */ 142 public MountPoseConfigs withMountPosePitch(double newMountPosePitch) 143 { 144 MountPosePitch = newMountPosePitch; 145 return this; 146 } 147 148 /** 149 * Modifies this configuration's MountPosePitch parameter and returns itself for 150 * method-chaining and easier to use config API. 151 * <p> 152 * The mounting calibration pitch-component. 153 * 154 * <ul> 155 * <li> <b>Minimum Value:</b> -360 156 * <li> <b>Maximum Value:</b> 360 157 * <li> <b>Default Value:</b> 0 158 * <li> <b>Units:</b> deg 159 * </ul> 160 * 161 * @param newMountPosePitch Parameter to modify 162 * @return Itself 163 */ 164 public MountPoseConfigs withMountPosePitch(Angle newMountPosePitch) 165 { 166 MountPosePitch = newMountPosePitch.in(Degrees); 167 return this; 168 } 169 170 /** 171 * Helper method to get this configuration's MountPosePitch parameter converted 172 * to a unit type. If not using the Java units library, {@link #MountPosePitch} 173 * can be accessed directly instead. 174 * <p> 175 * The mounting calibration pitch-component. 176 * 177 * <ul> 178 * <li> <b>Minimum Value:</b> -360 179 * <li> <b>Maximum Value:</b> 360 180 * <li> <b>Default Value:</b> 0 181 * <li> <b>Units:</b> deg 182 * </ul> 183 * 184 * @return MountPosePitch 185 */ 186 public Angle getMountPosePitchMeasure() 187 { 188 return Degrees.of(MountPosePitch); 189 } 190 191 /** 192 * Modifies this configuration's MountPoseRoll parameter and returns itself for 193 * method-chaining and easier to use config API. 194 * <p> 195 * The mounting calibration roll-component. 196 * 197 * <ul> 198 * <li> <b>Minimum Value:</b> -360 199 * <li> <b>Maximum Value:</b> 360 200 * <li> <b>Default Value:</b> 0 201 * <li> <b>Units:</b> deg 202 * </ul> 203 * 204 * @param newMountPoseRoll Parameter to modify 205 * @return Itself 206 */ 207 public MountPoseConfigs withMountPoseRoll(double newMountPoseRoll) 208 { 209 MountPoseRoll = newMountPoseRoll; 210 return this; 211 } 212 213 /** 214 * Modifies this configuration's MountPoseRoll parameter and returns itself for 215 * method-chaining and easier to use config API. 216 * <p> 217 * The mounting calibration roll-component. 218 * 219 * <ul> 220 * <li> <b>Minimum Value:</b> -360 221 * <li> <b>Maximum Value:</b> 360 222 * <li> <b>Default Value:</b> 0 223 * <li> <b>Units:</b> deg 224 * </ul> 225 * 226 * @param newMountPoseRoll Parameter to modify 227 * @return Itself 228 */ 229 public MountPoseConfigs withMountPoseRoll(Angle newMountPoseRoll) 230 { 231 MountPoseRoll = newMountPoseRoll.in(Degrees); 232 return this; 233 } 234 235 /** 236 * Helper method to get this configuration's MountPoseRoll parameter converted 237 * to a unit type. If not using the Java units library, {@link #MountPoseRoll} 238 * can be accessed directly instead. 239 * <p> 240 * The mounting calibration roll-component. 241 * 242 * <ul> 243 * <li> <b>Minimum Value:</b> -360 244 * <li> <b>Maximum Value:</b> 360 245 * <li> <b>Default Value:</b> 0 246 * <li> <b>Units:</b> deg 247 * </ul> 248 * 249 * @return MountPoseRoll 250 */ 251 public Angle getMountPoseRollMeasure() 252 { 253 return Degrees.of(MountPoseRoll); 254 } 255 256 257 258 @Override 259 public String toString() 260 { 261 String ss = "Config Group: MountPose\n"; 262 ss += " MountPoseYaw: " + MountPoseYaw + " deg" + "\n"; 263 ss += " MountPosePitch: " + MountPosePitch + " deg" + "\n"; 264 ss += " MountPoseRoll: " + MountPoseRoll + " deg" + "\n"; 265 return ss; 266 } 267 268 /** 269 * 270 */ 271 public StatusCode deserialize(String to_deserialize) 272 { 273 MountPoseYaw = ConfigJNI.Deserializedouble(SpnValue.Pigeon2MountPoseYaw.value, to_deserialize); 274 MountPosePitch = ConfigJNI.Deserializedouble(SpnValue.Pigeon2MountPosePitch.value, to_deserialize); 275 MountPoseRoll = ConfigJNI.Deserializedouble(SpnValue.Pigeon2MountPoseRoll.value, to_deserialize); 276 return StatusCode.OK; 277 } 278 279 /** 280 * 281 */ 282 public String serialize() 283 { 284 String ss = ""; 285 ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2MountPoseYaw.value, MountPoseYaw); 286 ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2MountPosePitch.value, MountPosePitch); 287 ss += ConfigJNI.Serializedouble(SpnValue.Pigeon2MountPoseRoll.value, MountPoseRoll); 288 return ss; 289 } 290} 291