Hardware:
- Arduino Mega2560
- Motor Shield: Dual H-brigde VNH2SP30
- Due to there is no lib of this shield, I modify the dual-vnh5019 Lib to fit the goal
- Github: https://github.com/kvzhao/DualVNH2SH30MotorShield
- DC Motor - IG42
- I also write a C++ wrapper for this motor, utilizing Encoder lib(also a little modify for constructor) and VNH2SP30 lib
- Github: https://github.com/kvzhao/DCMotorIG42
Source Code on Github: https://github.com/kvzhao/ME-PIDLab
The crucial part of the PID code is listed below
void loop() { // Run a period to estimate more precise speed Motor.Tick(); // Run for one Second delay(SamplingTime); Motor.Tock(); // Read rotation speed from Encoder Input = Motor.getSpeedRPS(); // PID Compute PID_Controller.Compute(); if ((Output-prevOutput) >= oscGap) { //Output = prevOutput; } Motor.setSpeed(Output); prevOutput = Output; // Show Data /* Serial.print("Input: "); Serial.println(Input); Serial.print("Setpoint: "); Serial.println(Setpoint); Serial.print("Error: "); Serial.println(error); Serial.print("Output: "); Serial.println(Output);*/ Serial.println(error); // wait a little while delay(5); }
My first test result (with KP=98, KI=8, PD=5)
There is almost no steady state error, however overshoot happens.
Next step is to tune the parameters and control the motor smoothly!
Some useful references
- http://www.robotroom.com/PWM5.html
- http://www.precisionmicrodrives.com/application-notes-technical-guides/application-bulletins/ab-012-driving-vibration-motors-with-pwm
- http://lancet.mit.edu/motors/motors3.html
- http://mechatronics.mech.northwestern.edu/design_ref/actuators/motor_theory.html
- http://www.roadtocreate.com/?tag=vnh2sp30
- http://www.pololu.com/product/537
沒有留言:
張貼留言