Attempt to create motor counter-emf
This commit is contained in:
parent
fb4592007c
commit
e2a1b9601a
|
@ -28,6 +28,11 @@ object TileMotor
|
||||||
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "motor.tcn"))
|
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "motor.tcn"))
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "motor.png")
|
val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "motor.png")
|
||||||
|
|
||||||
|
val fieldStrength = 1
|
||||||
|
val coils = 10
|
||||||
|
val area = 1
|
||||||
|
val motorConstant = fieldStrength * area * coils
|
||||||
}
|
}
|
||||||
|
|
||||||
class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with TSpatialNodeProvider with TRotatable
|
class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with TSpatialNodeProvider with TRotatable
|
||||||
|
@ -51,7 +56,7 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
||||||
nodes.add(electricNode)
|
nodes.add(electricNode)
|
||||||
nodes.add(mechNode)
|
nodes.add(mechNode)
|
||||||
|
|
||||||
electricNode.resistance = 100
|
electricNode.resistance = 10
|
||||||
|
|
||||||
def toggleGearRatio() = (gearRatio + 1) % 3
|
def toggleGearRatio() = (gearRatio + 1) % 3
|
||||||
|
|
||||||
|
@ -61,40 +66,27 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
||||||
updateConnectionMask()
|
updateConnectionMask()
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateConnectionMask()
|
|
||||||
{
|
|
||||||
electricNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
|
|
||||||
electricNode.positiveTerminals.clear()
|
|
||||||
electricNode.negativeTerminals.clear()
|
|
||||||
electricNode.positiveTerminals.addAll(getInputDirections())
|
|
||||||
electricNode.negativeTerminals.addAll(getOutputDirections())
|
|
||||||
electricNode.reconstruct()
|
|
||||||
notifyChange()
|
|
||||||
markUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
override def update()
|
override def update()
|
||||||
{
|
{
|
||||||
super.update()
|
super.update()
|
||||||
|
|
||||||
/*
|
/**
|
||||||
//TODO: Debug with free energy
|
* Produce torque based on current.
|
||||||
if (mechNode.power > dcNode.power)
|
*/
|
||||||
{
|
val power = electricNode.power
|
||||||
//Produce electricity
|
val torque = TileMotor.motorConstant * electricNode.current
|
||||||
dcNode.setVoltage(mechNode.power)
|
|
||||||
//TODO: Resist mech energy
|
//TODO: Check if angular velocity should be generated based on torque
|
||||||
}
|
if (torque != 0)
|
||||||
// else if (dcNode.power > mechNode.power)
|
mechNode.rotate(torque, power / torque)
|
||||||
else*/
|
|
||||||
{
|
/**
|
||||||
//Produce mechanical energy
|
* Motors produce emf or counter-emf by Lenz's law based on angular velocity
|
||||||
val mechRatio = Math.pow(10, gearRatio)
|
* emf = change of flux/time
|
||||||
val power = electricNode.power
|
* = (NBCos(x))/time
|
||||||
val negate = if (electricNode.voltage > 0) 1 else -1
|
*/
|
||||||
mechNode.rotate(negate * power * mechRatio, negate * power / mechRatio)
|
val inducedEmf = TileMotor.motorConstant * mechNode.angularVelocity // * Math.sin(mechNode.angularVelocity * System.currentTimeMillis() / 1000d)
|
||||||
//TODO: Resist DC energy
|
electricNode.generateVoltage(inducedEmf * -1)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override def setIO(dir: ForgeDirection, ioType: Int)
|
override def setIO(dir: ForgeDirection, ioType: Int)
|
||||||
|
@ -110,6 +102,18 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updateConnectionMask()
|
||||||
|
{
|
||||||
|
electricNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
|
||||||
|
electricNode.positiveTerminals.clear()
|
||||||
|
electricNode.negativeTerminals.clear()
|
||||||
|
electricNode.positiveTerminals.addAll(getInputDirections())
|
||||||
|
electricNode.negativeTerminals.addAll(getOutputDirections())
|
||||||
|
electricNode.reconstruct()
|
||||||
|
notifyChange()
|
||||||
|
markUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
|
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue