SHENG-HEN HSIEH / Mbed 2 deprecated VDU_2021

Dependencies:   mbed imu_driver

Files at this revision

API Documentation at this revision

Comitter:
open4416
Date:
Sun Nov 17 06:56:24 2019 +0000
Parent:
8:f8b1402c8f3c
Child:
10:0afeeb99f479
Commit message:
Add IMU lib initial release

Changed in this revision

imu_driver.lib 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
main.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/imu_driver.lib	Sun Nov 17 06:56:24 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Arithemetica/code/imu_driver/#9c07cc296819
--- a/main.cpp	Fri Nov 15 08:19:32 2019 +0000
+++ b/main.cpp	Sun Nov 17 06:56:24 2019 +0000
@@ -1,21 +1,23 @@
 #include "mbed.h"
 #include "main.h"
+#include "imu_driver.hpp"
 #define pi  3.14159265359f
 #define d2r 0.01745329252f
 #define dt  0.01f
 
 DigitalOut  Aux_Rly(PC_10,0);                       //Control aux relay, 1 active
-DigitalOut  Fault_Ind(PC_10,0);                     //Indicate fault bt flashing, 1 active
+DigitalOut  Fault_Ind(PC_12,0);                     //Indicate fault bt flashing, 1 active
 DigitalOut  LED(D13, 0);                            //Internal LED output, general purpose
 AnalogIn    AUX_1(PC_0);                            //Auxilaru analog sensor
 AnalogIn    AUX_2(PC_4);
 AnalogIn    AUX_3(PC_2);
 AnalogIn    AUX_4(PC_1);
 AnalogIn    SDn_sense(PB_0);                        //Shutdown circuit driving end detection
-CAN     can1(PB_8, PB_9, 1000000);                  //1Mbps, contain critical torque command message
-SPI     spi2(PB_15, PB_14, PB_13);                  //1Mbps, MOSI MISO SCLK, forIMU
-Serial  pc(USBTX, USBRX, 115200);
-Ticker  ticker1;                                    //100Hz task
+CAN         can1(PB_8, PB_9, 1000000);              //1Mbps, contain critical torque command message
+SPI         spi2(PB_15, PB_14, PB_13);              //1Mbps default, MOSI MISO SCLK, forIMU
+ImuDriver   <spi2, PA_13, PA_14, PA_15> imu;        //SPI instance, reset, data ready, slave select
+Serial      pc(USBTX, USBRX, 115200);
+Ticker      ticker1;                                //100Hz task
 CANMessage  can_msg_Rx;
 CANMessage  can_msg_Tx;
 
@@ -36,7 +38,7 @@
 int main()
 {
     //Init CAN network
-    CAN_init();
+    CAN_init();                 // Note now in Gloable test mode only for testing 2019/11/17
 
     //Start House keeping task
     printf("VDU start up, pend for module online\n");
@@ -47,10 +49,11 @@
         if (HST_EXFL == 1) {
             HST_EXFL = 0;
 
-            // Get IMU, Auxs
+            // Get IMU, Auxs, Max Temperature
+            Cooler();
             IMU_read();
             Aux_read();
-            Module_WD();                            // Module online watch dog
+            Module_WD();
 
             // Run state machine
             switch (VDU_STAT) {
@@ -208,7 +211,7 @@
         }
         // End of high speed loop
 
-        // Do low speed state reporting
+        // Do low speed state reporting 10 Hz
         if (LST_EXFL == 1) {
             LST_EXFL = 0;
             Cooler();
@@ -433,17 +436,17 @@
 
 void Tx_CLRerr_CAN1(void)
 {
-    Tx_Estop_CAN1();    //disable as default
-    RST_cmd = 0;        //clear out on shot
+    Tx_Estop_CAN1();        //disable as default
+    RST_cmd = 0;            //clear out on shot
 }
 
 void Tx_Estop_CAN1(void)
 {
-    RTD_cmd = 0;        //force disable
+    RTD_cmd = 0;            //force disable
     Tx_Tcmd_CAN1();
 }
 
-void Tx_Tcmd_CAN1(void)   // 100 Hz
+void Tx_Tcmd_CAN1(void)     // 100 Hz
 {
     int16_t tmp;
     tmp = (int16_t) (FL_Tcmd * 100.0f);
@@ -558,6 +561,7 @@
 
 void Module_WD(void)
 {
+    //Module online dissipitive indicator
     if (FL_online != 0) {
         FL_online -= 1;
     }
@@ -578,6 +582,8 @@
 void Cooler(void)
 {
     //Cooling auto control, unfinish 2019/11/15
+    Max_Tmotor = max_fval(FL_Tmotor, FR_Tmotor, RL_Tmotor, RR_Tmotor);
+    Max_Tmodule = max_fval(FL_Tmodule, FR_Tmodule, RL_Tmodule, RR_Tmodule);
     if(0) {
         Aux_Rly = 1;
     } else {
@@ -585,7 +591,7 @@
     }
 }
 
-int16_t max_val(int16_t i1, int16_t i2, int16_t i3, int16_t i4)
+int16_t max_uval(int16_t i1, int16_t i2, int16_t i3, int16_t i4)
 {
     int16_t max = i1;
     if(i2 > max) max = i2;
@@ -593,4 +599,13 @@
     if(i4 > max) max = i4;
     return max;
 }
+
+float max_fval(float i1, float i2, float i3, float i4)
+{
+    float max = i1;
+    if(i2 > max) max = i2;
+    if(i3 > max) max = i3;
+    if(i4 > max) max = i4;
+    return max;
+}
 //            pc.printf("SOC: %.2f\n", Module_Total*0.01f);
\ No newline at end of file
--- a/main.h	Fri Nov 15 08:19:32 2019 +0000
+++ b/main.h	Sun Nov 17 06:56:24 2019 +0000
@@ -66,10 +66,12 @@
 float FR_Tmotor = 0;
 float RL_Tmotor = 0;
 float RR_Tmotor = 0;
+float Max_Tmotor = 0;               // motor temperature degC, 10Hz recieving
 float FL_Tmodule = 0;               // inverter temperature degC, 10Hz recieving
 float FR_Tmodule = 0;
 float RL_Tmodule = 0;
 float RR_Tmodule = 0;
+float Max_Tmodule = 0;              // motor temperature degC, 10Hz recieving
 uint16_t FL_FLT_Run = 0;            // RUN fault code, 10Hz recieving
 uint16_t FR_FLT_Run = 0;
 uint16_t RL_FLT_Run = 0;
@@ -144,4 +146,5 @@
 void Tx_Tcmd_CAN1(void);        //Send out heart beat command
 void Tx_Qdrv_CAN1(void);        //Send out low speed heart beat for logging
 void CANpendTX(void);           //Helper function for CAN Tx
-int16_t max_val(int16_t i1, int16_t i2, int16_t i3, int16_t i4);
\ No newline at end of file
+int16_t max_uval(int16_t i1, int16_t i2, int16_t i3, int16_t i4);
+float max_fval(float i1, float i2, float i3, float i4);