Merge remote-tracking branch 'spc/dev' into dev

This commit is contained in:
Alexander Nozik 2023-12-13 20:24:43 +03:00
commit 5e64b79b77

View File

@ -123,10 +123,10 @@ fun main() = application {
kd: Double, kd: Double,
timeStep: Duration, timeStep: Duration,
) : PidParameters { ) : PidParameters {
override var kp by mutableStateOf(kp) override var kp by mutableStateOf(kp)
override var ki by mutableStateOf(ki) override var ki by mutableStateOf(ki)
override var kd by mutableStateOf(kd) override var kd by mutableStateOf(kd)
override var timeStep by mutableStateOf(timeStep) override var timeStep by mutableStateOf(timeStep)
} }
val pidParameters = remember { val pidParameters = remember {
@ -144,38 +144,70 @@ fun main() = application {
mass = 0.05 mass = 0.05
) )
Window(onCloseRequest = ::exitApplication) { Window(title = "Pid regulator simulator", onCloseRequest = ::exitApplication) {
MaterialTheme { MaterialTheme {
Column { Column {
Row { Row {
Text("kp:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp)) Text("kp:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp))
TextField(pidParameters.kp.toString(),{pidParameters.kp = it.toDouble()}, enabled = false) TextField(
String.format("%.2f",pidParameters.kp),
{ pidParameters.kp = it.toDouble() },
Modifier.width(100.dp),
enabled = false
)
Slider( Slider(
pidParameters.kp.toFloat(), pidParameters.kp.toFloat(),
{ pidParameters.kp = it.toDouble()}, { pidParameters.kp = it.toDouble() },
valueRange = 0f..10f, valueRange = 0f..20f,
steps = 100 steps = 100
) )
} }
Row { Row {
Text("ki:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp)) Text("ki:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp))
TextField(pidParameters.ki.toString(),{pidParameters.ki = it.toDouble()}, enabled = false) TextField(
String.format("%.2f",pidParameters.ki),
{ pidParameters.ki = it.toDouble() },
Modifier.width(100.dp),
enabled = false
)
Slider( Slider(
pidParameters.ki.toFloat(), pidParameters.ki.toFloat(),
{ pidParameters.ki = it.toDouble()}, { pidParameters.ki = it.toDouble() },
valueRange = -5f..5f, valueRange = -10f..10f,
steps = 100 steps = 100
) )
} }
Row { Row {
Text("kd:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp)) Text("kd:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp))
TextField(pidParameters.kd.toString(),{pidParameters.kd = it.toDouble()}, enabled = false) TextField(
String.format("%.2f",pidParameters.kd),
{ pidParameters.kd = it.toDouble() },
Modifier.width(100.dp),
enabled = false
)
Slider( Slider(
pidParameters.kd.toFloat(), pidParameters.kd.toFloat(),
{ pidParameters.kd = it.toDouble()}, { pidParameters.kd = it.toDouble() },
valueRange = -5f..5f, valueRange = -10f..10f,
steps = 100
)
}
Row {
Text("dt:", Modifier.align(Alignment.CenterVertically).width(50.dp).padding(5.dp))
TextField(
pidParameters.timeStep.toString(DurationUnit.MILLISECONDS),
{ pidParameters.timeStep = it.toDouble().milliseconds },
Modifier.width(100.dp),
enabled = false
)
Slider(
pidParameters.timeStep.toDouble(DurationUnit.MILLISECONDS).toFloat(),
{ pidParameters.timeStep = it.toDouble().milliseconds },
valueRange = 0f..100f,
steps = 100 steps = 100
) )
} }
@ -187,7 +219,7 @@ fun main() = application {
kd = -0.1 kd = -0.1
timeStep = 0.005.seconds timeStep = 0.005.seconds
} }
}){ }) {
Text("Reset") Text("Reset")
} }
} }