Source: https://gist.github.com/bradley219/5373998 Include serial output

Dependencies:   mbed

Dependents:   DC_Stepper_Controller_Lib

Committer:
ftppr
Date:
Mon May 24 14:46:32 2021 +0000
Revision:
0:845ccddeede5
pid

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ftppr 0:845ccddeede5 1 /**
ftppr 0:845ccddeede5 2 * Copyright 2019 Bradley J. Snyder <snyder.bradleyj@gmail.com>
ftppr 0:845ccddeede5 3 *
ftppr 0:845ccddeede5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ftppr 0:845ccddeede5 5 * of this software and associated documentation files (the "Software"), to deal
ftppr 0:845ccddeede5 6 * in the Software without restriction, including without limitation the rights
ftppr 0:845ccddeede5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ftppr 0:845ccddeede5 8 * copies of the Software, and to permit persons to whom the Software is
ftppr 0:845ccddeede5 9 * furnished to do so, subject to the following conditions:
ftppr 0:845ccddeede5 10 *
ftppr 0:845ccddeede5 11 * The above copyright notice and this permission notice shall be included in
ftppr 0:845ccddeede5 12 * all copies or substantial portions of the Software.
ftppr 0:845ccddeede5 13 *
ftppr 0:845ccddeede5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ftppr 0:845ccddeede5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ftppr 0:845ccddeede5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ftppr 0:845ccddeede5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ftppr 0:845ccddeede5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ftppr 0:845ccddeede5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ftppr 0:845ccddeede5 20 * THE SOFTWARE.
ftppr 0:845ccddeede5 21 */
ftppr 0:845ccddeede5 22
ftppr 0:845ccddeede5 23 #include "pid.h"
ftppr 0:845ccddeede5 24 #include "mbed.h"
ftppr 0:845ccddeede5 25
ftppr 0:845ccddeede5 26 Serial myPC(USBTX, USBRX); // import serial for the UART attached toUSB
ftppr 0:845ccddeede5 27
ftppr 0:845ccddeede5 28 int main() {
ftppr 0:845ccddeede5 29 myPC.printf("Welcome to PID Test \n\r");
ftppr 0:845ccddeede5 30 PID pid = PID(0.1, 100, -100, 0.1, 0.01, 0.5);
ftppr 0:845ccddeede5 31
ftppr 0:845ccddeede5 32 double val = 20;
ftppr 0:845ccddeede5 33 for (int i = 0; i < 100; i++) {
ftppr 0:845ccddeede5 34 double inc = pid.calculate(0, val);
ftppr 0:845ccddeede5 35 printf("val:% 7.3f inc:% 7.3f\n", val, inc);
ftppr 0:845ccddeede5 36 myPC.printf("val:% 7.3f inc:% 7.3f\n", val, inc);
ftppr 0:845ccddeede5 37 val += inc;
ftppr 0:845ccddeede5 38 }
ftppr 0:845ccddeede5 39
ftppr 0:845ccddeede5 40 return 0;
ftppr 0:845ccddeede5 41 }