001/* Copyright (C) Cross The Road Electronics 2024 */
002package com.ctre.phoenix.sensors;
003
004import com.ctre.phoenix.ErrorCode;
005import com.ctre.phoenix.platform.DeviceType;
006import com.ctre.phoenix.platform.PlatformJNI;
007
008/**
009 * Collection of simulation commands available to a CANCoder.
010 *
011 * Use the getSimCollection() routine inside your CANCoder to create the respective sim collection.
012 *
013 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
014 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
015 * Phoenix 6 API. A migration guide is available at
016 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
017 * <p>
018 * If the Phoenix 5 API must be used for this device, the device must have 22.X
019 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
020 * the firmware year dropdown.
021 */
022@Deprecated(since = "2024", forRemoval = true)
023public class CANCoderSimCollection {
024
025    private int _id;
026
027    /**
028     * Constructor for CANCoderSimCollection
029     * @param canCoder CANCoder to connect Collection to
030     */
031    public CANCoderSimCollection(CANCoder canCoder) {
032        _id = canCoder.getDeviceID();
033    }
034
035    /**
036     * Sets the simulated bus voltage of the CANCoder.
037     * <p>
038     * The minimum allowed bus voltage is 4 V - values
039     * below this will be promoted to 4 V.
040     * 
041     * @param vbat the bus voltage in volts
042     *
043     * @return  error code
044     */
045    public ErrorCode setBusVoltage(double vbat) {
046        int retval = PlatformJNI.JNI_SimSetPhysicsInput(DeviceType.CANCoder.value, _id, "BusVoltage", vbat);
047        return ErrorCode.valueOf(retval);
048    }
049
050    /**
051     * Sets the simulated raw position of the CANCoder.
052     * <p>
053     * The CANCoder integrates this to calculate the true reported position.
054     * <p>
055     * When using the WPI Sim GUI, you will notice a readonly 'position' and
056     * settable 'rawPositionInput'.  The readonly signal is the emulated position
057     * which will match self-test in Tuner and the hardware API.  Changes to
058     * 'rawPositionInput' will be integrated into the emulated position.  This way
059     * a simulator can modify the position without overriding your
060     * hardware API calls for home-ing your sensor.
061     * <p>
062     * Inputs to this function over time should be continuous, as user calls
063     * of setPosition() will be accounted for in the calculation.
064     * 
065     * @param newPos the new raw position in native units
066     *
067     * @return  error code
068     */
069    public ErrorCode setRawPosition(int newPos) {
070        int retval = PlatformJNI.JNI_SimSetPhysicsInput(DeviceType.CANCoder.value, _id, "IntegSensRawPos", newPos);
071        return ErrorCode.valueOf(retval);
072    }
073
074    /**
075     * Adds to the simulated position of the CANCoder.
076     * 
077     * @param dPos the change in position in native units
078     *
079     * @return  error code
080     */
081    public ErrorCode addPosition(int dPos) {
082        int retval = PlatformJNI.JNI_SimSetPhysicsInput(DeviceType.CANCoder.value, _id, "IntegSensAddPos", dPos);
083        return ErrorCode.valueOf(retval);
084    }
085
086    /**
087     * Sets the simulated velocity of the CANCoder.
088     * 
089     * @param newVel the new velocity in native units per 100ms
090     *
091     * @return  error code
092     */
093    public ErrorCode setVelocity(int newVel) {
094        int retval = PlatformJNI.JNI_SimSetPhysicsInput(DeviceType.CANCoder.value, _id, "IntegSensVel", newVel);
095        return ErrorCode.valueOf(retval);
096    }
097}