Cornelius Bezuidenhout / Mbed OS Heiko

Dependencies:   BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG SDFileSystem TS_DISCO_F746NG ResistiveTouchController Map CYS8218Controller MedianFilter

Files at this revision

API Documentation at this revision

Comitter:
Kerneels Bezuidenhout
Date:
Mon Oct 03 00:31:36 2016 +0200
Parent:
21:aa3074b237e0
Child:
23:bab197887d5e
Commit message:
Added AutomaticSettingsScreen

Changed in this revision

Screens/AutomaticControlScreen.cpp Show annotated file Show diff for this revision Revisions of this file
Screens/AutomaticSettingsScreen.cpp Show annotated file Show diff for this revision Revisions of this file
Screens/AutomaticSettingsScreen.hpp Show annotated file Show diff for this revision Revisions of this file
Screens/ManualSetpointScreen.cpp Show annotated file Show diff for this revision Revisions of this file
Screens/ManualSetpointScreen.hpp Show annotated file Show diff for this revision Revisions of this file
Screens/Screen.hpp Show annotated file Show diff for this revision Revisions of this file
Screens/Screens.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Screens/AutomaticControlScreen.cpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/Screens/AutomaticControlScreen.cpp	Mon Oct 03 00:31:36 2016 +0200
@@ -65,17 +65,14 @@
   {
     if( !*_ballOnPlate )
       _btStart.Inactivate();
-    else
+    else if( _btStart.Touched() )
     {
-      if( _btStart.Touched() )
-      {
-        _btStart.Inactivate();
-        _btStart.Erase();
-        _btStop.Activate();
-        _btStop.Draw(0xFFFF0000);
-        Thread::wait(200);
-        *_started = true;
-      }
+      _btStart.Inactivate();
+      _btStart.Erase();
+      _btStop.Activate();
+      _btStop.Draw(0xFFFF0000);
+      Thread::wait(200);
+      *_started = true;
     }
   }
   else if( _btStop.IsActive() )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Screens/AutomaticSettingsScreen.cpp	Mon Oct 03 00:31:36 2016 +0200
@@ -0,0 +1,42 @@
+#include "AutomaticSettingsScreen.hpp"
+
+AutomaticSettingsScreen::AutomaticSettingsScreen() :
+  Screen(),
+  _lbTitle( SCREEN_W/2, 0, "Settings", Label::CENTER, Font24),
+  _btBack( 0, SCREEN_H-30, 100, 30, "Back"),
+  _nlbP(0,26, "P =%.3f", *P);
+  _btP(SCREEN_W/2, 26, 100, 30, "Change"),
+  _nlbI(0,61, "P =%.3f", *I);
+  _btI(SCREEN_W/2, 61, 100, 30, "Change"),
+  _nlbD(0,96, "P =%.3f", *D);
+  _btD(SCREEN_W/2, 96, 100, 30, "Change"),
+  _nlbTs(0,131, "P =%.3f", *Ts);
+  _btTs(SCREEN_W/2, , 131, 30, "Change")
+{
+  _nextScreen = nextScreen;
+  _P = P;
+  _I = I;
+  _D = D;
+  _Ts = Ts;
+}
+
+void AutomaticSettingsScreen::Draw()
+{
+  Clear();
+  _lbTitle.Draw();
+  _btBack.Draw();
+  _nlbP.Draw();
+  _btP.Draw();
+  _nlbI.Draw();
+  _btI.Draw();
+  _nlbD.Draw();
+  _btD.Draw();
+  _nlbTs.Draw();
+  _btTs.Draw();
+}
+
+void AutomaticSettingsScreen::Process()
+{
+  if( _btBack.Touched() )
+    *_nextScreen = AUTOMATIC_CONTROL_SCREEN;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Screens/AutomaticSettingsScreen.hpp	Mon Oct 03 00:31:36 2016 +0200
@@ -0,0 +1,30 @@
+#ifndef AUTOMATIC_SETTINGS_SCREEN_HPP
+#define AUTOMATIC_SETTINGS_SCREEN_HPP
+
+#include "Screen.hpp"
+
+class AutomaticSettingsScreen : public Screen
+{
+public:
+  AutomaticSettingsScreen(int *nextScreen, float *P, float *I, float *D, float *Ts);
+
+  void Draw();
+  void Process();
+
+private:
+  Label _lbTitle;
+  NumericLabel<float> _nlbP;
+  Button _btP;
+  NumericLabel<float> _nlbI;
+  Button _btI;
+  NumericLabel<float> _nlbD;
+  Button _btD;
+  NumericLabel<float> _nlbTs;
+  Button _btTs;
+
+  float *_P;
+  float *_I;
+  float *_D;
+  float *_Ts;
+};
+#endif
--- a/Screens/ManualSetpointScreen.cpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/Screens/ManualSetpointScreen.cpp	Mon Oct 03 00:31:36 2016 +0200
@@ -1,19 +1,23 @@
 #include "ManualSetpointScreen.hpp"
 
-ManualSetpointScreen::ManualSetpointScreen(int *nextScreen, float *xSP, float *ySP) :
+ManualSetpointScreen::ManualSetpointScreen(int *nextScreen, float *xSP, float *ySP, int *ballOnPlate, bool *started) :
   Screen(),
   _lbTitle( SCREEN_W/2, 0, "Manual Setpoint", Label::CENTER, Font24),
   _btBack( 0, SCREEN_H-30, 100, 30, "Back"),
   _tpSetpoint( (SCREEN_W/2)-90 ,57, 180,180, -120.0, 120.0, -136,136),
-  _btStart( 110, SCREEN_H-30, SCREEN_W-120, 30, "Start"),
-  _btStop( 110, SCREEN_H-30, SCREEN_W-120, 30, "Stop"),
+  _btStart( 110, SCREEN_H-30, SCREEN_W-220, 30, "Start"),
+  _btStop( 110, SCREEN_H-30, SCREEN_W-220, 30, "Stop"),
   _nlbXSP(0,26,"x (mm)=%.0f",*xSP),
-  _nlbYSP(0,40,"x (mm)=%.0f",*xSP),
+  _nlbYSP(0,40,"y (mm)=%.0f",*ySP),
   _btReset( SCREEN_W-100, SCREEN_H-30, 100, 30, "Reset")
 {
   _nextScreen = nextScreen;
   _xSP = xSP;
   _ySP = ySP;
+  *_xSP = 0;
+  *_ySP = 0;
+  _ballOnPlate = ballOnPlate;
+  _started = started;
 }
 
 void ManualSetpointScreen::Draw()
@@ -22,17 +26,76 @@
   _lbTitle.Draw();
   _btBack.Draw();
   _tpSetpoint.Draw();
+  _btStop.Inactivate();
+  _btStart.Inactivate();
   _btStart.Draw();
-  _btStop.Draw();
   _nlbXSP.Draw();
   _nlbYSP.Draw();
+  _btReset.Draw();
 }
 
 void ManualSetpointScreen::Process()
 {
   if( _btBack.Touched() )
   {
+    //TODO Stop control system if running
     *_nextScreen = AUTOMATIC_MORE_SCREEN;
   }
 
+  if( _tpSetpoint.Touched() )
+  {
+    _tpSetpoint.Update();
+
+    *_xSP = floor(_tpSetpoint.GetX());
+    *_ySP = floor(_tpSetpoint.GetY());
+    _nlbXSP.Draw("x (mm)=%.0f",*xSP),);
+    _nlbYSP.Draw("y (mm)=%.0f",*ySP),);
+  }
+
+  if( _btReset.Touched() )
+  {
+    _tpSetpoint.Reset();
+    _btReset.Draw();
+
+    *_xSP = floor(_tpSetpoint.GetX());
+    *_ySP = floor(_tpSetpoint.GetY());
+    _nlbXSP.Draw("x (mm)=%.0f",*xSP),);
+    _nlbYSP.Draw("y (mm)=%.0f",*ySP),);
+  }
+
+  if( _btStart.IsActive() )
+  {
+    if( !*_ballOnPlate )
+      _btStart.Inactivate();
+    else if( _btStart.Touched() )
+    {
+      _btStart.Inactivate();
+      _btStart.Erase();
+      _btStop.Activate();
+      _btStop.Draw(0xFFFF0000);
+      Thread::wait(200);
+      *_started = true;
+    }
+  }
+  else if( _btStop.IsActive() )
+  {
+    if( _btStop.Touched() )
+    {
+      _btStop.Inactivate();
+      _btStop.Erase();
+      _btStart.Activate();
+      _btStart.Draw(0xFF00FF00);
+      Thread::wait(200);
+      *_started = false;
+    }
+  }
+  else if( *_ballOnPlate )
+  {
+    if( !_btStop.IsActive() )
+    {
+      _btSta.Activate();
+      _btStart.Drwa(0xFF00FF00);
+    }
+  }
+
 }
--- a/Screens/ManualSetpointScreen.hpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/Screens/ManualSetpointScreen.hpp	Mon Oct 03 00:31:36 2016 +0200
@@ -6,7 +6,7 @@
 class ManualSetpointScreen : public Screen
 {
 public:
-  ManualSetpointScreen(int *nextScreen, float *xSP, float *ySP);
+  ManualSetpointScreen(int *nextScreen, float *xSP, float *ySP, int *ballOnPlate, bool *started);
 
   void Draw();
   void Process();
@@ -23,5 +23,8 @@
 
   float *_xSP;
   float *_ySP;
+  int *_ballOnPlate;
+  bool *_started;
+  
 };
 #endif
--- a/Screens/Screen.hpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/Screens/Screen.hpp	Mon Oct 03 00:31:36 2016 +0200
@@ -27,6 +27,7 @@
   static const int AUTOMATIC_CONTROL_SCREEN = 5;
   static const int AUTOMATIC_MORE_SCREEN = 6;
   static const int MANUAL_SETPOINT_SCREEN = 7;
+  static const int AUTOMATIC_SETTINS_SCREEN = 8;
 
   static const int SCREEN_W = 480;
   static const int SCREEN_H = 272;
--- a/Screens/Screens.hpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/Screens/Screens.hpp	Mon Oct 03 00:31:36 2016 +0200
@@ -8,5 +8,6 @@
 #include "AutomaticControlScreen.hpp"
 #include "AutomaticMoreScreen.hpp"
 #include "ManualSetpointScreen.hpp"
+#include "AutomaticSettingsScreen.hpp"
 
 #endif
--- a/main.cpp	Sun Oct 02 21:22:04 2016 +0000
+++ b/main.cpp	Mon Oct 03 00:31:36 2016 +0200
@@ -24,7 +24,12 @@
 float ySP = 50;
 float y = 0;
 
-int Ts = 0;
+float P = 0;
+float I = 0;
+float D = 0;
+float Ts = 0;
+
+int MeasuredTs = 0;
 
 bool started = true;
 
@@ -82,7 +87,7 @@
           activeScreen = new ManualControlScreen(&nextScreen, &alpha, &beta);
           break;
         case Screen::AUTOMATIC_CONTROL_SCREEN :
-          activeScreen = new AutomaticControlScreen(&nextScreen, &x, &y, &Ts, &started, &ballOnPlate, &xSP, &ySP);
+          activeScreen = new AutomaticControlScreen(&nextScreen, &x, &y, &measuredTs, &started, &ballOnPlate, &xSP, &ySP);
           break;
         case Screen::AUTOMATIC_MORE_SCREEN :
           activeScreen = new AutomaticMoreScreen(&nextScreen);
@@ -90,6 +95,8 @@
         case Screen::MANUAL_SETPOINT_SCREEN :
           activeScreen = new ManualSetpointScreen(&nextScreen, &xSP, &ySP);
           break;
+        case Screen::AUTOMATIC_SETTINS_SCREEN :
+          activeScreen = new AutomaticSettingsScreen(&nextScreen, &P, &I, &D, &Ts);
       }
 
       activeScreen->Draw();