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

Controls task by 210983 #84

Open
wants to merge 8 commits into
base: ros
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 210983/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Steps Followed
1). Made the cartpole environment using gym.
2). Implemented a basic pid control for the output(theta).
3). The desired value of the output is zero, so the error is the value of theta.
4). Calculated the integral by adding values of theta on every iteration.
5). The derivative was given to us by the env observation(angular velocity).
6). Tuned the PID coefficients by hit and trial.
33 changes: 33 additions & 0 deletions 210983/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gym

env = gym.make('CartPole-v1')
observation = env.reset()

Kp = 10;
Kd = 12;
Ki = 4;
F = 0
integral = 0
force = 0;

for _ in range(1000):
env.render()
observation, reward, done , info = env.step(force)
theta = observation[2]
angular_vel = observation[3]

integral += theta
F = Kp*theta + Ki*integral + Kd*angular_vel

if F > 0:
force = 1
else:
force = 0

print(force)

if done:
observation = env.reset()
integral = 0

env.close()