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.ADXL345_I2C; 009import java.util.Objects; 010 011/** Class to control a simulated ADXL345. */ 012public class ADXL345Sim { 013 private SimDouble m_simX; 014 private SimDouble m_simY; 015 private SimDouble m_simZ; 016 017 /** 018 * Constructor. 019 * 020 * @param device The device to simulate 021 */ 022 public ADXL345Sim(ADXL345_I2C device) { 023 SimDeviceSim simDevice = 024 new SimDeviceSim( 025 "Accel:ADXL345_I2C" + "[" + device.getPort() + "," + device.getDeviceAddress() + "]"); 026 initSim(simDevice); 027 } 028 029 private void initSim(SimDeviceSim simDevice) { 030 Objects.requireNonNull(simDevice); 031 032 m_simX = simDevice.getDouble("x"); 033 m_simY = simDevice.getDouble("y"); 034 m_simZ = simDevice.getDouble("z"); 035 036 Objects.requireNonNull(m_simX); 037 Objects.requireNonNull(m_simY); 038 Objects.requireNonNull(m_simZ); 039 } 040 041 /** 042 * Sets the X acceleration. 043 * 044 * @param accel The X acceleration. 045 */ 046 public void setX(double accel) { 047 m_simX.set(accel); 048 } 049 050 /** 051 * Sets the Y acceleration. 052 * 053 * @param accel The Y acceleration. 054 */ 055 public void setY(double accel) { 056 m_simY.set(accel); 057 } 058 059 /** 060 * Sets the Z acceleration. 061 * 062 * @param accel The Z acceleration. 063 */ 064 public void setZ(double accel) { 065 m_simZ.set(accel); 066 } 067}