Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abir 210273 assignement 4 #95

Open
wants to merge 17 commits into
base: ros
Choose a base branch
from
34 changes: 34 additions & 0 deletions controls/cartpole.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions controls/readme.md
Original file line number Diff line number Diff line change
@@ -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.