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.SharpIR; 009 010/** Simulation class for Sharp IR sensors. */ 011public class SharpIRSim { 012 private final SimDouble m_simRange; 013 014 /** 015 * Constructor. 016 * 017 * @param sharpIR The real sensor to simulate 018 */ 019 public SharpIRSim(SharpIR sharpIR) { 020 this(sharpIR.getChannel()); 021 } 022 023 /** 024 * Constructor. 025 * 026 * @param channel Analog channel for this sensor 027 */ 028 public SharpIRSim(int channel) { 029 SimDeviceSim simDevice = new SimDeviceSim("SharpIR", channel); 030 m_simRange = simDevice.getDouble("Range (m)"); 031 } 032 033 /** 034 * Set the range in meters returned by the distance sensor. 035 * 036 * @param range range in meters of the target returned by the sensor 037 */ 038 public void setRange(double range) { 039 m_simRange.set(range); 040 } 041}