
Version 16 Working
Dependencies: mbed mbed-rtos TextLCD
Revision 28:3193157ebb0c, committed 2019-03-11
- Comitter:
- thomasmorris
- Date:
- Mon Mar 11 14:19:26 2019 +0000
- Parent:
- 27:22d6fd88828e
- Commit message:
- Version 16 Working
Changed in this revision
diff -r 22d6fd88828e -r 3193157ebb0c Interface/Interface.cpp --- a/Interface/Interface.cpp Fri Mar 01 21:57:59 2019 +0000 +++ b/Interface/Interface.cpp Mon Mar 11 14:19:26 2019 +0000 @@ -212,65 +212,53 @@ } } } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void INTERFACE::Start_Stop()//Start / Stop Routine { - if(_System_Running != 2) - { - _System_Running = !_System_Running; - } - //System not running cases (START) - printf("Function is: %d, System is: %d\n",_Function,_System_Running); + /* + System Running = 0 Stop + System Running = 1 Running + System Running = 2 Paused + */ - //System Running cases (Unpause) - if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused + printf("Function is: %d, System is: %d\n",_Function,_System_Running);//Used for debugging + + //Start Cases for when the system is stopped/////////////////////////////////////////////////////////////////////////////////// + if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected { - _Twist_Stop_mutex.lock(); - _Twist_Stop = false; - _Twist_Stop_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); _Twist_Go_mutex.lock(); _Twist_Go = true;//toggle used for coiling and twisting and Running the code _Twist_Go_mutex.unlock(); - STEPPER_MOTOR_1.Unpause_Code(); - - if(_Function == 2)//Coiling - { - printf("Coiling Code unpaused\n"); - } - if(_Function == 3)//Twisiting - { - printf("Twisting Code unpaused\n"); - } - _System_Running = 0; - } - else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused + else if (_Function == 0 & _System_Running == 0) //Annealing selected { - _Anneal_Stop_mutex.lock(); - _Anneal_Stop = false; - _Anneal_Stop_mutex.unlock(); - printf("Annealing Code unpaused\n"); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); _Anneal_Go_mutex.lock(); _Anneal_Go = true;//toggle and Run the code _Anneal_Go_mutex.unlock(); - _System_Running = 0; } - else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run + else if (_Function == 1 & _System_Running == 0) //Testing selected { - _Test_Stop_mutex.lock(); - _Test_Stop = false; - _Test_Stop_mutex.unlock(); - printf("Testing Code unpaused\n"); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); + _Test_Go_mutex.lock(); _Test_Go = true;//toggle and run the code _Test_Go_mutex.unlock(); - _System_Running = 0; - } - //System Running cases (STOP) - else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be stopped + /////////////////////////////////////// + + //System Running cases run to pause the code + else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be paused { _Twist_Stop_mutex.lock(); _Twist_Stop = true; @@ -296,10 +284,10 @@ _Anneal_Stop_mutex.unlock(); printf("Annealing Code Paused\n"); _System_Running_mutex.lock(); - _System_Running = 2; + _System_Running = 2;//Pause code _System_Running_mutex.unlock(); } - else if (_Function == 1 & _System_Running == 1) //Testing selected to be stopped + else if (_Function == 1 & _System_Running == 1) //Testing selected to be paused { _Test_Stop_mutex.lock(); _Test_Stop = true; @@ -312,27 +300,62 @@ _Tendon_mutex.unlock(); _System_Running_mutex.lock(); - _System_Running = 2; + _System_Running = 2;//Pause code _System_Running_mutex.unlock(); } - //Start Cases - else if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected + + //////////////// + //System Paused cases run to unpause + else if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused { + _Twist_Stop_mutex.lock(); + _Twist_Stop = false; + _Twist_Stop_mutex.unlock(); + _Twist_Go_mutex.lock(); _Twist_Go = true;//toggle used for coiling and twisting and Running the code _Twist_Go_mutex.unlock(); + + STEPPER_MOTOR_1.Unpause_Code(); + + if(_Function == 2)//Coiling + { + printf("Coiling Code unpaused\n"); + } + if(_Function == 3)//Twisiting + { + printf("Twisting Code unpaused\n"); + } + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } - else if (_Function == 0 & _System_Running == 0) //Annealing selected + else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused { + _Anneal_Stop_mutex.lock(); + _Anneal_Stop = false; + _Anneal_Stop_mutex.unlock(); + printf("Annealing Code unpaused\n"); + _Anneal_Go_mutex.lock(); _Anneal_Go = true;//toggle and Run the code _Anneal_Go_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } - else if (_Function == 1 & _System_Running == 0) //Testing selected + else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run { + _Test_Stop_mutex.lock(); + _Test_Stop = false; + _Test_Stop_mutex.unlock(); + printf("Testing Code unpaused\n"); _Test_Go_mutex.lock(); _Test_Go = true;//toggle and run the code _Test_Go_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } } void INTERFACE::Function()//Function Routine used to increment through the three functions @@ -463,7 +486,7 @@ } void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed { - if (_Function == 2 || _Function == 3) //Turning Code + if (_Function == 2 || _Function == 3) //Turning Code for coiling and twisting { if (_Twist_Go == true) {
diff -r 22d6fd88828e -r 3193157ebb0c Interface/Interface.hpp --- a/Interface/Interface.hpp Fri Mar 01 21:57:59 2019 +0000 +++ b/Interface/Interface.hpp Mon Mar 11 14:19:26 2019 +0000 @@ -4,9 +4,9 @@ #include "mbed.h" #include "STEPPER_MOTOR.hpp" //Include this to use the stepper motor -#define Type_of_Rig 3 //Place 2 for coiling place 3 for twisting -#define Default_Coiling_Turns 20 -#define Default_Twisting_Turns 70 +#define Type_of_Rig 2 //Place 2 for coiling place 3 for twisting +#define Default_Coiling_Turns 80 +#define Default_Twisting_Turns 20 //Digital In for the button control to the interface static DigitalIn button_up(D8); //D8//Increment Button @@ -17,9 +17,9 @@ //Led Outputs //check the pin outs -static DigitalOut Led_Select_Left(D3); -static DigitalOut Led_Select_Right(D2); -static DigitalOut Led_Power(A2); +static DigitalOut Led_Select_Left(D2); +static DigitalOut Led_Select_Right(D3); +static DigitalOut Led_Power(A0); static STEPPER_MOTOR STEPPER_MOTOR_1(D15,D14,D13,D12); static PwmOut Tendon_Power(PE_8);
diff -r 22d6fd88828e -r 3193157ebb0c README.txt --- a/README.txt Fri Mar 01 21:57:59 2019 +0000 +++ b/README.txt Mon Mar 11 14:19:26 2019 +0000 @@ -1,4 +1,4 @@ -COILING RIG CODE V10: +COILING RIG CODE V14: This code is used to operate the Carbon Fibre actuator construction rigs. The buttons on this rig operate as follows: - Reset: @@ -20,22 +20,24 @@ Useful code information: - Function 0 = Turn - Function 1 = Anneal - Function 2 = Test + Function 0 = Anneal + Function 1 = Test + Function 2 = Coiling + Function 3 = Twisting + Function 4 = Custom Black :Reset : HardWired Red :Up : D8 Orange:Down : A1 Brown :Start/Stop: D9 - Green :Select : A3 - Yellow:Function : A4 + Yellow:Function : A3 + Green :Select : A4 //Led Outputs //check the pin outs. static DigitalOut Led_Select_Left(D2); static DigitalOut Led_Select_Right(D3); - static DigitalOut Led_Power(A3); + static DigitalOut Led_Power(A0); TextLCD lcd(D0,D1,D4,D5,D6,D7); // rs, e, d4-d7 TendonPower (PWM) pin is PE_8 one below d0
diff -r 22d6fd88828e -r 3193157ebb0c SETUP.hpp --- a/SETUP.hpp Fri Mar 01 21:57:59 2019 +0000 +++ b/SETUP.hpp Mon Mar 11 14:19:26 2019 +0000 @@ -11,7 +11,7 @@ #include "STEPPER_MOTOR.hpp" #include "Interface.hpp" -#define Debounce_Time 100//200 works fine +#define Debounce_Time 150//200 works fine INTERFACE INTERFACE; //Digital Outputs
diff -r 22d6fd88828e -r 3193157ebb0c Stepper_Motor/STEPPER_MOTOR.cpp --- a/Stepper_Motor/STEPPER_MOTOR.cpp Fri Mar 01 21:57:59 2019 +0000 +++ b/Stepper_Motor/STEPPER_MOTOR.cpp Mon Mar 11 14:19:26 2019 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" //Include the mbed libraries #include "STEPPER_MOTOR.hpp" //Include the header file, this acts like a series of forward declarations - +int loop_wait_time = 0; //Constructor STEPPER_MOTOR::STEPPER_MOTOR(PinName N1, PinName N2, PinName N3, PinName N4) : pin1(N1),pin2(N2),pin3(N3),pin4(N4) { @@ -24,13 +24,13 @@ } void STEPPER_MOTOR::Rotate_Steps(int Steps,int Function) { - if(Function == 2) + if(Function == 2)//Coiling { - loop_wait_time = 1; + loop_wait_time = 2; } else if(Function == 3) { - loop_wait_time = 2; + loop_wait_time = 2;//Twisting } Steps = Steps*50; //int correctionfactor;
diff -r 22d6fd88828e -r 3193157ebb0c Stepper_Motor/STEPPER_MOTOR.hpp --- a/Stepper_Motor/STEPPER_MOTOR.hpp Fri Mar 01 21:57:59 2019 +0000 +++ b/Stepper_Motor/STEPPER_MOTOR.hpp Mon Mar 11 14:19:26 2019 +0000 @@ -8,7 +8,7 @@ //Libraries and header includes #include "mbed.h" #include "rtos.h" -static int loop_wait_time = 0; +//static float loop_wait_time = 0; class STEPPER_MOTOR //This creates a class called Led { public:
diff -r 22d6fd88828e -r 3193157ebb0c main.cpp --- a/main.cpp Fri Mar 01 21:57:59 2019 +0000 +++ b/main.cpp Mon Mar 11 14:19:26 2019 +0000 @@ -113,24 +113,25 @@ Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs this debouce time might need to be longer up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Up Button Pressed\n");//Output data to the putty terminal - INTERFACE.Up(); //Run the interface up routine + pc.printf("System running value is: %d\n",INTERFACE.Get_System_Running()); + if(INTERFACE.Get_System_Running() == 0) + { + INTERFACE.Up(); //Run the interface up routine + } } } void down_thread_function() //Action if the down button is pressed decrement { while(1) { - /* - Thread::signal_wait(1); //Wait to be signaled by the down button interrupt - Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs - Thread::signal_wait(2); //Wait to be signaled by the down button interrupt - - */ Thread::signal_wait(1); //Wait to be signaled by the down button interrupt Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Down Button Pressed\n");//Output data to the putty terminal - INTERFACE.Down();//Run the interface down routine + if(INTERFACE.Get_System_Running() == 0) + { + INTERFACE.Down();//Run the interface down routine + } } } void start_stop_thread_function() //Action if the Start/Stop button is pressed @@ -142,7 +143,6 @@ start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("S/S Button Pressed\n");//Output data to the putty terminal INTERFACE.Start_Stop();//Run the interface start / stop routine - //Thread::wait(1000);//Button debounce to prevent multiple re-runs } } void Function_Selection_thread_function()//Action if the Function button is pressed @@ -153,8 +153,10 @@ Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Function Button Pressed\n");//Output data to the putty terminal - INTERFACE.Function();//Run the interface function routine - //Thread::wait(2000);//Button debounce to prevent multiple re-runs + if(INTERFACE.Get_System_Running() == 0) + { + INTERFACE.Function();//Run the interface function routine + } } } void Selection_thread_function()//Action if the Select button is pressed @@ -165,15 +167,14 @@ Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Select Button Pressed\n");//Output data to the putty terminal - INTERFACE.Select();//Run the interface selection routine - //Thread::wait(1000);//Button debounce to prevent multiple re-runs + if(INTERFACE.Get_System_Running() == 0) + { + INTERFACE.Select();//Run the interface selection routine + } } } int main() -{ - //Interrupt setters - - +{ lcd.printf("Ready Player\n"); lcd.printf(" One \n"); Thread::wait(1000);