My final year project
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG SDFileSystem TS_DISCO_F746NG ResistiveTouchController Map CYS8218Controller MedianFilter
Revision 62:58e846621435, committed 2016-10-26
- Comitter:
- Generic
- Date:
- Wed Oct 26 10:40:54 2016 +0000
- Parent:
- 61:d16e5ad857ba
- Commit message:
- Firmware
Changed in this revision
--- a/CYS8218Controller.lib Wed Oct 19 22:13:09 2016 +0200 +++ b/CYS8218Controller.lib Wed Oct 26 10:40:54 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/Generic/code/CYS8218Controller/#062af0d57175 +http://developer.mbed.org/users/Generic/code/CYS8218Controller/#87b056f6d8ad
--- a/ResistiveTouchController.lib Wed Oct 19 22:13:09 2016 +0200 +++ b/ResistiveTouchController.lib Wed Oct 26 10:40:54 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/Generic/code/ResistiveTouchController/#a4ebeb3ba49c +https://developer.mbed.org/users/Generic/code/ResistiveTouchController/#140d6bff4860
--- a/Screens/AutomaticControlScreen.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/AutomaticControlScreen.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -8,7 +8,7 @@ _btStart(0, SCREEN_H-65, SCREEN_W, 30, "Start"), _btStop(0, SCREEN_H-65, SCREEN_W, 30, "Stop"), _btMore((SCREEN_W/2)-50, SCREEN_H-30, 100, 30, "More"), - _nlbTs( SCREEN_W/2, 26, "Cycle Time (us):%d", *Ts, Label::CENTER), + _nlbTs( SCREEN_W/2, 26, "Cycle Time (ms):%d", *Ts, Label::CENTER), _gXPos( 0, 40, SCREEN_W/2-1, 158, -170, 170, "X Position (mm)"), _gYPos( SCREEN_W/2+1, 40, SCREEN_W/2-1, 158, -136, 136, "Y Position (mm)") { @@ -104,7 +104,7 @@ _gXPos.Update(); _gYPos.Update(); - _nlbTs.Draw("Cycle time (us):%d",*_Ts); + _nlbTs.Draw("Cycle time (ms):%d",*_Ts); if( *_xSP ) {
--- a/Screens/AutomaticMoreScreen.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/AutomaticMoreScreen.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -4,8 +4,8 @@ Screen(), _lbTitle( SCREEN_W/2, 0, "More", Label::CENTER, Font24), _btBack(0,SCREEN_H-30,100,30,"Back"), - _btManualSP(0, 27, SCREEN_W/2-5, SCREEN_H-35-27, "Manual Tracking"), - _btSquare(SCREEN_W/2+5,27, SCREEN_W/2-5, SCREEN_H-35-27, "Square") + _btManualSP(0, 27, SCREEN_W/2-5, SCREEN_H-35-27, "Manual Tracking",Font20), + _btSquare(SCREEN_W/2+5,27, SCREEN_W/2-5, SCREEN_H-35-27, "4-Point Pattern",Font20) { _nextScreen = nextScreen; }
--- a/Screens/ManualControlScreen.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/ManualControlScreen.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -30,10 +30,10 @@ if( _btReset.Touched() ) { - _btReset.Draw(); _tpManual.Reset(); SetValues(); Thread::wait(200); + _btReset.Draw(); } if( _tpManual.Touched() )
--- a/Screens/ManualSetpointScreen.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/ManualSetpointScreen.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -7,8 +7,6 @@ _tpSetpoint( (SCREEN_W/2)-90 ,57, 180,180, -100.0, 100.0, -100.0 ,100.0), _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,"y (mm)=%.0f",*ySP), _btReset( SCREEN_W-100, SCREEN_H-30, 100, 30, "Reset") { _nextScreen = nextScreen; @@ -28,9 +26,7 @@ _tpSetpoint.Draw(); _btStop.Inactivate(); _btStart.Inactivate(); - _btStart.Draw(); - _nlbXSP.Draw(); - _nlbYSP.Draw(); + _btStart.Draw(); _btReset.Draw(); } @@ -48,8 +44,6 @@ *_ySP = -floor(_tpSetpoint.GetX()); *_xSP = -floor(_tpSetpoint.GetY()); - _nlbXSP.Draw("x (mm)=%.0f",*_xSP); - _nlbYSP.Draw("y (mm)=%.0f",*_ySP); } if( _btReset.Touched() )
--- a/Screens/ManualSetpointScreen.hpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/ManualSetpointScreen.hpp Wed Oct 26 10:40:54 2016 +0000 @@ -17,8 +17,6 @@ Trackpad _tpSetpoint; Button _btStart; Button _btStop; - NumericLabel<float> _nlbXSP; - NumericLabel<float> _nlbYSP; Button _btReset; float *_xSP;
--- a/Screens/SquareScreen.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/Screens/SquareScreen.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -2,7 +2,7 @@ SquareScreen::SquareScreen( int *nextScreen, float *xSP, float *ySP, int *ballOnPlate, bool *started, float *x, float *y) : Screen(), - _lbTitle( SCREEN_W/2, 0, "Manual Setpoint", Label::CENTER, Font24), + _lbTitle( SCREEN_W/2, 0, "4 Point Pattern", Label::CENTER, Font24), _btBack( 0, SCREEN_H-30, 100, 30, "Back"), _btReset( SCREEN_W-100, SCREEN_H-30, 100, 30, "Reset"), _cSquare( (SCREEN_W/2)-90 ,57, 180,180), @@ -130,6 +130,24 @@ DrawShape(); } + + if( _btReset.Touched() ) + { + _xPoints[0] = (SCREEN_W/2)-80; + _yPoints[0] = 67; + _xPoints[1] = (SCREEN_W/2)-80; + _yPoints[1] = 47+180; + _xPoints[2] = (SCREEN_W/2)+70; + _yPoints[2] = 47+180; + _xPoints[3] = (SCREEN_W/2)+70; + _yPoints[3] = 67; + _currentPoint = 0; + *_ySP = -_xMapper.Calculate((float)_xPoints[0]); + *_xSP = -_yMapper.Calculate((float)_yPoints[0]); + DrawShape(); + Thread::wait(200); + _btReset.Draw(); + } } void SquareScreen::DrawShape()
--- a/main.cpp Wed Oct 19 22:13:09 2016 +0200 +++ b/main.cpp Wed Oct 26 10:40:54 2016 +0000 @@ -47,11 +47,14 @@ //-- Controller Variables float P = 0.1; float I = 0; -float D = 10; -float Ts = 0.004; +float D = 9; +float Ts = 4; Timer cycleTimer; //----------------------- +float t[3][2]; +float d[3][2]; + //-- Sensors and Actuator objects ResistiveTouchController plate(A0,A1,A3,A4,A5); @@ -76,8 +79,6 @@ bool saved = false; -// TODO Delete these variables -Serial pc(USBTX,USBRX); int main() { @@ -121,6 +122,8 @@ if( nextScreen != currentScreen ) { started = false; + xSummation = 0; + ySummation = 0; Thread::wait(100); if( activeScreen != NULL) @@ -183,9 +186,16 @@ void Init() { - // TODO Read values from sd card + + d[0][0] = 921.6; + d[1][0] = 512; + d[2][0] = 102.4; + + d[0][1] = 512; + d[1][1] = 921.6; + d[2][1] = 102.4; + ImageFromSD splash("/sd/Splash.txt"); - pc.baud(57600); xMotor.SetZero(28.0); yMotor.SetZero(25.0); nextScreen = Screen::MAIN_MENU_SCREEN; @@ -203,7 +213,6 @@ if( saved) { - // TODO Save zero position on sd card xMotor.SetZero(zeroAlpha); yMotor.SetZero(-zeroBeta); zeroAlpha = 0; @@ -256,12 +265,11 @@ beta = ( beta > 10 ? 10 : (beta < -10 ? -10 : beta) ); xMotor.Set(alpha); - yMotor.Set(-beta); + yMotor.Set(beta); - if( Ts > 0) - Ts /= 1000; + float waitTime = Ts/1000.0; - while( cycleTimer.read() > Ts); + while( cycleTimer.read() < waitTime); cycleTimer.stop(); measuredTs = cycleTimer.read_ms(); @@ -287,12 +295,15 @@ { calTimer.start(); calHeldTime = calTimer.read(); + plate.Measure(); + + t[calPoint][0] = plate.RawX(); + t[calPoint][1] = plate.RawY(); if( calHeldTime >= 5 ) { while( plate.TouchDetected() ); - - //TODO Test calibration function + calPoint++; calTimer.stop(); calTimer.reset(); @@ -306,6 +317,7 @@ } else { + plate.Calibrate(t,d); calFinished = true; calPoint = 0; calStarted = false;