
PID Motor Position Control using ESP8266 WiFi Module, US Digital E4P-100-079, LMD18200 H-Bridge Break Out, and HN-GH12-1634T 30:1 200RPM Motor
Dependencies: 4DGL-uLCD-SE PID QEI SDFileSystem mbed ESP8266_pid_mtrPos_webserver_SDcard_v2
Dependents: ESP8266_pid_mtrPos_webserver_SDcard_v2
Diff: main.cpp
- Revision:
- 3:6067780e2f45
- Parent:
- 2:af4befcd02d6
- Child:
- 5:2c728eb9bc80
--- a/main.cpp Wed Nov 25 01:22:14 2015 +0000 +++ b/main.cpp Wed Nov 25 01:33:27 2015 +0000 @@ -13,6 +13,9 @@ 2. Developed and tested with FireFox 42.0 Web Browser. Does not seem to work well with Google Chrome or Internet Explorer for some reason... they seem to generate two post requests which messes with the user input values. + + 3. There are a bunch of printf statements in the code that can be + uncommented for debugging in a serial terminal progrom. TODO: ESP8366 has a max packet send size. Make sure we implement @@ -20,12 +23,16 @@ listed in the official ESP8266 AT Commands Documentation, I think it is 2048 bytes/chars - TODO: CREATE CONFIG FUNCTION TO SET SSID, PASSWORD, BAUDRATE ETC. + TODO: CREATE CONFIG FUNCTION TO SET SSID, PASSWORD, BAUDRATE ETC. + Perhaps have a serial terminal method to take user input, and + put the function call into a #ifdef WiFiConfig statement, so + that the user can enable it to config Wifi module then turn + it off once Wifi module is configed so that this program can + run in a "stand alone" mode. - TODO: CREATE FUCNTIONS FOR WIFI AND SERVER!!! GET RID OF "MAGIC NUMBER" - MAKE THIS AWESOME!!!! - - TODO: COMMENT AND DOCUMENT THE HELL OUT OF THIS PROGRAM!!! + 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. */ @@ -175,7 +182,7 @@ if(esp.readable()){ getreply(500, buff, sizeof(buff), sizeof(buff) -1); // Get full buff, leave last element for null char // printf("\r\n*************WORKING BUFFER******************************\r\n"); - printf(buff); printf("\n"); +// printf(buff); printf("\n"); // printf("\r\n**************END WORKING BUFFER**************************\r\n"); // If Recieved Data get ID, Length, and Data @@ -197,25 +204,25 @@ <input type="xxx" value="xxx"> </Form> Only the input with name="xxx" will appear in body of HTML */ - printf("\r\n*************USER INPUT**********************************\r\n"); + // printf("\r\n*************USER INPUT**********************************\r\n"); parse_input(buff, &setpoint, &kp, &ki, &kd); setpoint = clip(setpoint, -999.99, 999.99); kp = clip(kp, 0.00, 999.99); ki = clip(ki, 0.00, 999.99); kd = clip(kd, 0.00, 999.99); - printf("User Entered: \nSetpoint: %7.2f\nKp: %6.2f\nKi: %6.2f\nKd: %6.2f\n", setpoint, kp, ki, kd); +// printf("User Entered: \nSetpoint: %7.2f\nKp: %6.2f\nKi: %6.2f\nKd: %6.2f\n", setpoint, kp, ki, kd); pid.set_parameters(kp, ki, kd, Ts_init); // Updata PID params - printf("Updated to Kp: %1.2f Ki: %1.2f Kd: %1.2f Ts: %1.2f\r\n", - pid.getKp(), pid.getKi(), pid.getKd(), pid.getTs()); - printf("Setpoint: %1.2f\r\n", setpoint); - printf("Output: %1.2f\r\n", output); - printf("\r\n*************END USER INPUT******************************\r\n"); + // printf("Updated to Kp: %1.2f Ki: %1.2f Kd: %1.2f Ts: %1.2f\r\n", + // pid.getKp(), pid.getKi(), pid.getKd(), pid.getTs()); +// printf("Setpoint: %1.2f\r\n", setpoint); +// printf("Output: %1.2f\r\n", output); +// printf("\r\n*************END USER INPUT******************************\r\n"); // Update Webpage to reflect new values POSTED by client static bool isFirstRequest = true; if(!isFirstRequest) update_webpage(webpage, setpoint, kp, ki, kd); else isFirstRequest = false; // First Request just send page with initial values - printf(webpage); // DEBUGGING ONLY!!! REMOVE FOR RELEASE!!! +// printf(webpage); // DEBUGGING ONLY!!! REMOVE FOR RELEASE!!! // Command TCP/IP Data Tx esp.printf("AT+CIPSEND=%d,%d\r\n", id, strlen(webpage)); @@ -435,7 +442,7 @@ char input_buff[50]; char* begin; char* end; - printf("**************Parsing**************\n"); +// printf("**************Parsing**************\n"); memset(input_buff, '\0', sizeof(input_buff)); // Null out input buff begin = strstr(webpage_user_data, "setpoint_input=") + sizeof("setpoint_input"); // Points to start of setpoint_input value @@ -443,7 +450,7 @@ for(long i = 0; i < end - begin; i++){ // Parse out the value one char at a time input_buff[i] = begin[i]; } - printf("Setpoint Parsed Data: %s\n", input_buff); +// printf("Setpoint Parsed Data: %s\n", input_buff); *setpoint = atof(input_buff); memset(input_buff, '\0', sizeof(input_buff)); // Null out input buff @@ -453,7 +460,7 @@ for(long i = 0; i < end - begin; i++){ // Parse out the value one char at a time input_buff[i] = begin[i]; } - printf("Kp Parsed Data: %s\n", input_buff); +// printf("Kp Parsed Data: %s\n", input_buff); *kp = atof(input_buff); memset(input_buff, '\0', sizeof(input_buff)); // Null out input buff @@ -463,7 +470,7 @@ for(long i = 0; i < end - begin; i++){ // Parse out the value one char at a time input_buff[i] = begin[i]; } - printf("Ki Parsed Data: %s\n", input_buff); +// printf("Ki Parsed Data: %s\n", input_buff); *ki = atof(input_buff); memset(input_buff, '\0', sizeof(input_buff)); // Null out input buff @@ -473,9 +480,9 @@ for(long i = 0; i < end - begin; i++){ // Parse out the value one char at a time input_buff[i] = begin[i]; } - printf("Kd Parsed Data: %s\n", input_buff); +// printf("Kd Parsed Data: %s\n", input_buff); *kd = atof(input_buff); - printf("**********End Parsing***************\n"); +// printf("**********End Parsing***************\n"); } void pid_callback(){