Skip to content

Commit

Permalink
minor update to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
altavir committed Nov 23, 2023
1 parent 81d6b67 commit 827eb6e
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions demo/constructor/src/jvmMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ fun main() = application {
kd: Double,
timeStep: Duration,
) : PidParameters {
override var kp by mutableStateOf(kp)
override var ki by mutableStateOf(ki)
override var kd by mutableStateOf(kd)
override var timeStep by mutableStateOf(timeStep)
override var kp by mutableStateOf(kp)
override var ki by mutableStateOf(ki)
override var kd by mutableStateOf(kd)
override var timeStep by mutableStateOf(timeStep)
}

val pidParameters = remember {
Expand All @@ -144,38 +144,70 @@ fun main() = application {
mass = 0.05
)

Window(onCloseRequest = ::exitApplication) {
Window(title = "Pid regulator simulator", onCloseRequest = ::exitApplication) {
MaterialTheme {
Column {
Row {
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(
pidParameters.kp.toFloat(),
{ pidParameters.kp = it.toDouble()},
valueRange = 0f..10f,
{ pidParameters.kp = it.toDouble() },
valueRange = 0f..20f,
steps = 100
)
}
Row {
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(
pidParameters.ki.toFloat(),
{ pidParameters.ki = it.toDouble()},
valueRange = -5f..5f,
{ pidParameters.ki = it.toDouble() },
valueRange = -10f..10f,
steps = 100
)
}
Row {
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(
pidParameters.kd.toFloat(),
{ pidParameters.kd = it.toDouble()},
valueRange = -5f..5f,
{ pidParameters.kd = it.toDouble() },
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
)
}
Expand All @@ -187,7 +219,7 @@ fun main() = application {
kd = -0.1
timeStep = 0.005.seconds
}
}){
}) {
Text("Reset")
}
}
Expand Down

0 comments on commit 827eb6e

Please sign in to comment.