Danielle Kruijver / Mbed 2 deprecated Controll_SBT_main

Dependencies:   mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
DanielleKruijver
Date:
Fri Apr 12 09:55:53 2019 +0000
Parent:
0:3fbb3fa4ff64
Commit message:
Main SBT controllll

Changed in this revision

Daan_Test1_maxon.cpp Show annotated file Show diff for this revision Revisions of this file
Daan_Test1_maxon.h Show annotated file Show diff for this revision Revisions of this file
Force_to_wing_angle.cpp Show annotated file Show diff for this revision Revisions of this file
Move.cpp Show annotated file Show diff for this revision Revisions of this file
Move.h Show annotated file Show diff for this revision Revisions of this file
Sensor.cpp 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Daan_Test1_maxon.cpp	Fri Apr 12 09:55:53 2019 +0000
@@ -0,0 +1,260 @@
+#include "mbed.h"
+#include "Daan_Test1_maxon.h"
+#include "rtos.h"
+#define EPOS_DEBUG
+
+extern RawSerial pc;
+extern CAN can;
+
+
+
+/* -----------------------------------------------------------------------------
+You are going to open the function create_CAN_message. In this function, a 
+message is made that consists of the right NODE_ID, Length and the data. 
+This data comes from the data that is written in the .h file. 
+MessageOut is a CAN message that is part of the funtion create_CAN_msg and 
+will be filled with the right data. 
+can.write is a function from mbed and gives a 0 or 1 as output:
+    0 when nothing is written on the CAN line
+    1 when a message is written on the CAN line
+----------------------------------------------------------------------------- */
+CANMessage create_CAN_msg(int COB_ID, int LENGTH, char * DATA){             
+        CANMessage messageOut;                                                  
+ 
+        messageOut.format = CANStandard;                                        // standard or extended ID (can be skipped for standard)
+        messageOut.id = COB_ID;
+        messageOut.len = LENGTH;
+    
+        for ( int i = 0 ; i<LENGTH ; i++) {
+            messageOut.data[i] = DATA[i];                                       // repeat for each byte.
+        }
+    
+        if(can.write(messageOut)) {                                             //can.write() gives a 1 or 0 as output
+            #ifdef EPOS_DEBUG
+            pc.printf("sending message : ");                                    //output of can.write is 1: print something
+            for ( int ii = 0 ; ii<LENGTH ; ii++) {
+                pc.printf("%02x ",messageOut.data[ii]);                         
+            }
+            pc.printf("\r\n");
+            #endif
+            return 1;
+        } 
+        return messageOut;
+    }
+
+/* -----------------------------------------------------------------------------
+Make all messages that make use of the funtion CANMessage and return the 
+messages. 
+----------------------------------------------------------------------------- */     
+//CANMessage Latest_EPOS_msg(int NODE_ID){
+//    return EPOS_MSGS.msg_1;
+//    }
+    
+CANMessage EPOS::Shutdown(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Shutdown_Data);
+    }
+    
+CANMessage EPOS::SwitchOnAndEnable(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Switch_On_And_Enable_Data);
+    }
+        
+CANMessage EPOS::StatusWord(){
+    return create_CAN_msg(0x600 + NODE_ID,4,(char*)Status_Word_Data);
+    }
+    
+CANMessage EPOS::HomingMode(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Homing_Mode_Data);
+    }
+    
+CANMessage EPOS::HomingMethodPositive(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Homing_Method_Data_Positive);
+    }
+    
+CANMessage EPOS::HomingMethodNegative(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Homing_Method_Data_Negative);
+    }
+    
+CANMessage EPOS::StartHoming(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Start_Homing_Data);
+    }
+    
+CANMessage EPOS::ClearFault(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Clear_Fault_Data);
+    }
+    
+CANMessage EPOS::PositionMode(){
+    return create_CAN_msg(0x600+NODE_ID,8,(char*)Position_Mode_Data);
+    }
+    
+CANMessage EPOS::GoToPosition(float quartercircles){
+    
+    CANMessage msg;
+ 
+    msg.format = CANStandard;  // standard or extended ID (can be skipped for standard)
+    msg.id = 0x600 + NODE_ID;
+    msg.len = 8;
+    
+    /* -------------------------------------------------------------------------
+    Unions allow one portion of memory to be accessed as different data types. 
+    Its declaration and use is similar to the one of structures, but its 
+    functionality is totally different.
+    ------------------------------------------------------------------------- */
+    union {
+        int integer;
+        unsigned char byte[4];
+    } QC;
+    
+    QC.integer = quartercircles;
+    
+    /* -------------------------------------------------------------------------
+    The data that is sent to determine how many quartercircles have to be turned, 
+    consists of 4 bytes -> byte 0 = 0x23.
+    The Position Mode Setting Value has object 0x2062-00(byte1=0x62, byte2=0x20,
+    byte3=0x00).
+    The data is put in byte 4, 5, 6 and 7 and comes from the union Quaters_Union
+    ------------------------------------------------------------------------- */
+    msg.data[0] = 0x23;                                                         //0x23 as the first byte: 4 bytes in total sent
+    msg.data[1] = 0x62;                                                           
+    msg.data[2] = 0x20;
+    msg.data[3] = 0x00;
+    msg.data[4] = QC.byte[0];
+    msg.data[5] = QC.byte[1];
+    msg.data[6] = QC.byte[2];
+    msg.data[7] = QC.byte[3];   
+    
+    return msg;
+}
+    
+/* -----------------------------------------------------------------------------
+With the HOMING function you can home the motor. There are 2 differnt sorts of 
+homing: 
+    - 0xFD: -3: Current treshold positive speed (first in the direction of 
+    the motor and then to the end to go to the defined position).
+    - 0xFC: -4: Current treshold negative speed (this is what we are going 
+    to use in the real boat: first to the end of then back in the direction 
+    to the motor).
+For homing different steps have to be executed in the right order. Foo is used 
+as a counter to check if all the steps are executed. When can.write is 
+succesfull (when there is a message on the CAN line) foo increases with 1. To 
+check if all the messages are corrrect, we check it with pc.printf. In tera term
+you do not always get a message if homing is succesfull or failed because the 
+4th byte is already 0, but the 5th is 81 so you are not in the situations where
+the output is succes or failed. 
+    
+can.read? 
+----------------------------------------------------------------------------- */ 
+void EPOS::Homing(){
+    
+    int foo = 0;                                                              //foo is een teller, als can.write lukt komt er een 1 uit en als het faalt een 0. Uiteindelijk moet foo in dit geval dus 5 zijn. 
+    
+    foo += can.write(ClearFault());
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+    
+    foo += can.write(HomingMode());        
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+        
+    foo += can.write(HomingMethodPositive());
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+        
+    foo += can.write(Shutdown());      
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+
+    foo += can.write(SwitchOnAndEnable());
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+ 
+    foo += can.write(StartHoming());
+    Thread::wait(50);
+    pc.printf("Waarde van foo is: %i \r\n", foo);
+        
+    CANMessage msg;                                                         //msg nog vullen
+        
+    Thread::wait(250);
+         
+    for (int k=0; k<400; k++){                                              //while(iii<100){
+        #ifdef EPOS_DEBUG
+        pc.printf("Checking if homing NODE(%i) finished attempt :(%d) \r\n",NODE_ID,k);
+        #endif
+        
+        int sw=0;
+        sw +=can.write(StatusWord());
+        pc.printf("Waarde van sw is: %i \r\n", sw);
+            
+        Thread::wait(100);
+            
+        //msg = Latest_EPOS_msg(NODE_ID);                                         //the NODE_ID is only usefull when you have more messages, then you can use a switch on the basis of the node_id. 
+  
+        int teller = 0;
+        teller += can.read(msg);                                            //returns 0 if no message, 1 if message
+        pc.printf("Waarde van teller is: %i \r\n", teller);
+        
+          
+        //pc.printf("%02x \r\n",msg.data[1]);     //printen van de messages die je verstuurd
+        //pc.printf("%02x \r\n",msg.data[2]);     //printen van de messages die je verstuurd
+        //pc.printf("%02x \r\n",msg.data[4]);     //printen van de messages die je verstuurd
+        //pc.printf("%02x \r\n",msg.data[5]);     //printen van de messages die je verstuurd
+        
+            
+        if (msg.data[5] == 0x95){                                               //case home found
+            #ifdef EPOS_DEBUG
+            pc.printf("Homeing NODE(%i) Succesfull!! \r\n",NODE_ID);
+            #endif
+            //EPOS_HOME[NODE_ID-1]=1;
+            return;                                                           //optional because it is a void?
+        }
+        else if ( !(msg.data[4] == 0x37)){                                      //case homing failed
+            #ifdef EPOS_DEBUG
+            pc.printf("Homeing NODE(%i) FAILED!! \r\n",NODE_ID);
+            #endif
+            //EPOS_HOME[NODE_ID-1]=0;
+            //return;
+        }        
+        
+        Thread::wait(100);
+    }                                                                           //end for statement
+    
+    #ifdef EPOS_DEBUG
+    printf("\n Homing NODE(%i) timed out \r\n Resetting Device\r\n",NODE_ID);
+    #endif
+}    
+    //can.write(ReSet1());
+    //can.write(ReSet2());
+    //EPOS_HOME[NODE_ID-1]=0;
+    
+/* -----------------------------------------------------------------------------
+In this boolean funtion, the position is set and the axis is moving to the new 
+absolute position with the maximum acceleration and maximum velocity without a 
+particular traject. 
+With tel we built in a test to see if all the can messages are written on the 
+CAN line. 
+----------------------------------------------------------------------------- */
+
+void EPOS::StartPositionMode(){
+
+    int tel=0;
+    
+    tel += can.write(ClearFault());
+    Thread::wait(50);
+    pc.printf("Waarde van tel is: %i \r\n", tel);
+    
+    tel += can.write(PositionMode());
+    Thread::wait(50);
+    pc.printf("Waarde van tel is: %i \r\n", tel);
+        
+    tel += can.write(Shutdown());      
+    Thread::wait(50);
+    pc.printf("Waarde van tel is: %i \r\n", tel);
+
+    tel += can.write(SwitchOnAndEnable());
+    Thread::wait(50);
+    pc.printf("Waarde van tel is: %i \r\n", tel);
+           
+    //can.write(GoToPosition(quartercircles));                                             //send new position to the controllers
+    //Thread::wait(100);    
+}  
+                                                                                //end of StartPositionMode                                                                              
+                                                                                
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Daan_Test1_maxon.h	Fri Apr 12 09:55:53 2019 +0000
@@ -0,0 +1,103 @@
+#include "mbed.h"
+#include "DataStore.h"
+#ifndef EPOSS
+#define EPOSS
+
+
+/* -----------------------------------------------------------------------------
+EPOS commands that you need to home, you can find those in chapter 8.3 from the 
+application node. 
+----------------------------------------------------------------------------- */
+const char Shutdown_Data[8] = {0x2B,0x40,0x60,0x00,0x06,0x00,0x00,0x00};        //voorkomen dat je niet nog in een andere mode zit
+    
+const char Switch_On_And_Enable_Data[8] = {0x2B,0x40,0x60,0x00,0x0F,0x00,0x00,0x00}; //enable de motorcontroller (groene ledje constant aan)
+
+const char Homing_Mode_Data[8] = {0x2F,0x60,0x60,0x00,0x06,0x00,0x00,0x00};     //aan de 0x6060-00 geef je aan dat je nu gaat homen wat de waarde 06 heeft in de data bytes
+    
+const char Homing_Method_Data_Positive[8] = {0x2F,0x98,0x60,0x00,0xFD,0x00,0x00,0x00};  //bij de index 0x6098-00 geef je aan welke homing method je gaat gebruiken: 0xFD = -3 = current treshold positive speed
+
+const char Homing_Method_Data_Negative[8] = {0x2F,0x98,0x60,0x00,0xFC,0x00,0x00,0x00};  //bij de index 0x6098-00 geef je aan welke homing method je gaat gebruiken: 0xFC = -4 = current treshold negative speed
+    
+const char Start_Homing_Data[8] = {0x2B,0x40,0x60,0x00,0x1F,0x00,0x00,0x00}; //om te beginnen met homen geef je het controlword de waarde 0x001F om het homen te starten 
+
+const char Status_Word_Data[4] = {0x40,0x41,0x60,0x00};  //0x40, want ccs is 2: je upload iets van de controller om te kijken of het gelukt is. 
+
+const char Clear_Fault_Data[8] = {0x2B,0x40,0x60,0x00,0x80,0x00,0x00,0x00}; //Clear fault: 0x0080 versturen naar 0x6040-00    
+
+/* -----------------------------------------------------------------------------
+Additional EPOS commands that you need for going to a position, you can find 
+those in chapter 8.7 from the application node. 
+----------------------------------------------------------------------------- */
+const char Position_Mode_Data[8] = {0x2F,0x60,0x60,0x00,0xFF,0x00,0x00,0x00};
+
+/* -----------------------------------------------------------------------------
+Sends a CAN Message to the controller
+Returns 1 for succes. May be slow. a faster send message is build into Goto_Pos
+@param COB_ID
+@param Message length
+@param Data string
+----------------------------------------------------------------------------- */
+CANMessage create_CAN_msg(int COB_ID, int LENGTH, char * DATA);
+    
+//A struct in which msg_1 is saved
+//struct EPOS_MESSAGES {
+//    CANMessage msg_1;
+//};
+
+//CANMessage Latest_EPOS_msg(int NODE_ID);   
+ 
+// The EPOS class
+class EPOS{       
+        
+    public:
+    
+    //verbinding met main function
+    DataStore *m_FtoW_data;
+    
+    int NODE_ID;   // the CAN adress of this controller
+    
+    EPOS(int node_id){
+        NODE_ID=node_id;
+        };
+
+    /** puts the EPOS in shutdown state */
+    CANMessage Shutdown();
+    
+    /** puts the EPOS in Switchon state */
+    CANMessage SwitchOnAndEnable();
+     
+    /** Requests a statusword from the EPOS */
+    CANMessage StatusWord();
+    
+    /** puts the EPOS in homing mode */
+    CANMessage HomingMode();
+    
+    /** sets the homing method to current mode positive speed */
+    CANMessage HomingMethodPositive();
+    
+    /** sets the homing method to current mode positive speed */
+    CANMessage HomingMethodNegative();
+    
+    /** puts the EPOS in start homing state */
+    CANMessage StartHoming();
+     
+    /** Resets the fault condition on the EPOS */
+    CANMessage ClearFault();
+    
+    /** Function that defines a message with the right amount of quartercircles */
+    CANMessage GoToPosition(float quartercircles);
+    
+    /** Function that defines a message with the right amount of quartercircles */
+    CANMessage PositionMode();
+
+    /** Homes the EPOS with Current mode */
+    void Homing();
+    
+    /** With this function the axis is set in the position mode */
+    void StartPositionMode();
+    
+    /** With this function the axis is going to move */
+    void Move();
+};
+
+#endif
\ No newline at end of file
--- a/Force_to_wing_angle.cpp	Fri Apr 12 06:58:18 2019 +0000
+++ b/Force_to_wing_angle.cpp	Fri Apr 12 09:55:53 2019 +0000
@@ -10,7 +10,7 @@
 #include <iostream>
 #include <cmath>
 #include "math.h"
-Serial pc(USBTX,USBRX);
+
 control::ForceToWingAngle::ForceToWingAngle(){
 }
 
@@ -21,7 +21,7 @@
 }
 
 void control::ForceToWingAngle::MMA() {
-    pc.baud(115200);
+
     /* First we will start with the MMA. This is the motor mixing algorithm that 
      * divides the incoming forces from the 3 PID controllers in 3 different 
      * forces that the wings should deliver. The MMA consists of a matrix, that 
@@ -97,7 +97,6 @@
      output.Wing_left = left_angle_total - input2.Real_pitch + kZeroLiftAngle;
      output.Wing_right = right_angle_total - input2.Real_pitch + kZeroLiftAngle;
      output.Wing_back  = back_angle_total - input2.Real_pitch + kZeroLiftAngle;
-     pc.printf("%f,%f,%f,\n", output.Wing_left,output.Wing_right,output.Wing_back);
      
      m_FtoW_data->PutWingData(&output);
      return ;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Move.cpp	Fri Apr 12 09:55:53 2019 +0000
@@ -0,0 +1,34 @@
+
+#include "Move.h"
+#include "mbed.h"
+#include "rtos.h"
+
+extern RawSerial pc;
+extern CAN can;
+
+void MOVE::Move(){
+    EPOS epos1(1);
+    EPOS epos2(2);
+    EPOS epos4(4);
+    
+    float quartercircles_left = 0;
+    float quartercircles_right = 0;
+    float quartercircles_back = 0;
+    
+    DataStore::AngleWings alphas = m_FtoW_data -> GetWingData();
+    quartercircles_left = (-366889/alphas.Wing_left);             //366889 qc bij 1 rad hoekverdraaiing
+    quartercircles_right = (-366889/alphas.Wing_right);             //366889 qc bij 1 rad hoekverdraaiing
+    quartercircles_back = (-500000/alphas.Wing_back);               //NOG AANPASSEN!!!
+    
+    int teller = 0;
+    teller += can.write(epos1.GoToPosition(quartercircles_right));
+    pc.printf("Waarde van teller is: %i \r\n", teller);
+    wait(5);
+    teller += can.write(epos2.GoToPosition(quartercircles_left));
+    pc.printf("Waarde van teller is: %i \r\n", teller);
+    wait(5);
+    teller += can.write(epos4.GoToPosition(quartercircles_back));
+    pc.printf("Waarde van teller is: %i \r\n", teller);
+    wait(5);
+}
+      
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Move.h	Fri Apr 12 09:55:53 2019 +0000
@@ -0,0 +1,22 @@
+#ifndef _MOVE_H_
+#define _MOVE_H_
+#include "mbed.h"
+#include "rtos.h"
+#include <fstream>
+#include "DataStore.h"
+#include <iostream>
+#include <cmath>
+#include "math.h"
+#include "Daan_Test1_maxon.h"
+using namespace std;
+
+class MOVE
+{
+    public:
+        DataStore *m_FtoW_data;
+        virtual ~MOVE();
+        void Move( );
+
+};
+
+#endif
\ No newline at end of file
--- a/Sensor.cpp	Fri Apr 12 06:58:18 2019 +0000
+++ b/Sensor.cpp	Fri Apr 12 09:55:53 2019 +0000
@@ -29,11 +29,11 @@
     DataStore::sensor_struct sensor_waarde;
 
     // cout << "Called sensor::get_data(): " ;
-    sensor_waarde.pitch = rand() % 6; 
-    sensor_waarde.roll = rand() % 6; 
+    sensor_waarde.pitch = (rand() % 35)/100;        //0.35 rad = 20 graden 
+    sensor_waarde.roll = (rand() % 35)/100; 
     sensor_waarde.Z_accel = (rand() % 5 + 1)/10; 
-    sensor_waarde.angle_left = rand() % 6; 
-    sensor_waarde.angle_right= rand() % 6; 
+    sensor_waarde.angle_left = (rand() % 52)/100;   //0.52 rad = 30 graden
+    sensor_waarde.angle_right = (rand() % 52)/100; 
     m_ruwe_state_data->PutSensorData(&sensor_waarde);
     //printf("%f,%f,%f,%f,%f",sensor_waarde.pitch, sensor_waarde.roll, sensor_waarde.Z_accel, sensor_waarde.angle_left, sensor_waarde.angle_right);
 }
--- a/main.cpp	Fri Apr 12 06:58:18 2019 +0000
+++ b/main.cpp	Fri Apr 12 09:55:53 2019 +0000
@@ -14,21 +14,38 @@
 #include <cstdlib>
 #include <math.h>
 #include "mbed.h"
+#include "rtos.h"
 #include "Sensor.h"
 #include "Filtered_data.h"
 #include "DataStore.h"
 #include "ComplementaryFilter.h"
 #include "PID_caller.h"
 #include "Force_to_wing_angle.h"
+#include "Daan_Test1_maxon.h"
+#include "Move.h"
+
 //DigitalIn button(USER_BUTTON);
 DigitalOut led(LED2);
 using namespace std;
 
-/*
- * main.
- */
+RawSerial pc(SERIAL_TX,SERIAL_RX);
+CAN can(PB_8,PB_9);                                                             //NOG CHECKEN!!!
+
+EPOS epos1(1);
+EPOS epos2(2);
+EPOS epos4(4);
+
+Thread thread1;
+Thread thread2;
+Thread thread4;
+/* -----------------------------------------------------------------------------
+Main
+----------------------------------------------------------------------------- */
 int main(int argc, char** argv) {
-
+    pc.baud(921600);
+    can.frequency(250000);                                                      //NOG AANPASSEN IN EPOS COMPUTER PROGRAMMA ZODAT DE CAN FREQUENCY OP MOTORCONTROLLER OVEREENKOMT MET DIE VAN DE MASTER!! -> value 3
+    pc.printf("startup: \r\n"); 
+    
     // Maak de objecten.
     DataStore * ruwe_data = new DataStore();
     DataStore * filtered_data = new DataStore();
@@ -38,9 +55,9 @@
     Sensor * de_sensor = new Sensor();
     RuwDataFilter * filter = new RuwDataFilter();
     ComplementaryFilter * com_filter = new ComplementaryFilter();
-    PID_caller * PID =new PID_caller();
+    PID_caller * PID = new PID_caller();
     control::ForceToWingAngle * FtoW = new control::ForceToWingAngle();
-    
+    MOVE * moving = new MOVE();
 
     // De associaties, de verbindingen tussen de objecten.
     de_sensor->m_ruwe_state_data = ruwe_data;  // (1)
@@ -48,21 +65,59 @@
     filter->m_filtered_data = filtered_data;        // (3)
     com_filter->m_filtered_data = filtered_data; //(4)
     com_filter->m_complementary_data = complementary_data; //(5)
-    PID->m_complementary_data=complementary_data;  //(6)
-    PID->m_PID_data=pid_data; //(7)
-    FtoW->m_complementary_data=complementary_data; //(8)
-    FtoW->m_PID_data=pid_data; //(9)
-    FtoW->m_FtoW_data=FtoW_data; //(10)
+    PID->m_complementary_data = complementary_data;  //(6)
+    PID->m_PID_data = pid_data; //(7)
+    FtoW->m_complementary_data = complementary_data; //(8)
+    FtoW->m_PID_data = pid_data; //(9)
+    FtoW->m_FtoW_data = FtoW_data; //(10)
+    moving->m_FtoW_data = FtoW_data; //(11)
+    
+/* -----------------------------------------------------------------------------
+All three motors are going to home.
+----------------------------------------------------------------------------- */    
+    thread4.start(&epos4,&EPOS::Homing);
+    wait(15);
+    
+    thread2.start(&epos2,&EPOS::Homing);                                         //start de functie Homing
+    wait(15);   
+    //Thread::wait(1); 
+    
+    thread1.start(&epos1,&EPOS::Homing);                                         //start de functie Homing
+    wait(20);//Thread::wait(100); //was 100 
+    
+    thread4.join();
+    thread2.join();    
+    thread1.join();
+    wait(20);
+    
+/* -----------------------------------------------------------------------------
+All three motors are going in the startpositionmode.
+----------------------------------------------------------------------------- */    
+    thread1.start(&epos1,&EPOS::StartPositionMode);                                         
+    Thread::wait(1000);      //was 1000 
     
     
+    thread2.start(&epos2,&EPOS::StartPositionMode);                                         
+    Thread::wait(1000);      //was 1000 
+    
+    
+    thread4.start(&epos4,&EPOS::StartPositionMode);
+    Thread::wait(1000);
+    
+    thread4.join();
+    thread2.join();
+    thread1.join();
+    wait(20);
+        
     de_sensor->get_data();
     int N=0;
-    while (N < 100) {
+    while (N < 2) {
         led = !led;
         filter->FilterIt();
         com_filter->CalculateRealHeight();
         PID->PID_in();
         FtoW->MMA();
+        moving->Move();
         de_sensor->get_data();
     N=N+1;    
     }
@@ -77,6 +132,7 @@
     delete (PID);
     delete (com_filter);
     delete (FtoW);
+    delete (moving);
 
     return 0;
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Apr 12 09:55:53 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706