001package com.ctre.phoenix.motorcontrol;
002
003import com.ctre.phoenix.ErrorCode;
004import com.ctre.phoenix.motorcontrol.can.BaseMotorController;
005import com.ctre.phoenix.platform.DeviceType;
006import com.ctre.phoenix.platform.PlatformJNI;
007
008/**
009 * Collection of simulation commands available to a VictorSPX motor controller.
010 *
011 * Use the getSimCollection() routine inside your motor controller to create the respective sim collection.
012 */
013public class VictorSPXSimCollection {
014
015    private int _id;
016
017    /**
018     * Constructor for VictorSPXSimCollection
019     * @param motorController Motor Controller to connect Collection to
020     */
021    public VictorSPXSimCollection(BaseMotorController motorController) {
022        _id = motorController.getDeviceID();
023    }
024
025    /**
026     * Gets the last error generated by this object. Not all functions return an
027     * error code but can potentially report errors. This function can be used
028     * to retrieve those error codes.
029     *
030     * @return Last Error Code generated by a function.
031     */
032    public ErrorCode getLastError() {
033        int retval = PlatformJNI.JNI_SimGetLastError(DeviceType.VictorSPX.value, _id);
034        return ErrorCode.valueOf(retval);
035    }
036    
037    /**
038     * Gets the simulated output voltage across M+ and M- for the motor.
039     * 
040     * @return applied voltage to the motor in volts
041     */
042    public double getMotorOutputLeadVoltage() {
043        return PlatformJNI.JNI_SimGetPhysicsValue(DeviceType.VictorSPX.value, _id, "MotorOutputLeadVoltage");
044    }
045
046    /**
047     * Sets the simulated bus voltage of the VictorSPX.
048     * <p>
049     * The minimum allowed bus voltage is 4 V - values
050     * below this will be promoted to 4 V.
051     * 
052     * @param vbat the bus voltage in volts
053     *
054     * @return  error code
055     */
056    public ErrorCode setBusVoltage(double vbat) {
057        int retval = PlatformJNI.JNI_SimSetPhysicsInput(DeviceType.VictorSPX.value, _id, "BusVoltage", vbat);
058        return ErrorCode.valueOf(retval);
059    }
060}