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 org.wpilib.simulation;
006
007import org.wpilib.hardware.hal.SimDouble;
008import org.wpilib.hardware.motor.PWMMotorController;
009
010/** Class to control a simulated PWM motor controller. */
011public class PWMMotorControllerSim {
012  private final SimDouble m_simDutyCycle;
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_simDutyCycle = simDevice.getDouble("DutyCycle");
031  }
032
033  /**
034   * Gets the motor duty cycle.
035   *
036   * @return Duty cycle
037   */
038  public double getDutyCycle() {
039    return m_simDutyCycle.get();
040  }
041}