Skip to content

Commit

Permalink
Dev/dc motor transmission (#27)
Browse files Browse the repository at this point in the history
* Add translated transmission class

* Add docs and unit tests

* Add function for calculating speed

* fixed
  • Loading branch information
andycate authored and BBScholar committed Jan 31, 2019
1 parent 317a576 commit 0219ea6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
}

group = 'org.team5499'
version = '2.2.0'
version = '2.2.1'

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ package org.team5499.monkeyLib.math.physics
* and efficiency losses). The motor is assumed to be symmetric forward/reverse.
*
* @property speedPerVolt kV, or rad/s per V (no load)
* @property torquePerVolt N•m per V (stall)
* @property torquePerVolt N•m per Amp (stall)
* @property frictionVoltage the voltage needed to overcome static
* @property stallAmperage the stall amperage at 12 volts
*/
class DCMotorTransmission(
val speedPerVolt: Double,
val torquePerVolt: Double,
val frictionVoltage: Double
val frictionVoltage: Double,
val stallAmperage: Double
) {
// TODO add electrical constants? (e.g. current)

val torquePerAmp: Double
val internalResistance: Double

init {
torquePerAmp = torquePerVolt * 12.0 / stallAmperage
internalResistance = 12.0 / stallAmperage
}
/**
* Returns the idle speed of the motor at this voltage
*
Expand Down Expand Up @@ -87,4 +96,16 @@ class DCMotorTransmission(
}
return torque / torquePerVolt + outputSpeed / speedPerVolt + modifiedFrictionVoltage
}

/**
* Get the theoretical speed for voltage and amperage.
*
* @param voltage
* @param amperage
* @return speed rad/s
*/
fun getSpeedForVoltageAndAmperage(voltage: Double, amperage: Double): Double {
var modifiedVoltage = voltage - frictionVoltage
return (modifiedVoltage - amperage * internalResistance) * speedPerVolt
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.Assert.assertEquals
import org.team5499.monkeyLib.math.physics.DCMotorTransmission

class DCMotorTransmissionTest {
val motor = DCMotorTransmission(1000.0, 0.5, 1.0)
val motor = DCMotorTransmission(1000.0, 0.5, 1.0, 120.0)
val stallTorque = 5.5 // N•m
val freeSpeed = 11000.0 // rad/s
val epsilon = 0.1
Expand All @@ -31,4 +31,11 @@ class DCMotorTransmissionTest {
assertEquals(0.5, motor.torquePerVolt, 0.0)
assertEquals(1.0, motor.frictionVoltage, 0.0)
}

@Test
fun speedForVoltageAndAmperageTest() {
val predictedSpeed = motor.getSpeedForVoltageAndAmperage(6.0, 24.0)
println(predictedSpeed)
assertEquals(2600.0, predictedSpeed, epsilon)
}
}

0 comments on commit 0219ea6

Please sign in to comment.