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