An Arduino is used to balance a ball rolling on a beam. It uses an IR-Sensor for measurment and a PID-Controller controls the servo's output for lift.
You will need Arduino IDE to upload the code over to the Arduino Uno/Nano board.
Download .zip or clone repository to your computer.
The code utilize a number of open source libraries wich is included under /libraries.
The following libraries that are included:
- PID - PID
- Servo - Servo
- SharpDistSensor - SharpDistSensor
- Filters - Filters
Copy all of the content in the /libraries folder and move them over to your own Arduino libraries folder. This folder will often be in your Documents/Arduino folder.
You will now be able to open and run the project.
There are several constants and parameters that can vary. Therefor be aware that you might need to change the following to get it working:
- Sensor pin connected to A1
- Servo pin connected to D9
- START_POS should be at an angle where the beam is parallel to the ground
- SERVO_RANGE should be at an angle for good control, play around and check
- MIN_DISTANCE should be where you want the sensor to start measure distance
- MAX_DISTANCE should be where you want the sensor to stop measure distance
- mediumFilterWindowSize has to be an odd number and you should scale it up until noise is removed
- kp, ki, kd is the PID params and the numbers depend on your construction, play around and see
- irSensor.setModel(SharpDistSensor::GP2Y0A60SZLF_5V) be sure to select the right model
Open Serial Monitor and write any number between 0 - 100 to change setvalue.
Open Serial Plotter to watch values being plotted in real time.
Open Serial Monitor and you will now be able to change PID parameters by writing in the following format: 1.5:0.6:0.2 to change kp, ki, kd params.
- Arduino - Arduino
If you want to contribute or find anything wrong, please create a Pull request, or issue adressing the change, or issue.
- Magnus Øye - magnusoy
This project is licensed under the MIT License - see the LICENSE.md file for details