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.sim;
008
009import com.ctre.phoenixpro.StatusCode;
010import com.ctre.phoenixpro.hardware.core.CorePigeon2;
011import com.ctre.phoenixpro.hardware.Pigeon2;
012import com.ctre.phoenixpro.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         *
025         * @param device
026         *        Device to which this simulation state is attached
027         */
028        public Pigeon2SimState(CorePigeon2 device) {
029                _id = device.getDeviceID();
030        }
031
032        /**
033         * Sets the simulated supply voltage of the Pigeon2.
034         * <p>
035         * The minimum allowed supply voltage is 4 V - values below this
036         * will be promoted to 4 V.
037         *
038         * @param volts
039         *        The supply voltage in Volts
040         * @return Status code
041         */
042        public StatusCode setSupplyVoltage(double volts) {
043                return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "SupplyVoltage", volts));
044        }
045        /**
046         * Sets the simulated raw yaw of the Pigeon2.
047         * <p>
048         * Inputs to this function over time should be continuous, as user calls of {@link Pigeon2#setYaw} will be accounted for in the callee.
049         * <p>
050         * The Pigeon2 integrates this to calculate the true reported yaw.
051         * <p>
052         * When using the WPI Sim GUI, you will notice a readonly {@code yaw} and settable {@code rawYawInput}.
053         * The readonly signal is the emulated yaw which will match self-test in Tuner and the hardware API.
054         * Changes to {@code rawYawInput} will be integrated into the emulated yaw.
055         * This way a simulator can modify the yaw without overriding hardware API calls for home-ing the sensor.
056         *
057         * @param deg
058         *        The yaw in degrees
059         * @return Status code
060         */
061        public StatusCode setRawYaw(double deg) {
062                return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "RawYaw", deg));
063        }
064        /**
065         * Sets the simulated pitch of the Pigeon2.
066         *
067         * @param deg
068         *        The pitch in degrees
069         * @return Status code
070         */
071        public StatusCode setPitch(double deg) {
072                return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "Pitch", deg));
073        }
074        /**
075         * Sets the simulated roll of the Pigeon2.
076         *
077         * @param deg
078         *        The roll in degrees
079         * @return Status code
080         */
081        public StatusCode setRoll(double deg) {
082                return StatusCode.valueOf(PlatformJNI.JNI_SimSetPhysicsInput(kDevType.value, _id, "Roll", deg));
083        }
084}