diff --git a/210983/README.md b/210983/README.md new file mode 100644 index 0000000..f08143b --- /dev/null +++ b/210983/README.md @@ -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. \ No newline at end of file diff --git a/210983/main.py b/210983/main.py new file mode 100644 index 0000000..b4d7cec --- /dev/null +++ b/210983/main.py @@ -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() \ No newline at end of file