-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f82e1c9
commit 1dff657
Showing
3 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSimTorque.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package edu.wpi.first.wpilibj.simulation; | ||
|
||
import edu.wpi.first.math.numbers.N1; | ||
import edu.wpi.first.math.system.LinearSystem; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.math.system.plant.LinearSystemId; | ||
|
||
/** Represents a simulated flywheel mechanism. */ | ||
public class FlywheelSimTorque extends FlywheelSim { | ||
|
||
/** | ||
* Creates a simulated flywheel mechanism. | ||
* | ||
* @param plant The linear system that represents the flywheel. Use either {@link | ||
* LinearSystemId#createFlywheelSystem(DCMotor, double, double)} if using physical constants | ||
* or {@link LinearSystemId#identifyVelocitySystem(double, double)} if using system | ||
* characterization. | ||
* @param gearbox The type of and number of motors in the flywheel gearbox. | ||
* @param measurementStdDevs The standard deviations of the measurements. Can be omitted if no | ||
* noise is desired. If present must have 1 element for velocity. | ||
*/ | ||
public FlywheelSimTorque( | ||
LinearSystem<N1, N1, N1> plant, DCMotor gearbox, double... measurementStdDevs) { | ||
super(plant, gearbox, measurementStdDevs); | ||
} | ||
|
||
/** | ||
* Sets the input torque for the flywheel. | ||
* | ||
* @param volts The input torque. | ||
*/ | ||
public void setInputTorque(double torqueNM) { | ||
setInput(torqueNM); | ||
} | ||
|
||
@Override | ||
public double getVoltage() { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getVoltage'"); | ||
} | ||
|
||
@Override | ||
public double getTorqueNewtonMeters() { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getTorqueNewtonMeters'"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSimVoltage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package edu.wpi.first.wpilibj.simulation; | ||
|
||
import edu.wpi.first.math.numbers.N1; | ||
import edu.wpi.first.math.system.LinearSystem; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.math.system.plant.LinearSystemId; | ||
import edu.wpi.first.wpilibj.RobotController; | ||
|
||
/** Represents a simulated flywheel mechanism. */ | ||
public class FlywheelSimVoltage extends FlywheelSim { | ||
|
||
/** | ||
* Creates a simulated flywheel mechanism. | ||
* | ||
* @param plant The linear system that represents the flywheel. Use | ||
* either {@link | ||
* LinearSystemId#createFlywheelSystem(DCMotor, double, double)} | ||
* if using physical constants | ||
* or | ||
* {@link LinearSystemId#identifyVelocitySystem(double, double)} | ||
* if using system | ||
* characterization. | ||
* @param gearbox The type of and number of motors in the flywheel | ||
* gearbox. | ||
* @param measurementStdDevs The standard deviations of the measurements. Can be | ||
* omitted if no | ||
* noise is desired. If present must have 1 element | ||
* for velocity. | ||
*/ | ||
public FlywheelSimVoltage( | ||
LinearSystem<N1, N1, N1> plant, DCMotor gearbox, double... measurementStdDevs) { | ||
super(plant, gearbox, measurementStdDevs); | ||
|
||
} | ||
|
||
/** | ||
* Sets the input voltage for the flywheel. | ||
* | ||
* @param volts The input voltage. | ||
*/ | ||
public void setInputVoltage(double volts) { | ||
setInput(volts); | ||
clampInput(RobotController.getBatteryVoltage()); | ||
} | ||
|
||
/** | ||
* Gets the input voltage for the flywheel. | ||
* | ||
* @return The flywheel input voltage. | ||
*/ | ||
@Override | ||
public double getVoltage() { | ||
return getInput(0); | ||
} | ||
|
||
/** | ||
* Gets the torque on the flywheel. | ||
* | ||
* @return The flywheel's torque in Newton-Meters. | ||
*/ | ||
@Override | ||
public double getTorqueNewtonMeters() { | ||
return getAngularAccelerationRadPerSecSq() * m_jKgMetersSquared; | ||
} | ||
} |