Move dt/sim_warp_factor from config.json to CLI flags
Both are run-mode knobs (how fast to drive this particular process), not config.json material (a plant/hardware description that stays the same regardless of how a run happens to be invoked) - --dt and --sim-warp-factor, defaulting to 1.0 each (real time, 1-simulated- second ticks) unless a dev/test run asks for a faster warp explicitly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019qvu5giu7gvRCyEWzf2Vpx
This commit is contained in:
@@ -114,7 +114,7 @@ callbacks, e.g.:
|
|||||||
real, unmodeled kettle, has no model to feed)
|
real, unmodeled kettle, has no model to feed)
|
||||||
|
|
||||||
Each component runs inside its own `ATask` at a configurable interval
|
Each component runs inside its own `ATask` at a configurable interval
|
||||||
(`Controller.dt`, scaled by `sim_warp_factor`) and pushes state changes onto a
|
(`--dt`, scaled by `--sim-warp-factor`) and pushes state changes onto a
|
||||||
keyed WebSocket channel that any connected client can subscribe to and send
|
keyed WebSocket channel that any connected client can subscribe to and send
|
||||||
commands back on (e.g. `{"TempCtrl": {"Soll": {"Temp": 65}}}`).
|
commands back on (e.g. `{"TempCtrl": {"Soll": {"Temp": 65}}}`).
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ambient_temperature": 20,
|
"ambient_temperature": 20,
|
||||||
"Controller" : {
|
"Controller" : {
|
||||||
"dt": 1,
|
|
||||||
"sim_warp_factor": 50.0,
|
|
||||||
"stirrer_name": "sim",
|
"stirrer_name": "sim",
|
||||||
"plant_name": "sim",
|
"plant_name": "sim",
|
||||||
"pid_type": "Smith"
|
"pid_type": "Smith"
|
||||||
|
|||||||
+13
-3
@@ -39,6 +39,16 @@ if __name__ == '__main__':
|
|||||||
parser = ap.ArgumentParser()
|
parser = ap.ArgumentParser()
|
||||||
parser.add_argument("-c", "--config", default="config.json")
|
parser.add_argument("-c", "--config", default="config.json")
|
||||||
parser.add_argument("-m", "--logdir", default="logs")
|
parser.add_argument("-m", "--logdir", default="logs")
|
||||||
|
# Simulated seconds per tick, and how many of those fit into one real
|
||||||
|
# second - run-mode knobs (how fast to drive this particular process),
|
||||||
|
# not config.json material (a *plant/hardware* description that stays
|
||||||
|
# the same regardless of how this run happens to be invoked) - see
|
||||||
|
# tasks/sud_forecast.py's SudForecastEstimator and every *Task's own
|
||||||
|
# dt/interval split for where these actually end up. Defaulting both
|
||||||
|
# to 1.0 means real time, 1-simulated-second ticks unless asked
|
||||||
|
# otherwise - e.g. a much higher --sim-warp-factor for dev/testing.
|
||||||
|
parser.add_argument("--dt", type=float, default=1.0)
|
||||||
|
parser.add_argument("--sim-warp-factor", type=float, default=1.0)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -54,8 +64,8 @@ if __name__ == '__main__':
|
|||||||
server = WsServerMultiUser(listener=dispatcher)
|
server = WsServerMultiUser(listener=dispatcher)
|
||||||
taskmgr = TaskManager()
|
taskmgr = TaskManager()
|
||||||
|
|
||||||
DT = config['Controller']['dt']
|
DT = args.dt
|
||||||
DT_TASK = 1.0 / config['Controller']['sim_warp_factor']
|
DT_TASK = 1.0 / args.sim_warp_factor
|
||||||
theta_amb = config['ambient_temperature']
|
theta_amb = config['ambient_temperature']
|
||||||
plant_sim = "sim" in config['Controller']['plant_name']
|
plant_sim = "sim" in config['Controller']['plant_name']
|
||||||
|
|
||||||
@@ -113,7 +123,7 @@ if __name__ == '__main__':
|
|||||||
# see components/sud_forecast.py.
|
# see components/sud_forecast.py.
|
||||||
forecast_estimator = SudForecastEstimator(
|
forecast_estimator = SudForecastEstimator(
|
||||||
DT, theta_amb, config['Controller']['pid_type'], config['TempCtrl'],
|
DT, theta_amb, config['Controller']['pid_type'], config['TempCtrl'],
|
||||||
heater.get_powers(), config['Controller']['sim_warp_factor'])
|
heater.get_powers(), args.sim_warp_factor)
|
||||||
sud_task = SudTask(sud, tc, stirrer, pot, DT, DT_TASK, dispatcher.msgio_get("Sud"), forecast_estimator)
|
sud_task = SudTask(sud, tc, stirrer, pot, DT, DT_TASK, dispatcher.msgio_get("Sud"), forecast_estimator)
|
||||||
taskmgr.add(sud_task)
|
taskmgr.add(sud_task)
|
||||||
# Records every Sud run's measured data and forecast to their own
|
# Records every Sud run's measured data and forecast to their own
|
||||||
|
|||||||
Reference in New Issue
Block a user