diff --git a/controls/cartpole.py b/controls/cartpole.py new file mode 100644 index 0000000..726bdc2 --- /dev/null +++ b/controls/cartpole.py @@ -0,0 +1,34 @@ +import gym + +env = gym.make("CartPole-v1") +observation = env.reset() + +P = 9.8 +I = 4.0 +D = 4.0 + +force = 0 +integral = 0 +for _ in range(400): + + env.render() + observe, reward, done, info = env.step(force) + + velocity = observe[1] + angle = observe[2] + angular_velocity = observe[3] + + integral = integral + angle + + F = P*(angle) + I*(integral)+ D*(angular_velocity) + + force = 1 + if F > 0: + force = 1 + else : + force=0 + if done: + observe = env.reset() + integral = 0 + +env.close() \ No newline at end of file diff --git a/controls/readme.md b/controls/readme.md new file mode 100644 index 0000000..a17bd3b --- /dev/null +++ b/controls/readme.md @@ -0,0 +1,5 @@ +assignement 4 +1) Installed pip from terminal. +2) Installed gym and pygame packages from terminal using pip. +3) Create an environment using env and import cartpole model. +4) Use that kp is multiplied by error (angle), ki is multiplied by the sum of errors and kd is multiplied by the angular velocity. \ No newline at end of file