Wifi Webserver to control the Speed of a motor using PID
Dependencies: 4DGL-uLCD-SE PID QEI SDFileSystem mbed
Revision 1:1490beafb4f7, committed 2015-11-25
- Comitter:
- electromotivated
- Date:
- Wed Nov 25 02:49:45 2015 +0000
- Parent:
- 0:7478eabf00eb
- Child:
- 2:f579e98b82de
- Commit message:
- Success;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 25 02:11:34 2015 +0000
+++ b/main.cpp Wed Nov 25 02:49:45 2015 +0000
@@ -33,6 +33,8 @@
TODO: Move debugging printf statements inside of #ifdef DEBUG
statements, so that serial terminal print statements can be
turned on and off easily for debugging.
+
+ TODO: Implement stop button in webpage
*/
@@ -71,10 +73,11 @@
const float output_upper_limit = 1.0;
const float FEEDBACK_SCALE = 1.0/3000.0; // Scale feedback to 1rev/3000cnts
// this is encoder specific.
+// Init Webpage to these values
const float setpoint_init = 0.0;
const float kp_init = 0.01;
-const float ki_init = 0.01;
-const float kd_init = 0.0;
+const float ki_init = 0.015;
+const float kd_init = 0.0001;
const float Ts_init = 0.04; // 25Hz Sample Freq (40ms Sample Time)
PID pid(&setpoint, &feedback, &output, output_lower_limit, output_upper_limit,
@@ -97,7 +100,7 @@
/****************** Load Webpage from SD Card***************************************/
/***********************************************************************************/
- char file[] = "/sd/pid_pos.html";
+ char file[] = "/sd/pid_spd.html";
// Get file size so we can dynamically allocate buffer size
int num_chars = 0;
@@ -506,7 +509,7 @@
else mtr_pwm = 0.0;
}
}
- float k = Ts/2.0; // Discrete time, (Ts/2 because this callback is called
+ float k = Ts_init/2.0; // Discrete time, (Ts/2 because this callback is called
// at interval of Ts/2... or twice as fast as pid controller)
/* TODO: Implement a "rolling"/"moving" average */
@@ -535,10 +538,46 @@
Copy and past text below into a html file and save as the given file name to
your SD card.
-file name: pid_pos.html
+file name: pid_spd.html
html text:
+<!DOCTYPE html>
+<html>
+<head>
+<title>PID Motor Speed Control</title>
+</head>
+<body>
+<h1>PID Motor Speed Control</h1>
+<h2>Motor Status</h2>
+<p>
+<form title="Motor Status">
+<input type="text" value="Some user information" size="25" readonly /><br>
+Current Setpoint:
+<input type="number" name="current_setpoint" value="0000.00" readonly /><br>
+Current Position:
+<input type="number" name="current_position" value="0000.00" readonly /><br>
+</form>
+</p>
+<h2>PID Status</h2>
+<form title="User Input" method="post">
+PID Controls: <br>
+Setpoint (RPM):
+<input type="number" name="setpoint_input" value="0000.00" step="0.01" size="6" /><br>
+Proportional Gain:
+<input type="number" name="kp_input" value="000.01" step="0.0001" size="6" /><br>
+Integral Gain:
+<input type="number" name="ki_input" value="000.01" step="0.0001" size="6" /><br>
+Derivative Gain:
+<input type="number" name="kd_input" value="000.00" step="0.0001" size="6" /><br>
+<br>
+<input type="submit" value="Submit" />
+<input type="submit" name="update" value="Update">
+<input type="submit" name="estop" value="STOP">
+</form>
+</body>
+</html>
+
*****************************************************************************/
/*****************************************************************************/
\ No newline at end of file