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.sim; 008 009import com.ctre.phoenix6.StatusCode; 010import com.ctre.phoenix6.hardware.core.CorePigeon2; 011import com.ctre.phoenix6.hardware.Pigeon2; 012import com.ctre.phoenix6.jni.PlatformJNI; 013 014/** 015 * Class to control the state of a simulated {@link Pigeon2}. 016 */ 017public class Pigeon2SimState { 018 private final DeviceType kDevType = DeviceType.PRO_Pigeon2Type; 019 020 private final int _id; 021 022 /** 023 * Creates an object to control the state of the given {@link Pigeon2}. 024 * <p> 025 * Note the recommended method of accessing simulation features is to use 026 * {@link Pigeon2#getSimState} 027 * 028 * @param device 029 * Device to which this simulation state is attached 030 */ 031 public Pigeon2SimState(CorePigeon2 device) { 032 _id = device.getDeviceID(); 033 } 034 035 /** 036 * Sets the simulated supply voltage of the Pigeon2. 037 * <p> 038 * The minimum allowed supply voltage is 4 V - values below this 039 * will be promoted to 4 V. 040 * 041 * @param volts 042 * The supply voltage in Volts 043 * @return Status code 044 */ 045 public StatusCode setSupplyVoltage(double volts) { 046 return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "SupplyVoltage", volts)); 047 } 048 /** 049 * Sets the simulated raw yaw of the Pigeon2. 050 * <p> 051 * Inputs to this function over time should be continuous, as user calls of {@link Pigeon2#setYaw} will be accounted for in the callee. 052 * <p> 053 * The Pigeon2 integrates this to calculate the true reported yaw. 054 * <p> 055 * When using the WPI Sim GUI, you will notice a readonly {@code yaw} and settable {@code rawYawInput}. 056 * The readonly signal is the emulated yaw which will match self-test in Tuner and the hardware API. 057 * Changes to {@code rawYawInput} will be integrated into the emulated yaw. 058 * This way a simulator can modify the yaw without overriding hardware API calls for home-ing the sensor. 059 * 060 * @param deg 061 * The yaw in degrees 062 * @return Status code 063 */ 064 public StatusCode setRawYaw(double deg) { 065 return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "RawYaw", deg)); 066 } 067 /** 068 * Adds to the simulated yaw of the Pigeon2. 069 * 070 * @param dDeg 071 * The change in yaw in degrees 072 * @return Status code 073 */ 074 public StatusCode addYaw(double dDeg) { 075 return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "AddYaw", dDeg)); 076 } 077 /** 078 * Sets the simulated pitch of the Pigeon2. 079 * 080 * @param deg 081 * The pitch in degrees 082 * @return Status code 083 */ 084 public StatusCode setPitch(double deg) { 085 return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "Pitch", deg)); 086 } 087 /** 088 * Sets the simulated roll of the Pigeon2. 089 * 090 * @param deg 091 * The roll in degrees 092 * @return Status code 093 */ 094 public StatusCode setRoll(double deg) { 095 return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "Roll", deg)); 096 } 097}