]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/commitdiff
SW repair for 'IRC malfunction'
authorMartin Prudek <prudemar@fel.cvut.cz>
Sun, 4 Oct 2015 14:11:17 +0000 (16:11 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Sun, 4 Oct 2015 14:11:17 +0000 (16:11 +0200)
pmsm-control/test_sw/Makefile
pmsm-control/test_sw/cmd_proc.c
pmsm-control/test_sw/comp.c
pmsm-control/test_sw/controllers.h
pmsm-control/test_sw/main_pmsm.c
pmsm-control/test_sw/pmsm_state.h

index 73aeb4a897f8af52904a54b6ef10446e10cf4ee6..7fa17f2cbc357a13f13fd939fce25ee0c7845cc8 100644 (file)
@@ -1,5 +1,8 @@
 #author Martin Prudek
 #sestavuje klienta a server pro ovladani DC motoru pomoci raspberry Pi
 #author Martin Prudek
 #sestavuje klienta a server pro ovladani DC motoru pomoci raspberry Pi
+clean:
+       rm -f ./*.o
+       rm -f ./dc_pos_hmod/*.o
 all:
        echo "scp server client_rt client_wirpi"
 
 all:
        echo "scp server client_rt client_wirpi"
 
index f1636025c26a2c910d3621a11a2e47eee23b8382..2c5fdbae1d146a866483ad139471e596a2f5742d 100644 (file)
@@ -10,7 +10,7 @@
  * referencnich informaci z jineho zarizeni po protokolu
  * UDP. Jde zatim jen o testovaci rezim
  */
  * referencnich informaci z jineho zarizeni po protokolu
  * UDP. Jde zatim jen o testovaci rezim
  */
-#define UDP_CAPABLE_X
+#define UDP_CAPABLE
 
 #ifdef UDP_CAPABLE
 #include "udp_cli.h"
 
 #ifdef UDP_CAPABLE
 #include "udp_cli.h"
index 764726acc4ae46c09a1dc2848e1447517988a009..94274815f08a2c2e345fddb7b7dc379eb29f8faf 100644 (file)
@@ -8,6 +8,18 @@
 #include "pmsm_state.h"
 #include "rp_spi.h"
 
 #include "pmsm_state.h"
 #include "rp_spi.h"
 
+#include <stdio.h>
+#include <stdlib.h>
+
+int transitions[6][6]={
+                    {  0,  0,881,  0,730,  0},
+                    {  0,  0, 50,  0,  0,230},
+                    {881, 50,  0,  0,  0,  0},
+                    {  0,  0,  0,  0,550,380},
+                    {730,  0,  0,550,  0,  0},
+                    {  0,230,  0,380,  0,  0}
+                   };
+
 /**
  * \brief
  * Substact initial position.
 /**
  * \brief
  * Substact initial position.
@@ -32,6 +44,41 @@ uint16_t mult_cap(int32_t s,int d){
        return res;
 }
 
        return res;
 }
 
+/**
+ * \brief
+ * Attempt to resolve fail-state in case of irc cable malfunction.
+ *
+ * Pri prechodu mezi haly je pocitan rozdil aktualni a predpokladane
+ * vzdalenosti od indexu. Pokud prekroci MAX_DIFF, je prepnuto na
+ * komutaci jen pomoci halu.
+ */
+#define MAX_DIFF 90
+void repairPositionErr(struct rpi_state* this){
+       int new;
+       int old;
+       int trans;
+       /* doslo k prechodu mezi haly */
+       if (this->h1_old != this->spi_dat->hal1 ||
+           this->h2_old != this->spi_dat->hal2 ||
+           this->h3_old != this->spi_dat->hal3)
+       {
+               new=this->spi_dat->hal1*4+this->spi_dat->hal2*2+this->spi_dat->hal3;
+               old=this->h1_old*4+this->h2_old*2+this->h3_old;
+               trans = transitions[new-1][old-1]; /*predpokladana pozice */
+
+               /*pozice jsou v rozsahu 0-999*/
+               if (abs(this->index_dist-trans)>MAX_DIFF &&
+                   abs(this->index_dist-trans-1000)>MAX_DIFF){
+                       setIndexLost(this);
+               }
+
+               /*nakonec preulozme stare hodnoty*/
+               this->h1_old = this->spi_dat->hal1;
+               this->h2_old = this->spi_dat->hal2;
+               this->h3_old = this->spi_dat->hal3;
+       }
+
+}
 
 /**
  * \brief
 
 /**
  * \brief
@@ -89,6 +136,9 @@ void comIndDist(struct rpi_state* this){
        }
 
        this->index_dist = dist;
        }
 
        this->index_dist = dist;
+
+       repairPositionErr(this);
+
        return;
 
        index_lost:
        return;
 
        index_lost:
index 5b241489317a950b0e471ed72d983fc8aa924f6a..e914a1d722248b22ecb05c2dce145f0a5b16b736 100644 (file)
@@ -18,7 +18,9 @@
 /*     Hodnoty upraveny podle skutecnych vysledku      */
 /*     P=0.8   I=0.01                                  */
 
 /*     Hodnoty upraveny podle skutecnych vysledku      */
 /*     P=0.8   I=0.01                                  */
 
-#define PID_P_S                0.16            /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
+/* PID_P_S             0.16 */
+
+#define PID_P_S                0.08            /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
 #define PID_I_S                0.0134
 
 /**
 #define PID_I_S                0.0134
 
 /**
index 6f3c670777651a98ccfe8ab41755c8fc12c0a888..2f4731f8223e0247d7323b8760f070744c7b0f61 100644 (file)
@@ -149,6 +149,7 @@ void * control_loop(void* param){
                        }else{ /*index je v poradku*/
                                comIndDist(&rps);               /*vypocet vzdalenosti indexu*/
                        }
                        }else{ /*index je v poradku*/
                                comIndDist(&rps);               /*vypocet vzdalenosti indexu*/
                        }
+                       last_index=data.index_position;         /*preulozime stary index */
 
                        /* pocitame sirku plneni podle potreb rizeni*/
                        rps.main_controller(&rps);
 
                        /* pocitame sirku plneni podle potreb rizeni*/
                        rps.main_controller(&rps);
index 6fc77f475f47e20db4ca339ea3dc06bfe0ec5038..47401d8f9e4d7eb9e169fcceb7c7342ad3537054 100644 (file)
@@ -51,6 +51,8 @@ struct rpi_state{
        void (*main_controller)(struct rpi_state*);     /* primarni regulator */
 
        char error;                     /* detekce chyboveho stavu */
        void (*main_controller)(struct rpi_state*);     /* primarni regulator */
 
        char error;                     /* detekce chyboveho stavu */
+
+       int8_t h1_old,h2_old,h3_old;    /* stare hodnoty hallu */
 };
 
 /**
 };
 
 /**