Template for group 4

Dependencies:   mbed

Fork of RT2_P3_students by RT2_P3_students

Revision:
0:78ca29b4c49e
Child:
1:a30512c3ac73
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 03 08:47:41 2018 +0000
@@ -0,0 +1,96 @@
+#include "mbed.h"
+#include "math.h"
+//------------------------------------------
+#define PI 3.1415927f
+//------------------------------------------
+#include "EncoderCounter.h"
+#include "DiffCounter.h"
+#include "IIR_filter.h"
+#include "LinearCharacteristics.h"
+#include "PI_Cntrl.h"
+/* Cuboid balance on one edge on Nucleo F446RE
+
+ **** IMPORTANT: use ..\Labormodelle\RT-MOD054 - Würfel\Escon_Parameter_4nucleo.edc 
+                 settings for Maxon ESCON controller (upload via ESCON Studio) ****
+hardware Connections:
+ 
+ CN7                    CN10
+  :                         :
+  :                         :
+ ..                        ..
+ ..                        ..                  15.
+ ..    AOUT i_des on (PA_5)o.
+ ..                        ..
+ ..                        ..
+ ..               ENC CH A o.
+ o. GND                    ..                  10.
+ o. ENC CH B               ..
+ ..                        ..
+ ..                        ..
+ .o AIN acx (PA_0)         ..
+ .o AIN acy (PA_1)         ..                  5.
+ .o AIN Gyro(PA_4)         .o Analog GND
+ ..                        ..
+ ..                        ..
+ ..                        ..                  1.
+ ----------------------------
+ CN7               CN10
+ */
+Serial pc(SERIAL_TX, SERIAL_RX);        // serial connection via USB - programmer
+InterruptIn button(USER_BUTTON);        // User Button, short presses: reduce speed, long presses: increase speed
+AnalogIn ax(PA_0);                      // Analog IN (acc x) on PA_0
+AnalogIn ay(PA_1);                      // Analog IN (acc y) on PA_1
+AnalogIn gz(PA_4);                      // Analog IN (gyr z) on PA_4
+AnalogOut out(PA_5);                    // Analog OUT on PA_5   1.6 V -> 0A 3.2A -> 2A (see ESCON)
+float out_value = 1.6f;                 // set voltage on 1.6 V (0 A current)
+float w_soll = 10.0f;                   // desired velocity
+//------------------------------------------
+// ... here define variables like gains etc.
+//------------------------------------------
+
+//------------------------------------------
+Ticker  ControllerLoopTimer;            // interrupt for control loop
+EncoderCounter counter1(PB_6, PB_7);    // initialize counter on PB_6 and PB_7
+DiffCounter diff(0.01,Ts);              // discrete differentiate, based on encoder data
+//------------------------------------------
+// ... here define instantiate classes
+//------------------------------------------
+
+// ... define some linear characteristics -----------------------------------------
+
+// ----- User defined functions -----------
+void updateControllers(void);   // speed controller loop (via interrupt)
+// ------ END User defined functions ------
+
+//******************************************************************************
+//---------- main loop -------------
+//******************************************************************************
+int main()
+{
+    //attach controller loop to timer interrupt
+    pc.baud(2000000);   // for serial comm.
+    counter1.reset();   // encoder reset
+    diff.reset(0.0f,0.0f);
+    ControllerLoopTimer.attach(&updateControllers, Ts); //Assume Fs = ...;
+}
+//******************************************************************************
+//---------- control loop (called via interrupt) -------------
+//******************************************************************************
+void updateControllers(void){
+    short counts = counter1;            // get counts from Encoder
+    float vel = diff(counts);           // motor velocity 
+    
+    // ... your code 
+    
+    if(++k >= 199){
+        k = 0;
+        pc.printf("omega_soll=%3.2f omega=%3.2f \r\n",w_soll,vel);
+    }
+}
+//******************************************************************************
+//********** User functions like buttens handle etc. **************
+//******************************************************************************
+// pressed button
+//******************************************************************************
+
+//...
\ No newline at end of file