The filed python files contain starter environments in which you have to add your own code.
Your task is to add a PID controller to control the movement of the plate and make the ball reach the point set as input.
In case you do not have python, and a text editor installed then, we would recommend that you check out this video so that you have a nice setup to work with for the rest of the week!
Download the repo as a zip file by clicking on this link and expand it in a convenient location.
Now open a terminal inside the directory week 2 within the expanded folder. Then type the following commands to run the code.
python main.py
Refer to the last few sections of the week 1(click here) material for this topic, especially the python code at the end.
You can go through this PID Playlist for a quick refresher on what PID control is and how it is used. You don't need to watch the whole playlist, this is just to refresh a few key concepts that will be used.
Keep checking the resources page on Moodle for additional resources.
- pygame documentation - Very useful for finding useful functions, specially this - pygame.math.Vector2
- Pygame tutorial - do only what is required
- Python tutorial - Feel free to skip sections since we have already covered the same concepts in CS101
We have plate resting on a pivot. Either sides of the plate are attached to actuators that can change the angle of the plate within realistic speeds. The user is going to input a point on the plate with a mouse click. Your task is to code a controller which can make the ball reach that point. The system follows the ordinary differential equation:\
Happy Coding!!
- Find out all the variables you need to solve the PID equation and the ODE. Make sure you keep track of the integral and error terms as they may be used across time periods.
- Choose an appropriately small dt value.
- Set up constants of the PID controller in Control.py
- Write down the equations with the help of the code given in the week 1 colab link. Make sure to use the odeint() function to solve the ODE.
- Feel free to use as many parameters across the solve() function for both input and output.
- Make sure to set up saturation limits for theta, dtheta and x. Preferable the limits should be 15 degrees, 1 degree and 300 px for the three variables.
- Tune the PID controller to make the process as ideal as possible.
- Try to make your code run multiple PID loops in the same window one after the other. That is, if one set point value is reached another one can be input in the same window.
- A good project submission would show that a certain set point is reached. This can be defined as the ball being in acceptable and small enough range of the set point and the velocity of the ball being close enough to 0.