Remove automatic reads from virtual drive and pid
This commit is contained in:
parent
811477a636
commit
2698cee80b
@ -48,7 +48,7 @@ public class VirtualDrive(
|
|||||||
public val positionState: MutableDeviceState<Double>,
|
public val positionState: MutableDeviceState<Double>,
|
||||||
) : Drive, DeviceBySpec<Drive>(Drive, context) {
|
) : Drive, DeviceBySpec<Drive>(Drive, context) {
|
||||||
|
|
||||||
private val dt = meta["time.step"].double?.milliseconds ?: 5.milliseconds
|
private val dt = meta["time.step"].double?.milliseconds ?: 1.milliseconds
|
||||||
private val clock = context.clock
|
private val clock = context.clock
|
||||||
|
|
||||||
override var force: Double = 0.0
|
override var force: Double = 0.0
|
||||||
@ -73,7 +73,6 @@ public class VirtualDrive(
|
|||||||
|
|
||||||
// compute new value based on velocity and acceleration from the previous step
|
// compute new value based on velocity and acceleration from the previous step
|
||||||
positionState.value += velocity * dtSeconds + force / mass * dtSeconds.pow(2) / 2
|
positionState.value += velocity * dtSeconds + force / mass * dtSeconds.pow(2) / 2
|
||||||
propertyChanged(Drive.position, positionState.value)
|
|
||||||
|
|
||||||
// compute new velocity based on acceleration on the previous step
|
// compute new velocity based on acceleration on the previous step
|
||||||
velocity += force / mass * dtSeconds
|
velocity += force / mass * dtSeconds
|
||||||
|
@ -62,7 +62,6 @@ public class PidRegulator(
|
|||||||
lastPosition = drive.position
|
lastPosition = drive.position
|
||||||
|
|
||||||
drive.force = pidParameters.kp * delta + pidParameters.ki * integral + pidParameters.kd * derivative
|
drive.force = pidParameters.kp * delta + pidParameters.ki * integral + pidParameters.kd * derivative
|
||||||
propertyChanged(Regulator.position, drive.position)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import space.kscience.controls.manager.DeviceManager
|
|||||||
import space.kscience.controls.manager.clock
|
import space.kscience.controls.manager.clock
|
||||||
import space.kscience.controls.spec.doRecurring
|
import space.kscience.controls.spec.doRecurring
|
||||||
import space.kscience.controls.spec.name
|
import space.kscience.controls.spec.name
|
||||||
|
import space.kscience.controls.spec.read
|
||||||
import space.kscience.controls.spec.write
|
import space.kscience.controls.spec.write
|
||||||
import space.kscience.controls.vision.plotDeviceProperty
|
import space.kscience.controls.vision.plotDeviceProperty
|
||||||
import space.kscience.controls.vision.plotNumberState
|
import space.kscience.controls.vision.plotNumberState
|
||||||
@ -66,6 +67,7 @@ public fun main() {
|
|||||||
val target = 5 * sin(2.0 * PI * freq * t) +
|
val target = 5 * sin(2.0 * PI * freq * t) +
|
||||||
sin(2 * PI * 21 * freq * t + 0.1 * (timeFromStart / pidParameters.timeStep))
|
sin(2 * PI * 21 * freq * t + 0.1 * (timeFromStart / pidParameters.timeStep))
|
||||||
pid.write(Regulator.target, target)
|
pid.write(Regulator.target, target)
|
||||||
|
pid.read(Regulator.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user