w

Dependencies:   mbed

Committer:
co838_ab981
Date:
Mon Aug 01 15:31:47 2016 +0000
Revision:
0:c0509139a295
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
co838_ab981 0:c0509139a295 1 /**
co838_ab981 0:c0509139a295 2 * @author Aaron Berk
co838_ab981 0:c0509139a295 3 *
co838_ab981 0:c0509139a295 4 * @section LICENSE
co838_ab981 0:c0509139a295 5 *
co838_ab981 0:c0509139a295 6 * Copyright (c) 2010 ARM Limited
co838_ab981 0:c0509139a295 7 *
co838_ab981 0:c0509139a295 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
co838_ab981 0:c0509139a295 9 * of this software and associated documentation files (the "Software"), to deal
co838_ab981 0:c0509139a295 10 * in the Software without restriction, including without limitation the rights
co838_ab981 0:c0509139a295 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
co838_ab981 0:c0509139a295 12 * copies of the Software, and to permit persons to whom the Software is
co838_ab981 0:c0509139a295 13 * furnished to do so, subject to the following conditions:
co838_ab981 0:c0509139a295 14 *
co838_ab981 0:c0509139a295 15 * The above copyright notice and this permission notice shall be included in
co838_ab981 0:c0509139a295 16 * all copies or substantial portions of the Software.
co838_ab981 0:c0509139a295 17 *
co838_ab981 0:c0509139a295 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
co838_ab981 0:c0509139a295 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
co838_ab981 0:c0509139a295 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
co838_ab981 0:c0509139a295 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
co838_ab981 0:c0509139a295 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
co838_ab981 0:c0509139a295 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
co838_ab981 0:c0509139a295 24 * THE SOFTWARE.
co838_ab981 0:c0509139a295 25 *
co838_ab981 0:c0509139a295 26 * @section DESCRIPTION
co838_ab981 0:c0509139a295 27 *
co838_ab981 0:c0509139a295 28 * A PID controller is a widely used feedback controller commonly found in
co838_ab981 0:c0509139a295 29 * industry.
co838_ab981 0:c0509139a295 30 *
co838_ab981 0:c0509139a295 31 * This library is a port of Brett Beauregard's Arduino PID library:
co838_ab981 0:c0509139a295 32 *
co838_ab981 0:c0509139a295 33 * http://www.arduino.cc/playground/Code/PIDLibrary
co838_ab981 0:c0509139a295 34 *
co838_ab981 0:c0509139a295 35 * The wikipedia article on PID controllers is a good place to start on
co838_ab981 0:c0509139a295 36 * understanding how they work:
co838_ab981 0:c0509139a295 37 *
co838_ab981 0:c0509139a295 38 * http://en.wikipedia.org/wiki/PID_controller
co838_ab981 0:c0509139a295 39 *
co838_ab981 0:c0509139a295 40 * For a clear and elegant explanation of how to implement and tune a
co838_ab981 0:c0509139a295 41 * controller, the controlguru website by Douglas J. Cooper (who also happened
co838_ab981 0:c0509139a295 42 * to be Brett's controls professor) is an excellent reference:
co838_ab981 0:c0509139a295 43 *
co838_ab981 0:c0509139a295 44 * http://www.controlguru.com/
co838_ab981 0:c0509139a295 45 */
co838_ab981 0:c0509139a295 46
co838_ab981 0:c0509139a295 47
co838_ab981 0:c0509139a295 48
co838_ab981 0:c0509139a295 49 /**
co838_ab981 0:c0509139a295 50 * Includes
co838_ab981 0:c0509139a295 51 */
co838_ab981 0:c0509139a295 52 #include "mbed.h"
co838_ab981 0:c0509139a295 53
co838_ab981 0:c0509139a295 54 Serial host (USBTX, USBRX);
co838_ab981 0:c0509139a295 55 DigitalIn btn(D2);
co838_ab981 0:c0509139a295 56 DigitalOut led(LED1);
co838_ab981 0:c0509139a295 57
co838_ab981 0:c0509139a295 58 /**
co838_ab981 0:c0509139a295 59 * Proportional-integral-derivative controller.
co838_ab981 0:c0509139a295 60 */
co838_ab981 0:c0509139a295 61 int main()
co838_ab981 0:c0509139a295 62 {
co838_ab981 0:c0509139a295 63 int i = 0;
co838_ab981 0:c0509139a295 64 host.baud (38400);
co838_ab981 0:c0509139a295 65 while (true) {
co838_ab981 0:c0509139a295 66 if (!btn) {
co838_ab981 0:c0509139a295 67 /// show msg in serial
co838_ab981 0:c0509139a295 68 host.printf ("Hello, count = %d \r\n", i);
co838_ab981 0:c0509139a295 69 i++;
co838_ab981 0:c0509139a295 70 }
co838_ab981 0:c0509139a295 71 else
co838_ab981 0:c0509139a295 72 host.printf ("Wait... \r\n");
co838_ab981 0:c0509139a295 73 led = btn;
co838_ab981 0:c0509139a295 74 wait(0.2f);
co838_ab981 0:c0509139a295 75 }
co838_ab981 0:c0509139a295 76 }