001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj.simulation;
006
007import edu.wpi.first.hal.SimDouble;
008import edu.wpi.first.wpilibj.motorcontrol.PWMMotorController;
009
010/** Class to control a simulated PWM motor controller. */
011public class PWMMotorControllerSim {
012  private final SimDouble m_simSpeed;
013
014  /**
015   * Constructor.
016   *
017   * @param motorctrl The device to simulate
018   */
019  public PWMMotorControllerSim(PWMMotorController motorctrl) {
020    this(motorctrl.getChannel());
021  }
022
023  /**
024   * Constructor.
025   *
026   * @param channel The channel the motor controller is attached to.
027   */
028  public PWMMotorControllerSim(int channel) {
029    SimDeviceSim simDevice = new SimDeviceSim("PWMMotorController", channel);
030    m_simSpeed = simDevice.getDouble("Speed");
031  }
032
033  /**
034   * Gets the motor speed set.
035   *
036   * @return Speed
037   */
038  public double getSpeed() {
039    return m_simSpeed.get();
040  }
041}