Skip to content

IEEERASPESU/pid-challenge-template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 RERO PID Tuning Challenge — Round 0: The Control Warm-Up

Welcome to the RERO Robotics Hackathon — Round 0 (Online Round)!

This round is completely virtual. You will design and tune a PID controller to control a simulated Mass–Spring–Damper system. Your goal: make the system reach its target quickly, smoothly, and efficiently.


⚠️ IMPORTANT: READ THIS FIRST

🚨 ONLY EDIT ONE FILE: submission_template/pid_controller.py

❌ Do NOT modify or move any other files. ❌ Do NOT rename folders or edit the grader scripts. ✅ Your task is only to implement your PID parameters in pid_controller.py.

If you edit anything else, your submission will fail the autograder and earn zero.


🧠 1. What is this challenge?

You’ll tune a PID controller that drives a simulated mass–spring–damper system to a target position. Your controller will be tested automatically using multiple simulations. Each test evaluates how fast, accurate, and smooth your control is. The better your tuning, the higher your score (out of 1000).

You only need to implement one function:

def get_pid(seed):
    Kp = ...
    Ki = ...
    Kd = ...
    return Kp, Ki, Kd

⚙️ 2. How the system works

The system you’re controlling is a mass–spring–damper:

$$ m\ddot{y} + c\dot{y} + ky = u $$

Where:

  • $m$: mass
  • $c$: damping coefficient
  • $k$: spring stiffness
  • $y$: output position
  • $u$: control force (PID output)

This setup models many real systems — like suspension, robotic joints, or drones.

Default system parameters

Parameter Symbol Value Unit
Mass m 15.0 kg
Damping c 10.5 N·s/m
Spring constant k 25.0 N/m
Max actuator force uₘₐₓ 75.0 N
Sampling time Ts 0.01 s

Random noise and small disturbances are added automatically. Your PID must handle these variations gracefully.


🧾 3. Files in this repository

File/Folder Purpose Can you edit it?
submission_template/pid_controller.py Your file. Implement get_pid(seed) here. ✅ YES
grader/evaluator.py Runs the simulation and evaluates your PID. ❌ NO
grader/plant.py The simulated mass–spring–damper system. ❌ NO
grader/scoring.py Measures metrics like rise time, overshoot, etc. ❌ NO
.github/workflows/classroom.yml GitHub Actions autograder workflow. ❌ NO

🧪 4. How to test your PID locally

You can test everything on your own computer before submitting.

Step 1 — Install Python

You need Python 3.9 or later. Check your version:

python --version

Step 2 — Install dependencies

In your project folder, run:

pip install numpy matplotlib

(If a requirements.txt is provided, you can run pip install -r requirements.txt.)

Step 3 — Run the evaluator

Run the evaluator script:

python -m grader.evaluator submission_template/pid_controller.py

It will:

  • Load your PID gains

  • Simulate the system

  • Save the results as:

    • score.json — detailed numeric results
    • result.png — graph of your system response

You’ll see output like:

[INFO] Master RNG seed = 1234567
Mean score: 782.4
Results saved to score.json and result.png

Step 4 — Check your results

Open result.png to see how your controller performed. Open score.json to view metrics like overshoot, rise time, settling time, IAE, and energy.

If your score is low, tweak Kp, Ki, and Kd in pid_controller.py and run again.


🧩 5. How the scoring works

The system measures several performance metrics:

Metric Description Ideal Value
Overshoot How far you exceed the target Low
Undershoot How far you dip below target Low
Rise Time Time to reach 90% of target Short
Settling Time Time to remain within ±7.5% Short
ESS Steady-state error Near 0
Smoothness How stable the response is High
IAE Integrated absolute error Small
Energy Actuator effort used Low

Your total score starts at 1000 points. Points are subtracted based on these metrics. Higher is better.


🧮 6. How to submit on GitHub Classroom

Step 1 — Accept the assignment

Click the GitHub Classroom link provided by the organizers. This creates your private repo (e.g., pid-tuning-yourname).

Step 2 — Edit only this file

submission_template/pid_controller.py

Example:

def get_pid(seed):
    Kp = 12.0
    Ki = 5.0
    Kd = 1.2
    return Kp, Ki, Kd

Step 3 — Test locally

Run:

python -m grader.evaluator submission_template/pid_controller.py

Step 4 — Commit and push

Once satisfied with your results:

git add submission_template/pid_controller.py
git commit -m "Updated PID tuning"
git push origin main

GitHub Actions will automatically:

  • Run the evaluator,
  • Generate your score,
  • Upload score.json and result.png as artifacts,
  • Update the leaderboard.

You can view results in the Actions tab on your repo.


📚 7. Understanding the Mass–Spring–Damper System

Imagine:

  • A block (mass) connected to a spring and a damper.
  • When you push the block, it moves.
  • The spring tries to pull it back.
  • The damper tries to slow it down.

That’s your system. Your job is to control it so it reaches the target position and stays there quickly and smoothly.

Typical behavior

Type Damping Ratio Description
Underdamped < 0.5 Oscillatory
Critically damped ≈ 0.7 Fast and smooth
Overdamped > 1.0 Slow but stable

Your system has moderate damping (≈ 0.68) — a balanced test case for PID control.


🎛️ 8. Understanding PID Controllers

A PID Controller combines three simple ideas:

$$ u(t) = K_p e(t) + K_i \int e(t),dt + K_d \frac{d e(t)}{dt} $$

Where $e(t) = \text{setpoint} - y(t)$.

Term Role Effect
P (Proportional) Reacts to present error Faster response; may overshoot
I (Integral) Reacts to accumulated error Removes steady-state offset
D (Derivative) Reacts to error rate Dampens oscillations

You tune (Kp, Ki, Kd) to balance speed, accuracy, and stability.


⚗️ 9. How to tune PID parameters

🔹 Manual tuning

  1. Set Ki = 0 and Kd = 0.
  2. Increase Kp until you observe small oscillations.
  3. Add Kd to reduce oscillations and overshoot.
  4. Add Ki to eliminate steady-state error.
  5. Iterate: small changes → re-test → evaluate.

🔹 Ziegler–Nichols method (classic)

  1. Set Ki = 0, Kd = 0.
  2. Increase Kp until the system oscillates continuously — this is Ku (ultimate gain).
  3. Measure the oscillation period Pu.
  4. Apply:
Controller Kp Ti Td
P 0.5·Ku
PI 0.45·Ku Pu / 1.2
PID 0.6·Ku Pu / 2 Pu / 8

This gives a starting point; fine-tune manually afterwards.

🔹 Starting example (baseline)

Try this to get going:

def get_pid(seed):
    Kp = 12.0
    Ki = 5.0
    Kd = 1.2
    return Kp, Ki, Kd

Then adjust values based on your result.png and score.json.


🧾 10. Example of good vs bad control

Good PID response:

  • Smooth rise
  • Little or no overshoot
  • Settles quickly near setpoint

Bad PID response:

  • Large oscillations
  • Excessive overshoot/undershoot
  • Very slow to settle or never reaches setpoint

Aim for a clean, fast rise and stable steady-state.


🏁 11. Scoring summary

Metric Ideal
Overshoot Low
Settling time Short
ESS (steady-state error) Near 0
Smoothness High
IAE (integrated abs error) Small
Energy Low

Higher score indicates better control performance.


🚀 12. Submission checklist

  • ✅ Edited only submission_template/pid_controller.py
  • ✅ Ran evaluator locally with no errors
  • ✅ Committed and pushed changes to GitHub
  • ✅ Verified the GitHub Action completed successfully
  • ✅ Downloaded your score.json and result.png from Actions → Artifacts

📖 13. Extra reading


💬 Need help?

If you’re stuck or confused:

  • Email: ieee.ras.rr@pes.edu

We’ll help you get set up.


💡 Final tip

“If it overshoots, lower Kp. If it oscillates, increase Kd. If it never reaches the target, increase Ki.”

Good luck, engineers — and remember: Do not edit any file except submission_template/pid_controller.py.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%