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.Servo; 009 010/** Class to control a simulated Servo. */ 011public class ServoSim { 012 private final SimDouble m_simPosition; 013 014 /** 015 * Constructor. 016 * 017 * @param servo The device to simulate 018 */ 019 public ServoSim(Servo servo) { 020 this(servo.getChannel()); 021 } 022 023 /** 024 * Constructor. 025 * 026 * @param channel The channel the servo is attached to. 027 */ 028 public ServoSim(int channel) { 029 SimDeviceSim simDevice = new SimDeviceSim("Servo", channel); 030 m_simPosition = simDevice.getDouble("Position"); 031 } 032 033 /** 034 * Gets the position set. 035 * 036 * @return Position 037 */ 038 public double getPosition() { 039 return m_simPosition.get(); 040 } 041 042 /** 043 * Gets the angle set. 044 * 045 * @return Angle 046 */ 047 public double getAngle() { 048 return getPosition() * 180.0; 049 } 050}