Messa in campo 4 file - 26/06/2020 Francia

Dependencies:   mbed X_NUCLEO_IHM03A1_for

Fork of FORIGO_Modula_V7_3_VdcStep_maggio2020 by Francesco Pistone

Committer:
nerit
Date:
Mon May 20 07:51:35 2019 +0000
Revision:
28:0534c86365ec
Parent:
24:2b5e749e26b2
Child:
29:25a875d09817
Modificato il calcolo per la risincronizzazione del tamburo in rallentamento  per evitare il calcolo di velocita negative (condizione impossibile). Il valore minimo, se negativo viene forzato a 0.0xxxf. DA VERIFICARE.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nerit 3:a469bbd294b5 1 /*
nerit 3:a469bbd294b5 2 variabili generali di programma e set iniziali
nerit 3:a469bbd294b5 3 */
nerit 3:a469bbd294b5 4
nerit 3:a469bbd294b5 5 // SET INIZIALI DI MACCHINA
nerit 3:a469bbd294b5 6 bool canDataCheckEnable=false; // a true per attivare il controllo del quinconce anche con dati CAN
nerit 24:2b5e749e26b2 7 int speedFromPick = 1; // definisce se il controllo di velocità della ruota di semina è gestita dai becchi (set a 1) o dai fori sul disco (set a 0)
nerit 8:310f9e4eac7b 8 bool encoder=true; // true quando montato motore DC con encoder incorporato
nerit 3:a469bbd294b5 9 // NOTA: SE ENCODER=TRUE ALLORA SPEEDFROMPICK DEVE ESSERE MESSO A 0
nerit 3:a469bbd294b5 10 int tamburoStandard=1; // a 1 per tamburo parallelo alla ruota di semina, a 0 per zucca
nerit 3:a469bbd294b5 11 int cambiaStep=0;
nerit 3:a469bbd294b5 12
nerit 3:a469bbd294b5 13 bool tankLevelEnable = false;
nerit 3:a469bbd294b5 14 bool seedSensorEnable=false;
nerit 28:0534c86365ec 15 bool drumSelect=true; /// forzato a true per Germania
nerit 3:a469bbd294b5 16 bool currentCheckEnable=false;
nerit 3:a469bbd294b5 17 uint8_t cellsCountSet=1;
nerit 28:0534c86365ec 18 //int aspettareSincro=0;
nerit 28:0534c86365ec 19 //int tbFermo=0;
nerit 3:a469bbd294b5 20
nerit 3:a469bbd294b5 21 // VARIABILI DI PROGRAMMA
nerit 3:a469bbd294b5 22 int zeroRequestBuf=0;
nerit 3:a469bbd294b5 23 int runRequestBuf=0;
nerit 3:a469bbd294b5 24
nerit 3:a469bbd294b5 25 // define cycle variable related to the external command
nerit 3:a469bbd294b5 26 int oldTractorSpeedRead=0;
nerit 3:a469bbd294b5 27 int startCycle=0; // activate motors and functions
nerit 3:a469bbd294b5 28 int enableCycle=0; // enable regular cycle
nerit 3:a469bbd294b5 29 int zeroCycle=0; // azzeramento motori richiesto
nerit 3:a469bbd294b5 30 int OldStartCycle=0; // use for triggering command change
nerit 3:a469bbd294b5 31 int OldEnableCycle=0;
nerit 3:a469bbd294b5 32 int oldZeroCycle=0; // memoria azzeramento motori su richiesta
nerit 3:a469bbd294b5 33 int zeroCycleEnd=0; // ciclo di azzeramento completato
nerit 3:a469bbd294b5 34 int zeroTrigger=0;
nerit 3:a469bbd294b5 35 int TBzeroPinInput=0; // segnale invertito micro tamburo
nerit 3:a469bbd294b5 36 int seedWheelZeroPinInput=0; // segnale invertito sensore ruota di semina
nerit 3:a469bbd294b5 37 int SD_faultA=0;
nerit 3:a469bbd294b5 38 int SD_faultB=0;
nerit 3:a469bbd294b5 39 int DC_brake=1; // comando gestione frenatura motore DC
nerit 3:a469bbd294b5 40 int DC_forward=1; // comando gestione direzione motore DC
nerit 3:a469bbd294b5 41
nerit 3:a469bbd294b5 42 int oldFaseLavoro=0;
nerit 3:a469bbd294b5 43
nerit 3:a469bbd294b5 44 // define logic internal variables
nerit 3:a469bbd294b5 45 double tractorSpeed_MtS_timed=0.0f; // tractor speed calculated from pulse interval time
nerit 10:9e70619e97ab 46 double oldLocalTractorSpeed=0.0f;
nerit 3:a469bbd294b5 47 double speedForDisplay[5]={0.0f,0.0f,0.0f,0.0f,0.0f};
nerit 3:a469bbd294b5 48 double totalSpeed=0.0f;
nerit 3:a469bbd294b5 49 double OLDpulseSpeedInterval=1000.01f; // tractor speed calculated from pulse interval time
nerit 3:a469bbd294b5 50 double pulseDistance=0.0f; // linear space between pulse
nerit 3:a469bbd294b5 51 double pulseDistanceCalc=0.0f;
nerit 3:a469bbd294b5 52 double speedPerimeter=0.0f; // perimeter of tractor speed wheel
nerit 3:a469bbd294b5 53 double seedPerimeter=0.0f; // perimeter of seed wheel
nerit 3:a469bbd294b5 54 double mediaSpeed[5]={0.0f,0.0f,0.0f,0.0f,0.0f};
nerit 3:a469bbd294b5 55 int pntMedia=0;
nerit 3:a469bbd294b5 56 int actualPulseReadTimer=0; // timer read at previous pulse
nerit 3:a469bbd294b5 57 double pulseSpeedInterval=0.0f; // delta time of pulse
nerit 3:a469bbd294b5 58 int lastPulseRead=0;
nerit 3:a469bbd294b5 59 int oldLastPulseRead=0;
nerit 3:a469bbd294b5 60 int pulseRised=0; // pulse from speed wheel occured. Define when is possible to determine speed of up down motor.
nerit 3:a469bbd294b5 61 int pulseRised1 = 0;
nerit 3:a469bbd294b5 62 int pulseRised2 = 0;
nerit 13:d1030d4e51a8 63 int dcEncoderCnt=0;
nerit 13:d1030d4e51a8 64 double seedWheelDcPulse=0.0f;
nerit 13:d1030d4e51a8 65 double frazioneImpulsi=0.0f;
nerit 3:a469bbd294b5 66
nerit 3:a469bbd294b5 67 double rapportoRuote = 0.0f;
nerit 3:a469bbd294b5 68 double TBrpm = 0.0f;
nerit 3:a469bbd294b5 69 double TBfrequency = 0.0f;
nerit 3:a469bbd294b5 70 double TBperiod = 0.0f;
nerit 3:a469bbd294b5 71 double oldPeriodoTB = 0.0f;
nerit 3:a469bbd294b5 72 int SDzeroCyclePulse=0;
nerit 3:a469bbd294b5 73 int TBzeroCyclePulse=0;
nerit 3:a469bbd294b5 74 int SDzeroed=0;
nerit 3:a469bbd294b5 75 int TBzeroed=0;
nerit 3:a469bbd294b5 76 int oldOnSDzero=0;
nerit 3:a469bbd294b5 77 int oldOnTBzero=0;
nerit 3:a469bbd294b5 78 int oldOffSDzero=0;
nerit 3:a469bbd294b5 79 int oldOffTBzero=0;
nerit 3:a469bbd294b5 80 int SDzeroPinTrig=0;
nerit 3:a469bbd294b5 81 int TBzeroPinTrig=0;
nerit 3:a469bbd294b5 82 int SDzeroDebounced=0;
nerit 3:a469bbd294b5 83 int SDrunZero=0;
nerit 3:a469bbd294b5 84 int TBrunZero=0;
nerit 3:a469bbd294b5 85 int syncroCheck=0;
nerit 3:a469bbd294b5 86 double memoStepTB=0.0f;
nerit 3:a469bbd294b5 87 double erroreSyncro=0.0f;
nerit 3:a469bbd294b5 88 double errorePercentuale=1.0f;
nerit 3:a469bbd294b5 89 int oldSeedWheelZeroPinInput=0;
nerit 3:a469bbd294b5 90 int oldTBzeroPinInput=0;
nerit 3:a469bbd294b5 91 int stopCicloTB = 0;
nerit 3:a469bbd294b5 92 int startCicloTB = 0;
nerit 3:a469bbd294b5 93 int cicloTbinCorso = 0;
nerit 3:a469bbd294b5 94 int beccoPronto =0;
nerit 3:a469bbd294b5 95 int memoIntraPick=0;
nerit 3:a469bbd294b5 96
nerit 3:a469bbd294b5 97 double realGiroSD = 0.0f;
nerit 3:a469bbd294b5 98 double tempoBecco = 0.0f;
nerit 3:a469bbd294b5 99 double frequenzaReale = 0.0f;
nerit 3:a469bbd294b5 100 double semiPeriodoReale = 0.0f;
nerit 3:a469bbd294b5 101 double tempoTraBecchi_mS = 0.0f;
nerit 3:a469bbd294b5 102 double tempoGiroSD = 0.0f;
nerit 3:a469bbd294b5 103
nerit 3:a469bbd294b5 104 // variable for speed and step calculation
nerit 3:a469bbd294b5 105 uint32_t prePosSD=0; // actual position of seed wheel (step of motor)
nerit 3:a469bbd294b5 106 uint32_t SDactualPosition=0; // actual position of seed wheel (step of motor)
nerit 3:a469bbd294b5 107 uint32_t TBactualPosition=0;
nerit 3:a469bbd294b5 108 uint32_t TBpassPosition=0;
nerit 3:a469bbd294b5 109 uint32_t TBoldPosition=0;
nerit 3:a469bbd294b5 110 uint32_t posForQuinc=0;
nerit 3:a469bbd294b5 111
nerit 3:a469bbd294b5 112 int cycleStopRequest=0; // when cycle end request the zero of SD and UD
nerit 3:a469bbd294b5 113
nerit 3:a469bbd294b5 114 double duty_DC=0.0f;
nerit 3:a469bbd294b5 115 double oldDuty_DC=0.0f;
nerit 3:a469bbd294b5 116
nerit 3:a469bbd294b5 117 double dcActualDuty = 0.0f; // valore di lavoro del duty cycle
nerit 3:a469bbd294b5 118 double olddcActualDuty = 0.0f; // valore di lavoro del duty cycle
nerit 3:a469bbd294b5 119 double correzione = 0.0f;
nerit 3:a469bbd294b5 120 double periodo =0.0f;
nerit 3:a469bbd294b5 121 double ePpos = 0.0f;
nerit 3:a469bbd294b5 122 int aspettaStart=1;
nerit 3:a469bbd294b5 123 int countCicli=0;
nerit 3:a469bbd294b5 124 uint32_t fase = 0;
nerit 14:e2b5efa06c41 125 double loLimitSpeed=0.01f;
nerit 14:e2b5efa06c41 126 double hiLimitSpeed=0.01f;
nerit 3:a469bbd294b5 127
nerit 3:a469bbd294b5 128 int clocca=0;
nerit 3:a469bbd294b5 129 int enableSpeed=0;
nerit 3:a469bbd294b5 130 double speedOfSeedWheel =0.0f;
nerit 3:a469bbd294b5 131 int lowSpeed = 0;
nerit 3:a469bbd294b5 132 double valore=0.0f;
nerit 3:a469bbd294b5 133 //char val1[8]={0,0,0,0,0,0,0,0};
nerit 3:a469bbd294b5 134
nerit 3:a469bbd294b5 135 uint8_t enableSimula=0;
nerit 3:a469bbd294b5 136 uint8_t speedSimula=0;
nerit 3:a469bbd294b5 137 uint8_t avviaSimula=0;
nerit 3:a469bbd294b5 138 double oldSimulaSpeed=0.0f;
nerit 3:a469bbd294b5 139 int selezionato =0;
nerit 3:a469bbd294b5 140 int simOk=0;
nerit 20:4a400a4cc419 141 uint8_t speedStepp=0;
nerit 20:4a400a4cc419 142 int simStepper=0;
nerit 20:4a400a4cc419 143 bool oldSimStepper=false;
nerit 20:4a400a4cc419 144 double simStepSpeed=0.0f;
nerit 20:4a400a4cc419 145 double oldSimStepSpeed=0.1f;
nerit 3:a469bbd294b5 146
nerit 12:b0fc1d313813 147 int correggiCorrente=0;
nerit 3:a469bbd294b5 148 float SD_CurrentAnalog=0.0f; // valore di corrente sull'ingresso
nerit 3:a469bbd294b5 149 float SD_CurrentScaled=0.0f; // valore di corrente convertito in scala
nerit 3:a469bbd294b5 150 float SD_CurrentFactor=40.0f; // fattore di scala sensore 40mV/A
nerit 3:a469bbd294b5 151 float SD_CurrentPeak=0.0f; // valore massimo corrente
nerit 3:a469bbd294b5 152 float SD_CurrentMid=0.0f; // valore medio corrente
nerit 3:a469bbd294b5 153 float SD_CurrentLast=0.0f; // valore precedente corrente
nerit 3:a469bbd294b5 154 float SD_CurrentStart=0.0f; // valore a vuoto corrente (circa il 50% della tensione di alimentazione del sensore)
nerit 3:a469bbd294b5 155 bool reduceCurrent=false;
nerit 3:a469bbd294b5 156 bool incrementCurrent=false;
nerit 3:a469bbd294b5 157 double boostDcOut=0.0f;
nerit 3:a469bbd294b5 158
nerit 3:a469bbd294b5 159 float SD_analogMatrix[21]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
nerit 3:a469bbd294b5 160 int SD_analogIndex[11]={0,0,0,0,0,0,0,0,0,0};
nerit 3:a469bbd294b5 161 int frenata=0;
nerit 3:a469bbd294b5 162 int accensione=1;
nerit 3:a469bbd294b5 163 double SDsectorStep =0.0f;
nerit 3:a469bbd294b5 164 double TBsectorStep = 0.0f;
nerit 3:a469bbd294b5 165 double KcorT = 0.0f;
nerit 3:a469bbd294b5 166
nerit 3:a469bbd294b5 167 int trigSD=0;
nerit 3:a469bbd294b5 168 int trigTB=0;
nerit 3:a469bbd294b5 169 int inhibit=0;
nerit 3:a469bbd294b5 170 int trigCicli=0;
nerit 3:a469bbd294b5 171 int avvicinamento=0;
nerit 3:a469bbd294b5 172 int lowSpeedRequired=0;
nerit 3:a469bbd294b5 173
nerit 3:a469bbd294b5 174 uint8_t alarmHighRegister=0x00;
nerit 3:a469bbd294b5 175 uint8_t alarmLowRegister=0x00;
nerit 3:a469bbd294b5 176 double TBgiroStep=0.0f;
nerit 3:a469bbd294b5 177 int firstStart=1;
nerit 3:a469bbd294b5 178 int noSDzeroRequest=0;
nerit 3:a469bbd294b5 179 int timeHole=0;
nerit 10:9e70619e97ab 180 double memoTimeHole=0;
nerit 3:a469bbd294b5 181 int lockStart=0;
nerit 3:a469bbd294b5 182
nerit 3:a469bbd294b5 183 uint8_t quincStart=0;
nerit 3:a469bbd294b5 184 uint8_t oldQuincIn=0;
nerit 3:a469bbd294b5 185 double scostamento = 0.0f;
nerit 3:a469bbd294b5 186 uint8_t quincEnable=0;
nerit 3:a469bbd294b5 187 uint8_t quincCnt=0;
nerit 3:a469bbd294b5 188 double percento=0.0f;
nerit 3:a469bbd294b5 189 uint32_t masterSinc=0;
nerit 3:a469bbd294b5 190 uint32_t mast2_Sinc=0;
nerit 3:a469bbd294b5 191 bool quincClock=false;
nerit 3:a469bbd294b5 192 double oldQuincTimeSD=0.0f;
nerit 3:a469bbd294b5 193 uint8_t sincroQui=0;
nerit 3:a469bbd294b5 194 uint8_t quincPIDminus=0;
nerit 3:a469bbd294b5 195 uint8_t quincPIDplus=0;
nerit 3:a469bbd294b5 196 uint8_t quincLIMminus=0;
nerit 3:a469bbd294b5 197 uint8_t quincLIMplus=0;
nerit 3:a469bbd294b5 198 double memoCorrCorr=0.0f;
nerit 3:a469bbd294b5 199 double speedFromMaster=0.0f;
nerit 3:a469bbd294b5 200 uint8_t quincSector=0;
nerit 3:a469bbd294b5 201 uint8_t canDataCheck=0;
nerit 3:a469bbd294b5 202 double tempoBecchiPerQuinc=0.0f;
nerit 3:a469bbd294b5 203 int countPicks=0;
nerit 3:a469bbd294b5 204 uint8_t quinconceActive=0;
nerit 3:a469bbd294b5 205 uint8_t oldQuinconceOut=0;
nerit 3:a469bbd294b5 206
nerit 3:a469bbd294b5 207 double stepGrado = 0.0f;
nerit 3:a469bbd294b5 208 double TBfaseStep =0.0f;
nerit 19:231b8931cabc 209 double angoloPh=22.0f;
nerit 19:231b8931cabc 210 double angoloAv=4.0f;
nerit 3:a469bbd294b5 211
nerit 3:a469bbd294b5 212 uint8_t checkSDrotation=0;
nerit 3:a469bbd294b5 213 uint8_t comandiDaCan=0;
nerit 3:a469bbd294b5 214 uint8_t azzeraDaCan=0;
nerit 3:a469bbd294b5 215 uint8_t loadDaCan=0;
nerit 3:a469bbd294b5 216 uint8_t loadDaCanInCorso=0;
nerit 3:a469bbd294b5 217 uint8_t cntCellsForLoad=0;
nerit 3:a469bbd294b5 218 uint8_t trigRepos=0;
nerit 3:a469bbd294b5 219 uint8_t forzaFase=0;
nerit 3:a469bbd294b5 220 uint8_t erroreTamburo=0;
nerit 3:a469bbd294b5 221 uint8_t cntCellsForReload=0;
nerit 3:a469bbd294b5 222 uint8_t cntTbError=0;
nerit 3:a469bbd294b5 223
nerit 3:a469bbd294b5 224 uint8_t cellsCounterLow=0;
nerit 3:a469bbd294b5 225 uint8_t cellsCounterHig=0;
nerit 3:a469bbd294b5 226 uint8_t pickCounterLow=0;
nerit 3:a469bbd294b5 227 uint8_t pickCounterHig=0;
nerit 3:a469bbd294b5 228 uint8_t seedSee=0;
nerit 3:a469bbd294b5 229
nerit 3:a469bbd294b5 230 uint8_t cntCellsCorrect=0;
nerit 10:9e70619e97ab 231 uint8_t cntSpeedError=0;
nerit 3:a469bbd294b5 232
nerit 3:a469bbd294b5 233 uint8_t all_semiFiniti = 0; // semi finiti (generato dal relativo sensore)
nerit 3:a469bbd294b5 234 uint8_t all_pickSignal = 0; // errore segnale becchi (generato dal tempo tra un becco ed il successivo)
nerit 3:a469bbd294b5 235 uint8_t all_cellSignal = 0; // errore segnale celle (generato dal sensore tamburo )
nerit 3:a469bbd294b5 236 uint8_t all_lowBattery = 0; // allarme batteria (valore interno di tritecnica)
nerit 3:a469bbd294b5 237 uint8_t all_overCurrDC = 0; // sovracorrente motore DC (generato dal sensore di corrente)
nerit 3:a469bbd294b5 238 uint8_t all_stopSistem = 0; // sistema in stop (a tempo con ruota ferma)
nerit 3:a469bbd294b5 239 uint8_t all_upElements = 0; // elementi sollevati (generato dal relativo sensore)
nerit 3:a469bbd294b5 240 uint8_t all_noSeedOnCe = 0; // fallanza di semina (manca il seme nella cella)
nerit 3:a469bbd294b5 241 uint8_t all_cfgnErrors = 0; // errore di configurazione (incongruenza dei parametri impostati)
nerit 3:a469bbd294b5 242 uint8_t all_noDcRotati = 0; // ruota di semina bloccata (arriva la velocità ma non i becchi)
nerit 3:a469bbd294b5 243 uint8_t all_noStepRota = 0; // tamburo di semina bloccato (comando il tamburo ma non ricevo il sensore)
nerit 3:a469bbd294b5 244 uint8_t all_speedError = 0; // errore sensore velocità (tempo impulsi non costante)
nerit 3:a469bbd294b5 245 uint8_t all_noSpeedSen = 0; // mancanza segnale di velocità (sento i becchi ma non la velocita)
nerit 3:a469bbd294b5 246 uint8_t all_no_Zeroing = 0; // mancato azzeramento sistema (generato dal timeout del comando motore DC)
nerit 3:a469bbd294b5 247 uint8_t all_genericals = 0; // allarme generico
nerit 3:a469bbd294b5 248 uint8_t resetComandi=0;
nerit 3:a469bbd294b5 249
nerit 3:a469bbd294b5 250 //uint32_t spazioCoperto=0;