After completing the "Train TD3 Agent for PMSM Control" tutorial, I’m attempting to integrate reinforcement learning into my custom PMSM Simulink model—specifically, replacing the current loop PI controller with an RL agent, just like in the tutorial. However, after modifying the Simulink model, I encountered the following error when starting training:
Error using rl.internal.train.OffPolicyTrainer/run_internal_/nestedRunEpisode (line 304)
An error occurred while running the simulation for model 'rl_Basic_Model' with the following RL agent blocks:
rl_Basic_Model/Current_Regulator/rlCurrentController/Reinforcement Learning/RL Agent
Error in rl.internal.train.OffPolicyTrainer/run_internal_ (line 371)
out = nestedRunEpisode(policy);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in rl.internal.train.OffPolicyTrainer/run_ (line 39)
result = run_internal_(this);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in rl.internal.train.Trainer/run (line 8)
Error in rl.internal.trainmgr.OnlineTrainingManager/run_ (line 135)
trainResult = run(trainer);
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in rl.internal.trainmgr.TrainingManager/run (line 4)
Error in rl.agent.AbstractAgent/train (line 86)
trainingResult = run(tm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Error using rl.env.internal.reportSimulinkSimError (line 29)
'rl_Basic_Model/Current_Regulator/rlCurrentController/Reinforcement Learning/RL Agent/reward' has sample time 5e-05. Sample time of block must be inherited (-1) because blocks in a triggered subsystem must run only when the triggered subsystem runs.
understand this error is caused by the triggered subsystem in my model. Let me explain why I use triggers: In my SVPWM block, I output two triggers:
- A pwm trigger to trigger current loop calculations.
- A 1ms_trigger for speed loop or MTPA calculations.Finally, the block outputs pulses connected to the Universal Bridge block.(My PWM frequency is 20kHz (Ts=5e-5s), and the simulation step size is set to 3e-7s.)
My Questions:
- How can I resolve this sample time error while retaining my existing trigger logic? Is it possible to proceed with RL training without removing the triggers?
- When the RL Toolbox calls my Simulink model, does the environment update (e.g., changes in the motor, inverter, etc.) still follow my configured simulation step size (3e-7s as mentioned above)?
- The relationship between agent-sample time, simulation step.
Any guidance or suggestions would be greatly appreciated! Thank you.