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