Skip to content

Commit

Permalink
OA: RL PID Controller (SISO) #1050
Browse files Browse the repository at this point in the history
  • Loading branch information
amesin13 committed Oct 14, 2024
1 parent b7621c3 commit de7c6e3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mlpro/oa/control/controllers/oa_pid_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mlpro.bf.control.controllers.pid_controller import PIDController
from mlpro.bf.ml.basics import *
from mlpro.rl import Policy,SARSElement
from mlpro.bf.systems import ControlVariable, ControlledVariable
from mlpro.bf.control import ControlVariable, ControlledVariable


class RLPID(Policy):
Expand Down
1 change: 1 addition & 0 deletions src/mlpro/oa/control/controllers/wrapper_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def compute_output( self, p_ctrl_error: ControlError ) -> ControlVariable:


## -------------------------------------------------------------------------------------------------

def _adapt(self, p_ctrl_error: ControlError, p_ctrl_var: ControlVariable) -> bool:

# 0 Intro
Expand Down
11 changes: 6 additions & 5 deletions test/test_oa_pid_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mlpro.rl.models import *
from mlpro.rl.models_env import Reward
import datetime
from mlpro.bf.systems import ControlVariable, ControlledVariable
from mlpro.bf.control import ControlVariable, ControlledVariable

import math
matplotlib.use('TkAgg')
Expand All @@ -31,7 +31,7 @@ def __init__(self, p_logging=Log.C_LOG_ALL):



def _compute_reward(self, p_state_old: wrapper_rl.ControlledVariable = None, p_state_new: wrapper_rl.ControlledVariable = None) -> Reward:
def _compute_reward(self, p_state_old: ControlledVariable = None, p_state_new: ControlledVariable= None) -> Reward:

#get old error
error_old = p_state_old.get_feature_data().get_values()[0]
Expand Down Expand Up @@ -121,13 +121,13 @@ def _compute_reward(self, p_state_old: wrapper_rl.ControlledVariable = None, p_s

setpoint_space = Set()
setpoint_space.add_dim(p_dim=setpoint_dim)
setpoint = SetPoint(p_setpoint_data=Element(p_set=setpoint_space),p_tstamp=datetime.datetime.now())
setpoint.get_feature_data().set_value(setpoint_space.get_dim_ids()[0],0)
setpoint = SetPoint(p_id=0,p_value_space=setpoint_space,p_values=[0],p_tstamp=datetime.datetime.now())



error_space = Set()
error_space.add_dim(p_dim=error_dim)
control_error = ControlError(p_error_data=Element(error_space),p_tstamp=datetime.datetime.now())
control_error = ControlError(p_id=0,p_value_space=error_space,p_values=[0],p_tstamp=datetime.datetime.now())
oa_controller=wrapper_rl.OAControllerRL(p_input_space=MSpace(),p_output_space=MSpace(),p_rl_policy=rl_pid_policy,p_rl_fct_reward=MyReward())


Expand Down Expand Up @@ -160,6 +160,7 @@ def _compute_reward(self, p_state_old: wrapper_rl.ControlledVariable = None, p_s
control_error.get_feature_data().set_value(error_space.get_dim_ids()[0],actual_angle-setpoint.get_feature_data().get_values()[0])
control_error.set_tstamp(datetime.datetime.now())


oa_controller._adapt(p_ctrl_error=control_error,p_ctrl_var=ControlVariable())


Expand Down

0 comments on commit de7c6e3

Please sign in to comment.