Francesco Pistone
/
FORIGO_Modula_V6_R2C_DE_HwV5
vo
main.cpp@3:c0f11ca4df02, 2018-06-15 (annotated)
- Committer:
- nerit
- Date:
- Fri Jun 15 17:10:37 2018 +0000
- Revision:
- 3:c0f11ca4df02
- Parent:
- 2:d9c7430ae953
- Child:
- 4:d32258ec411f
update del 15/06/18
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nerit | 1:e88bf5011af6 | 1 | |
nerit | 1:e88bf5011af6 | 2 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 3 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 4 | // FIRMWARE SEMINATRICE MODULA |
nerit | 0:1e09cd7d66b4 | 5 | // VERSIONE PER SCHEDA DI CONTROLLO CON DRIVER INTEGRATI |
nerit | 0:1e09cd7d66b4 | 6 | // V4 - ATTENZIONE - LA VERSIONE V4 HA IL DRIVER STEPPER LV8727 |
nerit | 0:1e09cd7d66b4 | 7 | // IL MOTORE DC E' GESTITO CON IL DRIVER VNH3SP30-E E CON LA LETTURA |
nerit | 0:1e09cd7d66b4 | 8 | // DELLA CORRENTE ASSORBITA TRAMITE IL CONVERTITORE MLX91210-CAS102 CON 50A FONDOSCALA |
nerit | 0:1e09cd7d66b4 | 9 | // CHE FORNISCE UNA TENSIONE DI USCITA PARI A 40mV/A |
nerit | 0:1e09cd7d66b4 | 10 | // FIRST RELEASE OF BOARD DEC 2017 |
nerit | 0:1e09cd7d66b4 | 11 | // FIRST RELEASE OF FIRMWARE JAN 2018 |
nerit | 0:1e09cd7d66b4 | 12 | // |
nerit | 0:1e09cd7d66b4 | 13 | // THIS RELEASE: 09 JULY 2018 |
nerit | 0:1e09cd7d66b4 | 14 | // |
nerit | 0:1e09cd7d66b4 | 15 | // APPLICATION: MODULA CON DISTRIBUTORE ZUCCA OPPURE RISO E PUO' FUNZIONARE ANCHE CON SENSORE A 25 FORI SUL DISCO O |
nerit | 0:1e09cd7d66b4 | 16 | // ENCODER MOTORE SETTANDO GLI APPOSITI FLAGS |
nerit | 0:1e09cd7d66b4 | 17 | // |
nerit | 0:1e09cd7d66b4 | 18 | // 29 05 2018 - INSERITO SECONDO ENCODER VIRTUALE PER LA GESTIONE DEL SINCRONISMO TRA TAMBURO E RUOTA DI SEMINA |
nerit | 0:1e09cd7d66b4 | 19 | // IN PRATICA IL PRIMO ENCODER è SINCRONO CON IL SEGNALE DEI BECCHI E VIENE AZZERATO DA QUESTI, MENTRE |
nerit | 0:1e09cd7d66b4 | 20 | // IL SECONDO E' INCREMENTATO IN SINCRONO CON IL PRIMO MA AZZERATO DALLA FASE. IL SUO VALORE E' POI DIVISO |
nerit | 0:1e09cd7d66b4 | 21 | // PER IL RAPPORTO RUOTE E LA CORREZIONE AGISCE SULLA VELOCITA' DEL TAMBURO PER MANTENERE LA FASE DEL SECONDO |
nerit | 0:1e09cd7d66b4 | 22 | // ENCODER |
nerit | 0:1e09cd7d66b4 | 23 | // 05 06 2018 - INSERITO IL CONTROLLO DI GESTIONE DEL QUINCONCE SENZA ENCODER |
nerit | 0:1e09cd7d66b4 | 24 | // 09 06 2018 - INSERITO CONTROLLO DI FASE CON ENCODER MASTER PER QUINCONCE - DATO SCAMBIATO IN CAN |
nerit | 0:1e09cd7d66b4 | 25 | // |
nerit | 0:1e09cd7d66b4 | 26 | /******************** |
nerit | 0:1e09cd7d66b4 | 27 | IL FIRMWARE SI COMPONE DI 7 FILES: |
nerit | 0:1e09cd7d66b4 | 28 | - main.cpp |
nerit | 0:1e09cd7d66b4 | 29 | - main.hpp |
nerit | 0:1e09cd7d66b4 | 30 | - iodefinition.hpp |
nerit | 0:1e09cd7d66b4 | 31 | - canbus.hpp |
nerit | 0:1e09cd7d66b4 | 32 | - parameters.hpp |
nerit | 0:1e09cd7d66b4 | 33 | - timeandtick.hpp |
nerit | 0:1e09cd7d66b4 | 34 | - variables.hpp |
nerit | 0:1e09cd7d66b4 | 35 | ED UTILIZZA LE LIBRERIE STANDARD MBED PIU' UNA LIBRERIA MODIFICATA E DEDICATA PER IL CAN |
nerit | 0:1e09cd7d66b4 | 36 | ********************* |
nerit | 0:1e09cd7d66b4 | 37 | LA MACCHINA UTILIZZA SEMPRE 2 SOLI SENSORI; UNO PER SENTIRE LE CELLE DI CARICO SEME ED UNO PER SENTIRE I BECCHI DI SEMINA. |
nerit | 0:1e09cd7d66b4 | 38 | GLI AZIONAMENTI SONO COMPOSTI DA DUE MOTORI; UN DC PER IL CONTROLLO DELLA RUOTA DI SEMINA ED UNO STEPPER PER IL CONTROLLO DEL TAMBURO |
nerit | 0:1e09cd7d66b4 | 39 | UN SENSORE AGGIUNTIVO SULL'ELEMENTO MASTER RILEVA LA VELOCITA' DI AVANZAMENTO |
nerit | 0:1e09cd7d66b4 | 40 | UN SENSORE AGGIUNTIVO SULLA RUOTA DI SEMINA RILEVA LA ROTAZIONE DELLA RUOTA STESSA ATTRAVERSO FORI PRESENTI SUL DISCO DI SEMINA |
nerit | 0:1e09cd7d66b4 | 41 | ********************* |
nerit | 0:1e09cd7d66b4 | 42 | LA LOGICA GENERALE PREVEDE CHE IL DC DELLA RUOTA DI SEMINA VENGA COMANDATO IN FUNZIONE DELLA VELOCITA' LETTA DAL SENSORE DI AVANZAMAENTO DEL MASTER |
nerit | 0:1e09cd7d66b4 | 43 | IL PROBLEMA PRINCIPALE E' CHE QUANDO I BECCHI SONO INSERITI NEL TERRENO NON VI E' RETROAZIONE REALE SULLA VELOCITA' DI ROTAZIONE DELLA RUOTA STESSA |
nerit | 0:1e09cd7d66b4 | 44 | PROPRIO PERCHE' L'AVANZAMANETO NEL TERRENO IMPRIME UNA VELOCITA' PROPRIA AL BECCO E QUINDI ANCHE ALLA RUOTA. |
nerit | 0:1e09cd7d66b4 | 45 | PER OVVIARE A QUESTO PROBLEMA SI E' INSERITO UN CONTROLLO DI CORRENTE ASSORBITA DAL DC; SE E' BASSA DEVO ACCELERARE, SE E' ALTA DEVO RALLENTARE |
nerit | 0:1e09cd7d66b4 | 46 | IL VALORE DI RIFERIMENTO DELL'ANALOGICA DI INGRESSO VIENE AGGIORNATO OGNI VOLTA CHE LA RUOTA DI SEMINA E' FERMA |
nerit | 0:1e09cd7d66b4 | 47 | IL TAMBURO SEGUE LA RUOTA DI SEMINA RILEVANDONE LA VELOCITA' E RICALCOLANDO LA PROPRIA IN FUNZIONE DELLA REALE VELOCITA' DI ROTAZIONE DELLA RUOTA DI SEMINA |
nerit | 0:1e09cd7d66b4 | 48 | LA FASE VIENE DETERMINATA DAL PASSAGGIO DEI BECCHI SUL SENSORE RELATIVO. |
nerit | 0:1e09cd7d66b4 | 49 | IL PROBLEMA PRINCIPALE NEL MANTENERE LA FASE DEL TAMBURO E' DATO DAL FATTO CHE LA SINCRONIZZAZIONE DELLA FASE SOLO SULL'IMPULSO DEL BECCO NON E' SUFFICIENTE |
nerit | 0:1e09cd7d66b4 | 50 | SOPRATUTTO QUANDO I BECCHI SONO MOLTO DISTANZIATI. |
nerit | 0:1e09cd7d66b4 | 51 | PER OVVIARE A QUESTO PROBLEMA SI SONO INSERITI DUE ENCODER VIRTUALI CHE SEZIONANO LA RUOTA DI SEMINA IN 9000 PARTI. ENTRAMBI VENGONO GESTITI DA UN GENERATORE DINAMICO DI CLOCK INTERNO |
nerit | 0:1e09cd7d66b4 | 52 | TARATO SULLA REALE VELOCITA' DI ROTAZIONE DELLA RUOTA DI SEMINA. |
nerit | 0:1e09cd7d66b4 | 53 | IL PRIMO ENCODER VIRTUALE SI OCCUPA DI DETERMINARE LA POSIZIONE FISICA DELLA RUOTA DI SEMINA E SI AZZERA AL PASSAGGIO DI OGNI BECCO. |
nerit | 0:1e09cd7d66b4 | 54 | IL SECONDO VIENE AZZERATO DALL'IMPULSO DI FASE DEL PRIMO ENCODER DETERMINATO DAI VALORI IMPOSTI SUL TERMINALE TRITECNICA |
nerit | 0:1e09cd7d66b4 | 55 | IL SECONDO ENCODER VIENE CONFRONTATO CON LA POSIZIONE ASSOLUTA DEL TAMBURO (DETERMINATA DAL NUMERO DI STEP EMESSI DAL CONTROLLO), RAPPORTATA TRA CELLE E BECCHI. |
nerit | 0:1e09cd7d66b4 | 56 | IL CONFRONTO DETERMINA LA POSIZIONE RELATIVA DELLA SINGOLA CELLA RISPETTO AL SINGOLO BECCO. IL MANTENIMENTO DELLA SINCRONIZZAZIONE DI FASE, DETERMINA IL SINCRO CELLA/BECCO. |
nerit | 0:1e09cd7d66b4 | 57 | LA SINCRONIZZAZIONE VIENE PERO' E' A SUA VOLTA RICALCOLATA SHIFTANDO LA POSIZIONE DI AZZERAMENTO DEL SECONDO ENCODER IN FUNZIONE DELLA VELOCITA' DI ROTAZIONE GENERALE AL FINE |
nerit | 0:1e09cd7d66b4 | 58 | DI CAMBIARE L'ANGOLO DI ANTICIPO DI RILASCIO DEL SEME IN FUNZIONE DELLA VELOCITA' E RECUPERARE COSI' IL TEMPO DI VOLO DEL SEME. |
nerit | 0:1e09cd7d66b4 | 59 | IL TAMBURO HA DUE TIPI DI FUNZIONAMENTO: CONTINUO E AD IMPULSI. E' SELEZIONABILE IN FUNZIONE DELLA VELOCITA' E DEL TIPO DI DISTRIBUTORE MONTATO. |
nerit | 0:1e09cd7d66b4 | 60 | ********************** |
nerit | 0:1e09cd7d66b4 | 61 | TUTTI I VALORI, CELLE, BECCHI, IMPULSI VELOCITA', ANCGOLO DI AVVIO, FASE DI SEMINA, ECC.. SONO IMPOSTABILI DA PANNELLO OPERATORE |
nerit | 0:1e09cd7d66b4 | 62 | I DATI SONO SCAMBIATI CON IL PANNELLO OPERATORE E CON GLI ALTRI MODULI ATTRAVERSO RETE CAN CON PROTOCOLLO FREESTYLE ATTRAVERSO INDIRIZZAMENTI DEDICATI |
nerit | 0:1e09cd7d66b4 | 63 | AL MOMENTO NON E' POSSIBILE ATTRIBUIRE L'INIDIRIZZO BASE DELL'ELEMENTO DA TERMINALE OPERATORE MA SOLO IN FASE DI COMPILAZIONE DEL FIRMWARE. |
nerit | 0:1e09cd7d66b4 | 64 | ********************** |
nerit | 0:1e09cd7d66b4 | 65 | ALTRE SEZIONI RIGUARDANO LA GENERAZIONE DEGLI ALLARMI, LA COMUNICAZIONE CAN, LA SIMULAZIONE DI LAVORO, LA GESTIONE DELLA DIAGNOSI ECC.. |
nerit | 0:1e09cd7d66b4 | 66 | IL MOTORE DC E' CONTROLLATO DA DIVERSE ROUTINE; LE PRIORITA' SONO (DALLA PIU' BASSA ALLA PIU' ALTA): CALCOLO TEORICO, RICALCOLO REALE, CONTROLLO DI FASE QUINCONCE, CONTROLLO DI CORRENTE. |
nerit | 0:1e09cd7d66b4 | 67 | LO STEPPER SEGUE IL DC. |
nerit | 0:1e09cd7d66b4 | 68 | ********************** |
nerit | 0:1e09cd7d66b4 | 69 | IN FASE DI ACCENSIONE ED OGNI QUALVOLTA SI ARRIVA A VELOCITA' ZERO, LA MACCHINA ESEGUE UN CICLO DI AZZERAMENTO |
nerit | 0:1e09cd7d66b4 | 70 | NON ESISTE PULSANTE DI MARCIA/STOP; E' SEMPRE ATTIVA. |
nerit | 0:1e09cd7d66b4 | 71 | ********************** |
nerit | 0:1e09cd7d66b4 | 72 | NEL PROGRAMMA E' PRESENTE UNA SEZIONE DI TEST FISICO DELLA SCHEDA ATTIVABILE SOLO IN FASE DI COMPILAZIONE |
nerit | 0:1e09cd7d66b4 | 73 | ********************** |
nerit | 0:1e09cd7d66b4 | 74 | ALTRE FUNZIONI: PRECARICAMENTO DEL TAMBURO |
nerit | 0:1e09cd7d66b4 | 75 | AZZERAMENTO MANUALE |
nerit | 0:1e09cd7d66b4 | 76 | STATISTICA DI SEMINA (CONTA LE CELLE) |
nerit | 0:1e09cd7d66b4 | 77 | */ |
nerit | 0:1e09cd7d66b4 | 78 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 79 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 80 | |
nerit | 0:1e09cd7d66b4 | 81 | #include "main.hpp" |
nerit | 0:1e09cd7d66b4 | 82 | #include "timeandtick.hpp" |
nerit | 0:1e09cd7d66b4 | 83 | #include "canbus.hpp" |
nerit | 0:1e09cd7d66b4 | 84 | #include "watchdog.h" |
nerit | 0:1e09cd7d66b4 | 85 | #include "iodefinition.hpp" |
nerit | 0:1e09cd7d66b4 | 86 | #include "parameters.hpp" |
nerit | 0:1e09cd7d66b4 | 87 | #include "variables.hpp" |
nerit | 0:1e09cd7d66b4 | 88 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 89 | //******************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 90 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
nerit | 0:1e09cd7d66b4 | 91 | // TASK SECTION |
nerit | 0:1e09cd7d66b4 | 92 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
nerit | 0:1e09cd7d66b4 | 93 | //************************************************************************ |
nerit | 3:c0f11ca4df02 | 94 | //************************************************************************ |
nerit | 0:1e09cd7d66b4 | 95 | // rise of seed speed 25 pulse sensor |
nerit | 0:1e09cd7d66b4 | 96 | void sd25Fall(){ |
nerit | 0:1e09cd7d66b4 | 97 | timeHole=metalTimer.read_ms(); |
nerit | 0:1e09cd7d66b4 | 98 | int memo_TimeHole= (memoTimeHole + timeHole)/ (int)2; |
nerit | 0:1e09cd7d66b4 | 99 | memoTimeHole = timeHole; |
nerit | 0:1e09cd7d66b4 | 100 | metalTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 101 | if (speedFromPick==0){ |
nerit | 0:1e09cd7d66b4 | 102 | speedOfSeedWheel=((seedPerimeter/25.0f)/(double)memo_TimeHole)*1000.0f; //mtS |
nerit | 0:1e09cd7d66b4 | 103 | } |
nerit | 0:1e09cd7d66b4 | 104 | } |
nerit | 0:1e09cd7d66b4 | 105 | //************************************************** |
nerit | 0:1e09cd7d66b4 | 106 | // generate speed clock when speed is simulated from Tritecnica display |
nerit | 0:1e09cd7d66b4 | 107 | void speedSimulationClock(){ |
nerit | 0:1e09cd7d66b4 | 108 | lastPulseRead=speedTimer.read_us(); |
nerit | 0:1e09cd7d66b4 | 109 | oldLastPulseRead=lastPulseRead; |
nerit | 0:1e09cd7d66b4 | 110 | speedTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 111 | pulseRised=1; |
nerit | 0:1e09cd7d66b4 | 112 | } |
nerit | 0:1e09cd7d66b4 | 113 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 114 | // interrupt task for tractor speed reading |
nerit | 0:1e09cd7d66b4 | 115 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 116 | void tractorReadSpeed(){ |
nerit | 0:1e09cd7d66b4 | 117 | if ((oldTractorSpeedRead==0)){ |
nerit | 0:1e09cd7d66b4 | 118 | lastPulseRead=speedTimer.read_us(); |
nerit | 0:1e09cd7d66b4 | 119 | oldLastPulseRead=lastPulseRead; |
nerit | 0:1e09cd7d66b4 | 120 | speedTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 121 | pulseRised=1; |
nerit | 0:1e09cd7d66b4 | 122 | oldTractorSpeedRead=1; |
nerit | 0:1e09cd7d66b4 | 123 | } |
nerit | 0:1e09cd7d66b4 | 124 | speedFilter.reset(); |
nerit | 0:1e09cd7d66b4 | 125 | speedClock=1; |
nerit | 0:1e09cd7d66b4 | 126 | } |
nerit | 0:1e09cd7d66b4 | 127 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 128 | void speedMediaCalc(){ |
nerit | 0:1e09cd7d66b4 | 129 | double lastPd=(double) lastPulseRead/1000.0f; |
nerit | 0:1e09cd7d66b4 | 130 | pulseSpeedInterval = (mediaSpeed[0]+lastPd)/2.0f; |
nerit | 0:1e09cd7d66b4 | 131 | if (enableSimula==1){ |
nerit | 0:1e09cd7d66b4 | 132 | double TMT = (double)(speedSimula) * 100.0f /3600.0f; |
nerit | 0:1e09cd7d66b4 | 133 | pulseSpeedInterval = pulseDistance / TMT; |
nerit | 0:1e09cd7d66b4 | 134 | } |
nerit | 0:1e09cd7d66b4 | 135 | mediaSpeed[0]=lastPd; |
nerit | 0:1e09cd7d66b4 | 136 | OLDpulseSpeedInterval=pulseSpeedInterval; |
nerit | 0:1e09cd7d66b4 | 137 | } |
nerit | 0:1e09cd7d66b4 | 138 | |
nerit | 0:1e09cd7d66b4 | 139 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 140 | // clocked task for manage virtual encoder of seed wheel i/o |
nerit | 0:1e09cd7d66b4 | 141 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 142 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 143 | void step_SDPulseOut(){ |
nerit | 0:1e09cd7d66b4 | 144 | SDactualPosition++; |
nerit | 0:1e09cd7d66b4 | 145 | prePosSD++; |
nerit | 0:1e09cd7d66b4 | 146 | } |
nerit | 0:1e09cd7d66b4 | 147 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 148 | void step_TBPulseOut(){ |
nerit | 0:1e09cd7d66b4 | 149 | TBmotorStepOut=!TBmotorStepOut; |
nerit | 0:1e09cd7d66b4 | 150 | if (TBmotorStepOut==0){ |
nerit | 0:1e09cd7d66b4 | 151 | TBactualPosition++; |
nerit | 0:1e09cd7d66b4 | 152 | } |
nerit | 0:1e09cd7d66b4 | 153 | } |
nerit | 0:1e09cd7d66b4 | 154 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 155 | // aggiornamento parametri di lavoro fissi e da Tritecnica |
nerit | 0:1e09cd7d66b4 | 156 | void aggiornaParametri(){ |
nerit | 0:1e09cd7d66b4 | 157 | speedPerimeter = Pi * speedWheelDiameter ; // perimeter of speed wheel |
nerit | 0:1e09cd7d66b4 | 158 | pulseDistance = (speedPerimeter / speedWheelPulse)*1000.0f; // linear space between speed wheel pulse |
nerit | 0:1e09cd7d66b4 | 159 | seedPerimeter = Pi * (seedWheelDiameter-(deepOfSeed*2.0f)); // perimeter of seed wheel |
nerit | 0:1e09cd7d66b4 | 160 | intraPickDistance = seedPerimeter/pickNumber; |
nerit | 0:1e09cd7d66b4 | 161 | K_WheelRPM = 60.0f/seedPerimeter; // calcola il K per i giri al minuto della ruota di semina |
nerit | 0:1e09cd7d66b4 | 162 | K_WhellFrequency = (seedWheelMotorSteps*SDreductionRatio)/60.0f; // calcola il K per la frequenza di comando del motore di semina |
nerit | 0:1e09cd7d66b4 | 163 | rapportoRuote = pickNumber/cellsNumber; // calcola il rapporto tra il numero di becchi ed il numero di celle |
nerit | 0:1e09cd7d66b4 | 164 | K_TBfrequency = (TBmotorSteps*TBreductionRatio)/240.0f; |
nerit | 0:1e09cd7d66b4 | 165 | K_percentuale = TBmotorSteps*TBreductionRatio; |
nerit | 0:1e09cd7d66b4 | 166 | SDsectorStep = (double)fixedStepGiroSD / (double)pickNumber; |
nerit | 0:1e09cd7d66b4 | 167 | TBsectorStep = (TBmotorSteps*TBreductionRatio)/cellsNumber; |
nerit | 0:1e09cd7d66b4 | 168 | KcorT = (SDsectorStep/TBsectorStep);///2.0f; |
nerit | 0:1e09cd7d66b4 | 169 | angoloFase=angoloPh; |
nerit | 0:1e09cd7d66b4 | 170 | avvioGradi=angoloAv; |
nerit | 0:1e09cd7d66b4 | 171 | stepGrado=fixedStepGiroSD/360.0f; |
nerit | 0:1e09cd7d66b4 | 172 | TBdeltaStep=(fixedStepGiroSD/pickNumber)+(stepGrado*avvioGradi); |
nerit | 0:1e09cd7d66b4 | 173 | TBfaseStep = (stepGrado*angoloFase); |
nerit | 0:1e09cd7d66b4 | 174 | K_WheelRPM = 60.0f/seedPerimeter; // calcola il K per i giri al minuto della ruota di semina 25.4 25,40 |
nerit | 0:1e09cd7d66b4 | 175 | if (speedFromPick==1) { |
nerit | 0:1e09cd7d66b4 | 176 | intraPickDistance = seedPerimeter/pickNumber; |
nerit | 0:1e09cd7d66b4 | 177 | }else{ |
nerit | 0:1e09cd7d66b4 | 178 | intraPickDistance = seedPerimeter/25.0f; // 25 è il numero di fori presenti nel disco di semina |
nerit | 0:1e09cd7d66b4 | 179 | } |
nerit | 0:1e09cd7d66b4 | 180 | if (anticipoMax > ((360.0f/pickNumber)-(avvioGradi+16.0f))){ |
nerit | 0:1e09cd7d66b4 | 181 | anticipoMax=(360.0f/pickNumber)-(avvioGradi+16.0f); |
nerit | 0:1e09cd7d66b4 | 182 | } |
nerit | 0:1e09cd7d66b4 | 183 | } |
nerit | 0:1e09cd7d66b4 | 184 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 185 | void cambiaTB(double perio){ |
nerit | 0:1e09cd7d66b4 | 186 | // update TB frequency |
nerit | 0:1e09cd7d66b4 | 187 | double TBper=0.0f; |
nerit | 0:1e09cd7d66b4 | 188 | if (aspettaStart==0){ |
nerit | 0:1e09cd7d66b4 | 189 | if (perio<250.0f){perio=500.0f;} |
nerit | 0:1e09cd7d66b4 | 190 | double scala =0.0f; |
nerit | 0:1e09cd7d66b4 | 191 | if (lowSpeed==1){ |
nerit | 0:1e09cd7d66b4 | 192 | scala =2.0f; |
nerit | 0:1e09cd7d66b4 | 193 | }else{ |
nerit | 0:1e09cd7d66b4 | 194 | scala =1.8f; |
nerit | 0:1e09cd7d66b4 | 195 | } |
nerit | 0:1e09cd7d66b4 | 196 | TBper=perio/scala; |
nerit | 0:1e09cd7d66b4 | 197 | if (oldPeriodoTB!=TBper){ |
nerit | 0:1e09cd7d66b4 | 198 | if (TBper >= 250.0f){ |
nerit | 0:1e09cd7d66b4 | 199 | TBticker.attach_us(&step_TBPulseOut,TBper); // clock time are milliseconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 200 | }else{ |
nerit | 0:1e09cd7d66b4 | 201 | TBticker.detach(); |
nerit | 0:1e09cd7d66b4 | 202 | } |
nerit | 0:1e09cd7d66b4 | 203 | oldPeriodoTB=TBper; |
nerit | 0:1e09cd7d66b4 | 204 | } |
nerit | 0:1e09cd7d66b4 | 205 | } |
nerit | 0:1e09cd7d66b4 | 206 | } |
nerit | 0:1e09cd7d66b4 | 207 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 208 | void seedCorrect(){ |
nerit | 0:1e09cd7d66b4 | 209 | /* |
nerit | 0:1e09cd7d66b4 | 210 | posError determina la posizione relativa di TB rispetto ad SD |
nerit | 0:1e09cd7d66b4 | 211 | la reale posizione di SD viene modificata in funzione della velocità per |
nerit | 0:1e09cd7d66b4 | 212 | traslare la posizione relativa di TB. All'aumentare della velocità la posizione |
nerit | 0:1e09cd7d66b4 | 213 | di SD viene incrementata così che TB acceleri per raggiungerla in modo da rilasciare il seme prima |
nerit | 0:1e09cd7d66b4 | 214 | La taratura del sistema avviene determinando prima il valore di angoloFase alla minima velocità, |
nerit | 0:1e09cd7d66b4 | 215 | poi, alla massima velocità, dovrebbe spostarsi la posizione relativa con una variabile proporzionale alla velocità, ma c'è un però. |
nerit | 0:1e09cd7d66b4 | 216 | Il problema è che il momento di avvio determina una correzione dell'angolo di partenza del tamburo |
nerit | 0:1e09cd7d66b4 | 217 | angolo che viene rideterminato ogni volta che il sensore becchi legge un transito. |
nerit | 0:1e09cd7d66b4 | 218 | Di fatto c'è una concorrenza tra l'angolo di avvio determinato e la correzione di posizione relativa |
nerit | 0:1e09cd7d66b4 | 219 | del tamburo. E' molto probabile che convenga modificare solo la posizione relativa e non anche l'angolo di avvio |
nerit | 0:1e09cd7d66b4 | 220 | Ancora di più se viene eliminata la parte gestita da ciclata. |
nerit | 0:1e09cd7d66b4 | 221 | In questo modo dovrebbe esserci solo un andamento in accelerazione di TB che viene poi eventualmente decelerato |
nerit | 0:1e09cd7d66b4 | 222 | dal passaggio sul sensore di TB. Funzione corretta perchè il sincronismo tra i sensori genera l'inibizione della correzione |
nerit | 0:1e09cd7d66b4 | 223 | di fase di TB. In pratica il ciclo viene resettato al passaggio sul sensore di SD che riporta a 0 la posizione di SD. |
nerit | 0:1e09cd7d66b4 | 224 | Appena il sensore di TB viene impegnato allora viene abilitato il controllo di fase del tamburo. |
nerit | 0:1e09cd7d66b4 | 225 | Questo si traduce nel fatto che il controllo di posizione viene gestito solo all'interno di uno slot di semina in modo che |
nerit | 0:1e09cd7d66b4 | 226 | il tamburo non risenta della condizione di reset della posizione di SD mentre lui è ancora nella fase precedente. Si fermerebbe. |
nerit | 0:1e09cd7d66b4 | 227 | |
nerit | 0:1e09cd7d66b4 | 228 | // La considerazione finale è che mantenendo l'angolo di avvio fisso e regolato sulla bassa velocità, intervenendo solo sulla correzione |
nerit | 0:1e09cd7d66b4 | 229 | // di posizione in questa routine, dovrebbe essere possibile seminare correttamente a tutte le velocità regolando solo 2 parametri. |
nerit | 0:1e09cd7d66b4 | 230 | */ |
nerit | 0:1e09cd7d66b4 | 231 | /* |
nerit | 0:1e09cd7d66b4 | 232 | SDsectorStep = (double)fixedStepGiroSD / (double)pickNumber; |
nerit | 0:1e09cd7d66b4 | 233 | TBsectorStep = (TBmotorSteps*TBreductionRatio)/cellsNumber; |
nerit | 0:1e09cd7d66b4 | 234 | KcorT = (SDsectorStep/TBsectorStep); |
nerit | 0:1e09cd7d66b4 | 235 | angoloFase=angoloPh; |
nerit | 0:1e09cd7d66b4 | 236 | stepGrado=fixedStepGiroSD/360.0f; |
nerit | 0:1e09cd7d66b4 | 237 | avvioGradi = costante da terminale tritecnica |
nerit | 0:1e09cd7d66b4 | 238 | TBdeltaStep=(fixedStepGiroSD/pickNumber)-(stepGrado*avvioGradi); |
nerit | 0:1e09cd7d66b4 | 239 | TBfaseStep = (stepGrado*angoloFase); |
nerit | 0:1e09cd7d66b4 | 240 | anticipoMax = valore in gradi del massimo anticipo proporzionale alla velocità della ruota di semina |
nerit | 0:1e09cd7d66b4 | 241 | */ |
nerit | 0:1e09cd7d66b4 | 242 | |
nerit | 0:1e09cd7d66b4 | 243 | if ((tractorSpeed_MtS_timed>0.01f)){ |
nerit | 0:1e09cd7d66b4 | 244 | if (inhibit==0){ |
nerit | 0:1e09cd7d66b4 | 245 | double posError =0.0f; |
nerit | 0:1e09cd7d66b4 | 246 | double posSD=((double)SDactualPosition)/KcorT; |
nerit | 0:1e09cd7d66b4 | 247 | posError = posSD - (double)TBactualPosition; |
nerit | 0:1e09cd7d66b4 | 248 | // interviene sulla velocità di TB per raggiungere la corretta posizione relativa |
nerit | 0:1e09cd7d66b4 | 249 | if((lowSpeed==0)&&(aspettaStart==0)){ |
nerit | 0:1e09cd7d66b4 | 250 | if (posError>50.0f){posError=50.0f;} |
nerit | 0:1e09cd7d66b4 | 251 | if (posError<-50.0f){posError=-50.0f;} |
nerit | 0:1e09cd7d66b4 | 252 | if ((posError >=1.0f)||(posError<=-1.0f)){ |
nerit | 0:1e09cd7d66b4 | 253 | ePpos = periodo /(1.0f+ ((posError/100.0f))); |
nerit | 0:1e09cd7d66b4 | 254 | cambiaTB(ePpos); |
nerit | 0:1e09cd7d66b4 | 255 | } |
nerit | 0:1e09cd7d66b4 | 256 | } |
nerit | 0:1e09cd7d66b4 | 257 | } |
nerit | 0:1e09cd7d66b4 | 258 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 259 | #if defined(SDreset) |
nerit | 0:1e09cd7d66b4 | 260 | pc.printf("Fase: %d",fase); |
nerit | 0:1e09cd7d66b4 | 261 | pc.printf(" PrePosSD: %d",prePosSD); |
nerit | 0:1e09cd7d66b4 | 262 | pc.printf(" PosSD: %d",SDactualPosition); |
nerit | 0:1e09cd7d66b4 | 263 | pc.printf(" speed: %f",tractorSpeed_MtS_timed); |
nerit | 0:1e09cd7d66b4 | 264 | pc.printf(" Trigger: %d \n", trigRepos); |
nerit | 0:1e09cd7d66b4 | 265 | #endif |
nerit | 0:1e09cd7d66b4 | 266 | #endif |
nerit | 0:1e09cd7d66b4 | 267 | } |
nerit | 0:1e09cd7d66b4 | 268 | } |
nerit | 0:1e09cd7d66b4 | 269 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 270 | void videoUpdate(){ |
nerit | 0:1e09cd7d66b4 | 271 | for(int aa=0;aa<4;aa++){speedForDisplay[aa]=speedForDisplay[aa+1];} |
nerit | 0:1e09cd7d66b4 | 272 | speedForDisplay[4]=tractorSpeed_MtS_timed; |
nerit | 0:1e09cd7d66b4 | 273 | totalSpeed=0.0f; |
nerit | 0:1e09cd7d66b4 | 274 | for (int aa=0; aa<5; aa++){totalSpeed += speedForDisplay[aa];} |
nerit | 0:1e09cd7d66b4 | 275 | totalSpeed = totalSpeed / 5.0f; |
nerit | 0:1e09cd7d66b4 | 276 | } |
nerit | 0:1e09cd7d66b4 | 277 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 278 | void ciclaTB(){ |
nerit | 0:1e09cd7d66b4 | 279 | if ((startCicloTB==1)&&(cicloTbinCorso==0)){ |
nerit | 0:1e09cd7d66b4 | 280 | TBticker.attach_us(&step_TBPulseOut,TBperiod/2.5f); // clock time are milliseconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 281 | cicloTbinCorso = 1; |
nerit | 0:1e09cd7d66b4 | 282 | startCicloTB=0; |
nerit | 0:1e09cd7d66b4 | 283 | } |
nerit | 0:1e09cd7d66b4 | 284 | if ((loadDaCan==1)&&(loadDaCanInCorso==0)){ |
nerit | 0:1e09cd7d66b4 | 285 | TBticker.attach_us(&step_TBPulseOut,1000.0f); // clock time are milliseconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 286 | loadDaCanInCorso=1; |
nerit | 0:1e09cd7d66b4 | 287 | stopCicloTB=0; |
nerit | 0:1e09cd7d66b4 | 288 | } |
nerit | 0:1e09cd7d66b4 | 289 | if ((stopCicloTB==1)&&(TBactualPosition>5)){ |
nerit | 0:1e09cd7d66b4 | 290 | TBticker.detach(); |
nerit | 0:1e09cd7d66b4 | 291 | cicloTbinCorso = 0; |
nerit | 0:1e09cd7d66b4 | 292 | stopCicloTB=0; |
nerit | 0:1e09cd7d66b4 | 293 | loadDaCanInCorso=0; |
nerit | 0:1e09cd7d66b4 | 294 | loadDaCan=0; |
nerit | 0:1e09cd7d66b4 | 295 | } |
nerit | 0:1e09cd7d66b4 | 296 | } |
nerit | 0:1e09cd7d66b4 | 297 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 298 | void allarmi(){ |
nerit | 0:1e09cd7d66b4 | 299 | uint8_t alarmLowRegister1=0x00; |
nerit | 0:1e09cd7d66b4 | 300 | alarmLowRegister=0x00; |
nerit | 0:1e09cd7d66b4 | 301 | alarmHighRegister=0x80; |
nerit | 0:1e09cd7d66b4 | 302 | |
nerit | 0:1e09cd7d66b4 | 303 | //alarmLowRegister=alarmLowRegister+(all_semiFiniti*0x01); // manca il sensore |
nerit | 0:1e09cd7d66b4 | 304 | alarmLowRegister=alarmLowRegister+(all_pickSignal*0x02); // fatto |
nerit | 0:1e09cd7d66b4 | 305 | alarmLowRegister=alarmLowRegister+(all_cellSignal*0x04); // fatto |
nerit | 0:1e09cd7d66b4 | 306 | alarmLowRegister=alarmLowRegister+(all_lowBattery*0x08); // fatto |
nerit | 0:1e09cd7d66b4 | 307 | alarmLowRegister=alarmLowRegister+(all_overCurrDC*0x10); // fatto |
nerit | 0:1e09cd7d66b4 | 308 | alarmLowRegister=alarmLowRegister+(all_stopSistem*0x20); // verificarne la necessità |
nerit | 0:1e09cd7d66b4 | 309 | //alarmLowRegister=alarmLowRegister+(all_upElements*0x40); // manca il sensore |
nerit | 0:1e09cd7d66b4 | 310 | //alarmLowRegister=alarmLowRegister+(all_noSeedOnCe*0x80); // manca il sensore |
nerit | 0:1e09cd7d66b4 | 311 | |
nerit | 0:1e09cd7d66b4 | 312 | //alarmLowRegister1=alarmLowRegister1+(all_cfgnErrors*0x01); // da scrivere |
nerit | 0:1e09cd7d66b4 | 313 | alarmLowRegister1=alarmLowRegister1+(all_noDcRotati*0x02); // fatto |
nerit | 0:1e09cd7d66b4 | 314 | alarmLowRegister1=alarmLowRegister1+(all_noStepRota*0x04); // fatto |
nerit | 0:1e09cd7d66b4 | 315 | alarmLowRegister1=alarmLowRegister1+(all_speedError*0x08); // fatto |
nerit | 0:1e09cd7d66b4 | 316 | alarmLowRegister1=alarmLowRegister1+(all_noSpeedSen*0x10); // fatto |
nerit | 0:1e09cd7d66b4 | 317 | alarmLowRegister1=alarmLowRegister1+(all_no_Zeroing*0x20); // fatto |
nerit | 0:1e09cd7d66b4 | 318 | alarmLowRegister1=alarmLowRegister1+(all_genericals*0x40); |
nerit | 0:1e09cd7d66b4 | 319 | if (alarmLowRegister1 > 0){ |
nerit | 0:1e09cd7d66b4 | 320 | alarmHighRegister = 0x81; |
nerit | 0:1e09cd7d66b4 | 321 | alarmLowRegister = alarmLowRegister1; |
nerit | 0:1e09cd7d66b4 | 322 | } |
nerit | 0:1e09cd7d66b4 | 323 | |
nerit | 0:1e09cd7d66b4 | 324 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 325 | #if defined(VediAllarmi) |
nerit | 0:1e09cd7d66b4 | 326 | if (all_pickSignal==1){pc.printf("AllarmeBecchi\n");} |
nerit | 0:1e09cd7d66b4 | 327 | if (all_cellSignal==1){pc.printf("AllarmeCelle\n");} |
nerit | 0:1e09cd7d66b4 | 328 | if (all_lowBattery==1){pc.printf("AllarmeBassaCorrente\n");} |
nerit | 0:1e09cd7d66b4 | 329 | if (all_overCurrDC==1){pc.printf("AllarmeAltaCorrente\n");} |
nerit | 0:1e09cd7d66b4 | 330 | if (all_stopSistem==1){pc.printf("AllarmeStop\n");} |
nerit | 0:1e09cd7d66b4 | 331 | if (all_noDcRotati==1){pc.printf("AllarmeDCnoRotation\n");} |
nerit | 0:1e09cd7d66b4 | 332 | if (all_noStepRota==1){pc.printf("AllarmeNoStepRotation\n");} |
nerit | 0:1e09cd7d66b4 | 333 | if (all_speedError==1){pc.printf("AllarmeSpeedError\n");} |
nerit | 0:1e09cd7d66b4 | 334 | if (all_noSpeedSen==1){pc.printf("AllarmeNoSpeedSensor\n");} |
nerit | 0:1e09cd7d66b4 | 335 | if (all_no_Zeroing==1){pc.printf("AllarmeNoZero\n");} |
nerit | 0:1e09cd7d66b4 | 336 | if (all_genericals==1){pc.printf("AllarmeGenerico\n");} |
nerit | 0:1e09cd7d66b4 | 337 | pc.printf("Code: 0x%x%x\n",alarmHighRegister,alarmLowRegister); |
nerit | 0:1e09cd7d66b4 | 338 | #endif |
nerit | 0:1e09cd7d66b4 | 339 | #endif |
nerit | 0:1e09cd7d66b4 | 340 | all_semiFiniti=0; |
nerit | 0:1e09cd7d66b4 | 341 | all_pickSignal=0; |
nerit | 0:1e09cd7d66b4 | 342 | all_cellSignal=0; |
nerit | 0:1e09cd7d66b4 | 343 | all_lowBattery=0; |
nerit | 0:1e09cd7d66b4 | 344 | all_overCurrDC=0; |
nerit | 0:1e09cd7d66b4 | 345 | all_stopSistem=0; |
nerit | 0:1e09cd7d66b4 | 346 | all_upElements=0; |
nerit | 0:1e09cd7d66b4 | 347 | all_noSeedOnCe=0; |
nerit | 0:1e09cd7d66b4 | 348 | all_cfgnErrors=0; |
nerit | 0:1e09cd7d66b4 | 349 | all_noDcRotati=0; |
nerit | 0:1e09cd7d66b4 | 350 | all_noStepRota=0; |
nerit | 0:1e09cd7d66b4 | 351 | all_speedError=0; |
nerit | 0:1e09cd7d66b4 | 352 | all_noSpeedSen=0; |
nerit | 0:1e09cd7d66b4 | 353 | all_no_Zeroing=0; |
nerit | 0:1e09cd7d66b4 | 354 | all_genericals=0; |
nerit | 0:1e09cd7d66b4 | 355 | } |
nerit | 0:1e09cd7d66b4 | 356 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 357 | #if defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 358 | void upDateSincro(){ |
nerit | 0:1e09cd7d66b4 | 359 | char val1[8]={0,0,0,0,0,0,0,0}; |
nerit | 0:1e09cd7d66b4 | 360 | val1[0]=(prePosSD /0x00FF0000)&0x000000FF; |
nerit | 0:1e09cd7d66b4 | 361 | val1[1]=(prePosSD /0x0000FF00)&0x000000FF; |
nerit | 0:1e09cd7d66b4 | 362 | val1[2]=(prePosSD /0x000000FF)&0x000000FF; |
nerit | 0:1e09cd7d66b4 | 363 | val1[3]=prePosSD & 0x000000FF; |
nerit | 0:1e09cd7d66b4 | 364 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 365 | #if defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 366 | if(can1.write(CANMessage(TX_SI, *&val1,8))){ |
nerit | 0:1e09cd7d66b4 | 367 | checkState=0; |
nerit | 0:1e09cd7d66b4 | 368 | } |
nerit | 0:1e09cd7d66b4 | 369 | #endif |
nerit | 0:1e09cd7d66b4 | 370 | #endif |
nerit | 0:1e09cd7d66b4 | 371 | } |
nerit | 0:1e09cd7d66b4 | 372 | #endif |
nerit | 0:1e09cd7d66b4 | 373 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 374 | void upDateSpeed(){ |
nerit | 0:1e09cd7d66b4 | 375 | /* |
nerit | 0:1e09cd7d66b4 | 376 | aggiorna dati OPUSA3 |
nerit | 0:1e09cd7d66b4 | 377 | val1[0] contiene il dato di velocità |
nerit | 0:1e09cd7d66b4 | 378 | val1[1] contiene il byte basso della tabella allarmi |
nerit | 0:1e09cd7d66b4 | 379 | uint8_t all_semiFiniti = 0; // semi finiti (generato dal relativo sensore) |
nerit | 0:1e09cd7d66b4 | 380 | uint8_t all_pickSignal = 0; // errore segnale becchi (generato dal tempo tra un becco ed il successivo) |
nerit | 0:1e09cd7d66b4 | 381 | uint8_t all_cellSignal = 0; // errore segnale celle (generato dal sensore tamburo ) |
nerit | 0:1e09cd7d66b4 | 382 | uint8_t all_lowBattery = 0; // allarme batteria (valore interno di tritecnica) |
nerit | 0:1e09cd7d66b4 | 383 | uint8_t all_overCurrDC = 0; // sovracorrente motore DC (generato dal sensore di corrente) |
nerit | 0:1e09cd7d66b4 | 384 | uint8_t all_stopSistem = 0; // sistema in stop (a tempo con ruota ferma) |
nerit | 0:1e09cd7d66b4 | 385 | uint8_t all_upElements = 0; // elementi sollevati (generato dal relativo sensore) |
nerit | 0:1e09cd7d66b4 | 386 | uint8_t all_noSeedOnCe = 0; // fallanza di semina (manca il seme nella cella) |
nerit | 0:1e09cd7d66b4 | 387 | uint8_t all_cfgnErrors = 0; // errore di configurazione (incongruenza dei parametri impostati) |
nerit | 0:1e09cd7d66b4 | 388 | uint8_t all_noDcRotati = 0; // ruota di semina bloccata (arriva la velocità ma non i becchi) |
nerit | 0:1e09cd7d66b4 | 389 | uint8_t all_noStepRota = 0; // tamburo di semina bloccato (comando il tamburo ma non ricevo il sensore) |
nerit | 0:1e09cd7d66b4 | 390 | uint8_t all_speedError = 0; // errore sensore velocità (tempo impulsi non costante) |
nerit | 0:1e09cd7d66b4 | 391 | uint8_t all_noSpeedSen = 0; // mancanza segnale di velocità (sento i becchi ma non la velocita) |
nerit | 0:1e09cd7d66b4 | 392 | uint8_t all_no_Zeroing = 0; // mancato azzeramento sistema (generato dal timeout del comando motore DC) |
nerit | 0:1e09cd7d66b4 | 393 | uint8_t all_genericals = 0; // allarme generico |
nerit | 0:1e09cd7d66b4 | 394 | val1[2] contiene il byte alto della tabella di allarmi |
nerit | 0:1e09cd7d66b4 | 395 | val1[3] contiene i segnali per la diagnostica |
nerit | 0:1e09cd7d66b4 | 396 | bit 0= sensore ruota fonica |
nerit | 0:1e09cd7d66b4 | 397 | bit 1= sensore celle |
nerit | 0:1e09cd7d66b4 | 398 | bit 2= sensore posizione |
nerit | 0:1e09cd7d66b4 | 399 | bit 3= sensore becchi |
nerit | 0:1e09cd7d66b4 | 400 | bit 4= motore DC |
nerit | 0:1e09cd7d66b4 | 401 | bit 5= controller |
nerit | 0:1e09cd7d66b4 | 402 | bit 6= motore stepper |
nerit | 0:1e09cd7d66b4 | 403 | */ |
nerit | 0:1e09cd7d66b4 | 404 | char val1[8]={0,0,0,0,0,0,0,0}; |
nerit | 0:1e09cd7d66b4 | 405 | |
nerit | 0:1e09cd7d66b4 | 406 | val1[3]=0; |
nerit | 0:1e09cd7d66b4 | 407 | val1[3]=val1[3]+(tractorSpeedRead*0x01); |
nerit | 3:c0f11ca4df02 | 408 | val1[3]=val1[3]+(TBzeroPinInput*0x02); |
nerit | 0:1e09cd7d66b4 | 409 | val1[3]=val1[3]+(ElementPosition*0x04); |
nerit | 3:c0f11ca4df02 | 410 | val1[3]=val1[3]+(seedWheelZeroPinInput*0x08); |
nerit | 0:1e09cd7d66b4 | 411 | #if defined(simulaPerCan) |
nerit | 0:1e09cd7d66b4 | 412 | if (buttonUser==0){ |
nerit | 0:1e09cd7d66b4 | 413 | val1[1]=0x02; |
nerit | 0:1e09cd7d66b4 | 414 | }else{ |
nerit | 0:1e09cd7d66b4 | 415 | val1[1]=0x00; |
nerit | 0:1e09cd7d66b4 | 416 | } |
nerit | 0:1e09cd7d66b4 | 417 | val1[3]=valore; |
nerit | 0:1e09cd7d66b4 | 418 | valore+=1; |
nerit | 0:1e09cd7d66b4 | 419 | if(valore>50){ |
nerit | 0:1e09cd7d66b4 | 420 | valore=0; |
nerit | 0:1e09cd7d66b4 | 421 | } |
nerit | 0:1e09cd7d66b4 | 422 | tractorSpeed_MtS_timed=valore; |
nerit | 0:1e09cd7d66b4 | 423 | #endif |
nerit | 0:1e09cd7d66b4 | 424 | allarmi(); |
nerit | 0:1e09cd7d66b4 | 425 | valore = totalSpeed*36.0f; // tractorSpeed_MtS_timed*36.0f; |
nerit | 0:1e09cd7d66b4 | 426 | val1[0]=valore; |
nerit | 0:1e09cd7d66b4 | 427 | val1[1]=alarmHighRegister; // registro alto allarmi. Parte sempre da 0x80 |
nerit | 0:1e09cd7d66b4 | 428 | val1[2]=alarmLowRegister; // registro basso allarmi |
nerit | 0:1e09cd7d66b4 | 429 | //val1[3]=val1[3];// registro di stato degli ingressi |
nerit | 0:1e09cd7d66b4 | 430 | val1[4]=resetComandi; |
nerit | 0:1e09cd7d66b4 | 431 | val1[5]=cellsCounterLow; |
nerit | 0:1e09cd7d66b4 | 432 | val1[6]=cellsCounterHig; |
nerit | 0:1e09cd7d66b4 | 433 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 434 | if(can1.write(CANMessage(TX_ID, *&val1,8))){ |
nerit | 0:1e09cd7d66b4 | 435 | checkState=0; |
nerit | 0:1e09cd7d66b4 | 436 | } |
nerit | 0:1e09cd7d66b4 | 437 | #endif |
nerit | 0:1e09cd7d66b4 | 438 | } |
nerit | 0:1e09cd7d66b4 | 439 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 440 | void leggiCAN(){ |
nerit | 0:1e09cd7d66b4 | 441 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 442 | if(can1.read(rxMsg)) { |
nerit | 0:1e09cd7d66b4 | 443 | if (firstStart==1){ |
nerit | 3:c0f11ca4df02 | 444 | /* |
nerit | 0:1e09cd7d66b4 | 445 | #if defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 446 | sincUpdate.attach(&upDateSincro,0.01f); |
nerit | 0:1e09cd7d66b4 | 447 | #endif |
nerit | 3:c0f11ca4df02 | 448 | */ |
nerit | 0:1e09cd7d66b4 | 449 | canUpdate.attach(&upDateSpeed,0.11f); |
nerit | 0:1e09cd7d66b4 | 450 | firstStart=0; |
nerit | 0:1e09cd7d66b4 | 451 | } |
nerit | 0:1e09cd7d66b4 | 452 | |
nerit | 0:1e09cd7d66b4 | 453 | if (rxMsg.id==RX_ID){ |
nerit | 0:1e09cd7d66b4 | 454 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 455 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 456 | pc.printf("Messaggio ricevuto\n"); |
nerit | 0:1e09cd7d66b4 | 457 | #endif |
nerit | 0:1e09cd7d66b4 | 458 | #endif |
nerit | 0:1e09cd7d66b4 | 459 | } |
nerit | 0:1e09cd7d66b4 | 460 | if (rxMsg.id==RX_Broadcast){ |
nerit | 0:1e09cd7d66b4 | 461 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 462 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 463 | pc.printf("BroadCast ricevuto\n"); |
nerit | 0:1e09cd7d66b4 | 464 | #endif |
nerit | 0:1e09cd7d66b4 | 465 | #endif |
nerit | 0:1e09cd7d66b4 | 466 | enableSimula= rxMsg.data[0]; |
nerit | 0:1e09cd7d66b4 | 467 | speedSimula = rxMsg.data[1]; |
nerit | 0:1e09cd7d66b4 | 468 | avviaSimula = rxMsg.data[2]; |
nerit | 0:1e09cd7d66b4 | 469 | selezionato = rxMsg.data[3]; |
nerit | 0:1e09cd7d66b4 | 470 | comandiDaCan = rxMsg.data[4]; |
nerit | 0:1e09cd7d66b4 | 471 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 472 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 473 | pc.printf("Comandi: %x\n",comandiDaCan); |
nerit | 0:1e09cd7d66b4 | 474 | #endif |
nerit | 0:1e09cd7d66b4 | 475 | #endif |
nerit | 0:1e09cd7d66b4 | 476 | switch (comandiDaCan){ |
nerit | 0:1e09cd7d66b4 | 477 | case 1: |
nerit | 0:1e09cd7d66b4 | 478 | case 3: |
nerit | 0:1e09cd7d66b4 | 479 | azzeraDaCan=1; |
nerit | 0:1e09cd7d66b4 | 480 | resetComandi=0x01; |
nerit | 0:1e09cd7d66b4 | 481 | comandiDaCan=0; |
nerit | 0:1e09cd7d66b4 | 482 | break; |
nerit | 0:1e09cd7d66b4 | 483 | case 2: |
nerit | 0:1e09cd7d66b4 | 484 | loadDaCan=1; |
nerit | 0:1e09cd7d66b4 | 485 | resetComandi=0x02; |
nerit | 0:1e09cd7d66b4 | 486 | comandiDaCan=0; |
nerit | 0:1e09cd7d66b4 | 487 | break; |
nerit | 0:1e09cd7d66b4 | 488 | default: |
nerit | 0:1e09cd7d66b4 | 489 | comandiDaCan=0; |
nerit | 0:1e09cd7d66b4 | 490 | resetComandi=0xFF; |
nerit | 0:1e09cd7d66b4 | 491 | break; |
nerit | 0:1e09cd7d66b4 | 492 | } |
nerit | 0:1e09cd7d66b4 | 493 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 494 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 495 | pc.printf("Comandi: %x\n",resetComandi); |
nerit | 0:1e09cd7d66b4 | 496 | #endif |
nerit | 0:1e09cd7d66b4 | 497 | #endif |
nerit | 0:1e09cd7d66b4 | 498 | if (speedSimula>45){ |
nerit | 0:1e09cd7d66b4 | 499 | speedSimula=45; |
nerit | 0:1e09cd7d66b4 | 500 | } |
nerit | 0:1e09cd7d66b4 | 501 | // modulo 1 |
nerit | 0:1e09cd7d66b4 | 502 | if (RX_ID==0x100){ |
nerit | 0:1e09cd7d66b4 | 503 | if ((selezionato&0x01)==0x01){ |
nerit | 0:1e09cd7d66b4 | 504 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 505 | }else{ |
nerit | 0:1e09cd7d66b4 | 506 | simOk=0; |
nerit | 0:1e09cd7d66b4 | 507 | } |
nerit | 0:1e09cd7d66b4 | 508 | } |
nerit | 0:1e09cd7d66b4 | 509 | // modulo 2 |
nerit | 0:1e09cd7d66b4 | 510 | if (RX_ID==0x102){ |
nerit | 0:1e09cd7d66b4 | 511 | if ((selezionato&0x02)==0x02){ |
nerit | 0:1e09cd7d66b4 | 512 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 513 | }else{ |
nerit | 0:1e09cd7d66b4 | 514 | simOk=0; |
nerit | 0:1e09cd7d66b4 | 515 | } |
nerit | 0:1e09cd7d66b4 | 516 | } |
nerit | 0:1e09cd7d66b4 | 517 | // modulo 3 |
nerit | 0:1e09cd7d66b4 | 518 | if (RX_ID==0x104){ |
nerit | 0:1e09cd7d66b4 | 519 | if ((selezionato&0x04)==0x04){ |
nerit | 0:1e09cd7d66b4 | 520 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 521 | }else{ |
nerit | 0:1e09cd7d66b4 | 522 | simOk=0; |
nerit | 0:1e09cd7d66b4 | 523 | } |
nerit | 0:1e09cd7d66b4 | 524 | } |
nerit | 0:1e09cd7d66b4 | 525 | // modulo 4 |
nerit | 0:1e09cd7d66b4 | 526 | if (RX_ID==0x106){ |
nerit | 0:1e09cd7d66b4 | 527 | if ((selezionato&0x08)==0x08){ |
nerit | 0:1e09cd7d66b4 | 528 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 529 | }else{ |
nerit | 0:1e09cd7d66b4 | 530 | simOk=0; |
nerit | 0:1e09cd7d66b4 | 531 | } |
nerit | 0:1e09cd7d66b4 | 532 | } |
nerit | 0:1e09cd7d66b4 | 533 | // modulo 5 |
nerit | 0:1e09cd7d66b4 | 534 | if (RX_ID==0x108){ |
nerit | 0:1e09cd7d66b4 | 535 | if ((selezionato&0x10)==0x10){ |
nerit | 0:1e09cd7d66b4 | 536 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 537 | }else{ |
nerit | 0:1e09cd7d66b4 | 538 | simOk=0; |
nerit | 0:1e09cd7d66b4 | 539 | } |
nerit | 0:1e09cd7d66b4 | 540 | } |
nerit | 0:1e09cd7d66b4 | 541 | |
nerit | 0:1e09cd7d66b4 | 542 | } |
nerit | 0:1e09cd7d66b4 | 543 | if (rxMsg.id==RX_Settings){ |
nerit | 0:1e09cd7d66b4 | 544 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 545 | pickNumber = rxMsg.data[0]; // numero di becchi installati sulla ruota di semina |
nerit | 0:1e09cd7d66b4 | 546 | cellsNumber = rxMsg.data[1]; // numero di celle del tamburo |
nerit | 0:1e09cd7d66b4 | 547 | deepOfSeed=(rxMsg.data[2]/10000.0f); // deep of seeding |
nerit | 0:1e09cd7d66b4 | 548 | seedWheelDiameter = ((rxMsg.data[4]*0xFF)+rxMsg.data[3])/10000.0f; // seed wheel diameter setting |
nerit | 0:1e09cd7d66b4 | 549 | speedWheelDiameter = ((rxMsg.data[6]*0xFF)+rxMsg.data[5])/10000.0f; // variable for tractor speed calculation (need to be set from UI) ( Unit= meters ) |
nerit | 0:1e09cd7d66b4 | 550 | speedWheelPulse = rxMsg.data[7]; // variable which define the number of pulse each turn of tractor speed wheel (need to be set from UI) |
nerit | 0:1e09cd7d66b4 | 551 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 552 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 553 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 554 | pc.printf("Seed wheel diameter %f \n",seedWheelDiameter); |
nerit | 0:1e09cd7d66b4 | 555 | pc.printf("Speed wheel diameter %f \n",speedWheelDiameter); |
nerit | 0:1e09cd7d66b4 | 556 | #endif |
nerit | 0:1e09cd7d66b4 | 557 | #endif |
nerit | 0:1e09cd7d66b4 | 558 | } |
nerit | 0:1e09cd7d66b4 | 559 | } |
nerit | 0:1e09cd7d66b4 | 560 | if (rxMsg.id==RX_AngoloPh){ |
nerit | 0:1e09cd7d66b4 | 561 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 562 | #if defined(M1) |
nerit | 0:1e09cd7d66b4 | 563 | angoloPh = (double) rxMsg.data[0] ; |
nerit | 0:1e09cd7d66b4 | 564 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 565 | #endif |
nerit | 0:1e09cd7d66b4 | 566 | #if defined(M2) |
nerit | 0:1e09cd7d66b4 | 567 | angoloPh = (double) rxMsg.data[1] ; |
nerit | 0:1e09cd7d66b4 | 568 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 569 | #endif |
nerit | 0:1e09cd7d66b4 | 570 | #if defined(M3) |
nerit | 0:1e09cd7d66b4 | 571 | angoloPh = (double) rxMsg.data[2] ; |
nerit | 0:1e09cd7d66b4 | 572 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 573 | #endif |
nerit | 0:1e09cd7d66b4 | 574 | #if defined(M4) |
nerit | 0:1e09cd7d66b4 | 575 | angoloPh = (double) rxMsg.data[3] ; |
nerit | 0:1e09cd7d66b4 | 576 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 577 | #endif |
nerit | 0:1e09cd7d66b4 | 578 | #if defined(M5) |
nerit | 0:1e09cd7d66b4 | 579 | angoloPh = (double) rxMsg.data[4] ; |
nerit | 0:1e09cd7d66b4 | 580 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 581 | #endif |
nerit | 0:1e09cd7d66b4 | 582 | #if defined(M6) |
nerit | 0:1e09cd7d66b4 | 583 | angoloPh = (double) rxMsg.data[5] ; |
nerit | 0:1e09cd7d66b4 | 584 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 585 | #endif |
nerit | 0:1e09cd7d66b4 | 586 | } |
nerit | 0:1e09cd7d66b4 | 587 | } |
nerit | 0:1e09cd7d66b4 | 588 | if (rxMsg.id==RX_AngoloAv){ |
nerit | 0:1e09cd7d66b4 | 589 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 590 | #if defined(M1) |
nerit | 0:1e09cd7d66b4 | 591 | angoloAv = (double) rxMsg.data[0] ; |
nerit | 0:1e09cd7d66b4 | 592 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 593 | #endif |
nerit | 0:1e09cd7d66b4 | 594 | #if defined(M2) |
nerit | 0:1e09cd7d66b4 | 595 | angoloAv = (double) rxMsg.data[1] ; |
nerit | 0:1e09cd7d66b4 | 596 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 597 | #endif |
nerit | 0:1e09cd7d66b4 | 598 | #if defined(M3) |
nerit | 0:1e09cd7d66b4 | 599 | angoloAv = (double) rxMsg.data[2] ; |
nerit | 0:1e09cd7d66b4 | 600 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 601 | #endif |
nerit | 0:1e09cd7d66b4 | 602 | #if defined(M4) |
nerit | 0:1e09cd7d66b4 | 603 | angoloAv = (double) rxMsg.data[3] ; |
nerit | 0:1e09cd7d66b4 | 604 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 605 | #endif |
nerit | 0:1e09cd7d66b4 | 606 | #if defined(M5) |
nerit | 0:1e09cd7d66b4 | 607 | angoloAv = (double) rxMsg.data[4] ; |
nerit | 0:1e09cd7d66b4 | 608 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 609 | #endif |
nerit | 0:1e09cd7d66b4 | 610 | #if defined(M6) |
nerit | 0:1e09cd7d66b4 | 611 | angoloAv = (double) rxMsg.data[5] ; |
nerit | 0:1e09cd7d66b4 | 612 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 613 | #endif |
nerit | 0:1e09cd7d66b4 | 614 | } |
nerit | 0:1e09cd7d66b4 | 615 | } |
nerit | 0:1e09cd7d66b4 | 616 | if (rxMsg.id==RX_Quinconce){ |
nerit | 0:1e09cd7d66b4 | 617 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 618 | quinconceActive = (uint8_t) rxMsg.data[0]; |
nerit | 0:1e09cd7d66b4 | 619 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 620 | } |
nerit | 0:1e09cd7d66b4 | 621 | } |
nerit | 0:1e09cd7d66b4 | 622 | if (rxMsg.id==RX_QuincSinc){ |
nerit | 0:1e09cd7d66b4 | 623 | masterSinc = (uint32_t) rxMsg.data[0] * 0x00FF0000; |
nerit | 0:1e09cd7d66b4 | 624 | masterSinc = masterSinc + ((uint32_t) rxMsg.data[1] * 0x0000FF00); |
nerit | 0:1e09cd7d66b4 | 625 | masterSinc = masterSinc + ((uint32_t) rxMsg.data[2] * 0x000000FF); |
nerit | 0:1e09cd7d66b4 | 626 | masterSinc = masterSinc + ((uint32_t) rxMsg.data[3]); |
nerit | 0:1e09cd7d66b4 | 627 | } |
nerit | 0:1e09cd7d66b4 | 628 | } |
nerit | 0:1e09cd7d66b4 | 629 | #endif |
nerit | 0:1e09cd7d66b4 | 630 | #if defined(overWriteCanSimulation) |
nerit | 0:1e09cd7d66b4 | 631 | enableSimula=1; |
nerit | 0:1e09cd7d66b4 | 632 | speedSimula=25; |
nerit | 0:1e09cd7d66b4 | 633 | avviaSimula=1; |
nerit | 0:1e09cd7d66b4 | 634 | simOk=1; |
nerit | 0:1e09cd7d66b4 | 635 | #endif |
nerit | 0:1e09cd7d66b4 | 636 | |
nerit | 0:1e09cd7d66b4 | 637 | } |
nerit | 0:1e09cd7d66b4 | 638 | |
nerit | 0:1e09cd7d66b4 | 639 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 640 | void DC_CheckCurrent(){ |
nerit | 0:1e09cd7d66b4 | 641 | |
nerit | 0:1e09cd7d66b4 | 642 | // TODO: tabella di riferimento assorbimenti alle varie velocità al fine di gestire |
nerit | 0:1e09cd7d66b4 | 643 | // gli allarmi e le correzioni di velocità |
nerit | 0:1e09cd7d66b4 | 644 | |
nerit | 0:1e09cd7d66b4 | 645 | //float SD_analogMatrix[10]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; |
nerit | 0:1e09cd7d66b4 | 646 | //int SD_analogIndex[10]={0,0,0,0,0,0,0,0,0,0}; |
nerit | 0:1e09cd7d66b4 | 647 | // Analog reading |
nerit | 0:1e09cd7d66b4 | 648 | //number = floor(number * 100) / 100; |
nerit | 0:1e09cd7d66b4 | 649 | //if (pwmCheck==1){ |
nerit | 0:1e09cd7d66b4 | 650 | timeout.detach(); |
nerit | 0:1e09cd7d66b4 | 651 | for (int ii=1;ii<20;ii++){ |
nerit | 0:1e09cd7d66b4 | 652 | SD_analogMatrix[ii]=SD_analogMatrix[ii+1]; |
nerit | 0:1e09cd7d66b4 | 653 | } |
nerit | 0:1e09cd7d66b4 | 654 | SD_CurrentAnalog = floor(SDcurrent.read()*100)/100; // valore in ingresso compreso tra 0.00 e 1.00 |
nerit | 0:1e09cd7d66b4 | 655 | SD_analogMatrix[20]=SD_CurrentAnalog; |
nerit | 0:1e09cd7d66b4 | 656 | if (SDmotorPWM==0.0f){ |
nerit | 0:1e09cd7d66b4 | 657 | SD_CurrentStart=SD_CurrentAnalog; |
nerit | 0:1e09cd7d66b4 | 658 | } |
nerit | 0:1e09cd7d66b4 | 659 | float sommaTutto=0.0f; |
nerit | 0:1e09cd7d66b4 | 660 | for (int ii=1;ii<21;ii++){ |
nerit | 0:1e09cd7d66b4 | 661 | sommaTutto=sommaTutto+SD_analogMatrix[ii]; |
nerit | 0:1e09cd7d66b4 | 662 | } |
nerit | 0:1e09cd7d66b4 | 663 | float SD_CurrentAnalogica=sommaTutto/20.0f; |
nerit | 0:1e09cd7d66b4 | 664 | SD_CurrentScaled = floor(( (SD_CurrentAnalogica - SD_CurrentStart)*3.3f) / (SD_CurrentFactor/1000.0f)*10)/10; |
nerit | 0:1e09cd7d66b4 | 665 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 666 | #if defined(correnteAssorbita) |
nerit | 0:1e09cd7d66b4 | 667 | pc.printf("CorrenteStart: %f ",SD_CurrentStart); |
nerit | 0:1e09cd7d66b4 | 668 | pc.printf(" CorrenteScaled: %f ",SD_CurrentScaled); |
nerit | 0:1e09cd7d66b4 | 669 | pc.printf(" CorrenteMedia: %f \n",SD_CurrentAnalogica); |
nerit | 0:1e09cd7d66b4 | 670 | #endif |
nerit | 0:1e09cd7d66b4 | 671 | #endif |
nerit | 0:1e09cd7d66b4 | 672 | reduceCurrent=false; |
nerit | 0:1e09cd7d66b4 | 673 | incrementCurrent=false; |
nerit | 0:1e09cd7d66b4 | 674 | /* |
nerit | 0:1e09cd7d66b4 | 675 | if (SD_CurrentScaled < 3.0f){ |
nerit | 0:1e09cd7d66b4 | 676 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 677 | all_lowBattery=1; |
nerit | 0:1e09cd7d66b4 | 678 | #endif |
nerit | 0:1e09cd7d66b4 | 679 | incrementCurrent=true; |
nerit | 0:1e09cd7d66b4 | 680 | } |
nerit | 0:1e09cd7d66b4 | 681 | */ |
nerit | 0:1e09cd7d66b4 | 682 | if (SD_CurrentScaled > 13.0f){ |
nerit | 0:1e09cd7d66b4 | 683 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 684 | all_overCurrDC=1; |
nerit | 0:1e09cd7d66b4 | 685 | #endif |
nerit | 0:1e09cd7d66b4 | 686 | reduceCurrent=true; |
nerit | 0:1e09cd7d66b4 | 687 | } |
nerit | 0:1e09cd7d66b4 | 688 | //} |
nerit | 0:1e09cd7d66b4 | 689 | } |
nerit | 0:1e09cd7d66b4 | 690 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 691 | void DC_prepare(){ |
nerit | 0:1e09cd7d66b4 | 692 | // direction or brake preparation |
nerit | 0:1e09cd7d66b4 | 693 | if (DC_brake==1){SDmotorInA=1;SDmotorInB=1;}else{if (DC_forward==1){SDmotorInA=1;SDmotorInB=0;}else{SDmotorInA=0;SDmotorInB=1;}} |
nerit | 0:1e09cd7d66b4 | 694 | // fault reading |
nerit | 0:1e09cd7d66b4 | 695 | if (SDmotorInA==1){SD_faultA=1;}else{SD_faultA=0;} |
nerit | 0:1e09cd7d66b4 | 696 | if (SDmotorInB==1){SD_faultB=1;}else{SD_faultB=0;} |
nerit | 0:1e09cd7d66b4 | 697 | } |
nerit | 0:1e09cd7d66b4 | 698 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 699 | void startDelay(){ |
nerit | 0:1e09cd7d66b4 | 700 | int ritardo =0; |
nerit | 0:1e09cd7d66b4 | 701 | ritardo = (int)((float)(dcActualDuty*800.0f)); |
nerit | 0:1e09cd7d66b4 | 702 | timeout.attach_us(&DC_CheckCurrent,ritardo); |
nerit | 0:1e09cd7d66b4 | 703 | } |
nerit | 0:1e09cd7d66b4 | 704 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 705 | void quincTrigga(){ |
nerit | 0:1e09cd7d66b4 | 706 | if (quinconceIn==1){ |
nerit | 0:1e09cd7d66b4 | 707 | quincClock=true; |
nerit | 0:1e09cd7d66b4 | 708 | }else{ |
nerit | 0:1e09cd7d66b4 | 709 | quincClock=false; |
nerit | 0:1e09cd7d66b4 | 710 | } |
nerit | 0:1e09cd7d66b4 | 711 | } |
nerit | 0:1e09cd7d66b4 | 712 | //******************************************************* |
nerit | 2:d9c7430ae953 | 713 | void quinCalc(){ |
nerit | 0:1e09cd7d66b4 | 714 | // riceve l'impulso di sincro dal master e fa partire il timer di verifica dell'errore |
nerit | 2:d9c7430ae953 | 715 | #if !defined(mezzo) |
nerit | 0:1e09cd7d66b4 | 716 | if ((quincClock==true)&&(oldQuincIn==0)){ |
nerit | 0:1e09cd7d66b4 | 717 | oldQuincIn=1; |
nerit | 1:e88bf5011af6 | 718 | oldQuincTimeSD = (double) quincTimeSD.read_ms(); |
nerit | 0:1e09cd7d66b4 | 719 | if (quincStart==0){ |
nerit | 0:1e09cd7d66b4 | 720 | quincTime.reset(); |
nerit | 0:1e09cd7d66b4 | 721 | quincStart=1; |
nerit | 0:1e09cd7d66b4 | 722 | } |
nerit | 0:1e09cd7d66b4 | 723 | } |
nerit | 2:d9c7430ae953 | 724 | if(quincClock==false){ |
nerit | 0:1e09cd7d66b4 | 725 | oldQuincIn=0; |
nerit | 0:1e09cd7d66b4 | 726 | } |
nerit | 2:d9c7430ae953 | 727 | #else |
nerit | 2:d9c7430ae953 | 728 | if ((((quinconceActive==0)&&(quincClock==true))||((quinconceActive==1)&&(quincClock==false)))&&(oldQuincIn==0)){ |
nerit | 0:1e09cd7d66b4 | 729 | oldQuincIn=1; |
nerit | 1:e88bf5011af6 | 730 | oldQuincTimeSD = (double) quincTimeSD.read_ms(); |
nerit | 0:1e09cd7d66b4 | 731 | if (quincStart==0){ |
nerit | 0:1e09cd7d66b4 | 732 | quincTime.reset(); |
nerit | 0:1e09cd7d66b4 | 733 | quincStart=1; |
nerit | 0:1e09cd7d66b4 | 734 | } |
nerit | 0:1e09cd7d66b4 | 735 | } |
nerit | 2:d9c7430ae953 | 736 | if((((quincClock==false)&&(quinconceActive==0))||((quincClock==true)&&(quinconceActive==1)))){ |
nerit | 0:1e09cd7d66b4 | 737 | oldQuincIn=0; |
nerit | 0:1e09cd7d66b4 | 738 | } |
nerit | 2:d9c7430ae953 | 739 | #endif |
nerit | 0:1e09cd7d66b4 | 740 | // riceve l'impulso di passaggio del becco locale e determina il valore dell'errore |
nerit | 0:1e09cd7d66b4 | 741 | // controllo di linea e di quinconcio |
nerit | 2:d9c7430ae953 | 742 | if ((quincStart==1)&&(SDzeroDebounced==1)){ |
nerit | 2:d9c7430ae953 | 743 | quincStart=0; |
nerit | 2:d9c7430ae953 | 744 | percento=1.0f; |
nerit | 2:d9c7430ae953 | 745 | scostamento = (double)quincTime.read_ms(); |
nerit | 2:d9c7430ae953 | 746 | scostamento2 = oldQuincTimeSD; |
nerit | 3:c0f11ca4df02 | 747 | double pippo = 0.025f-((tractorSpeed_MtS_timed/1.25f)*0.02f); |
nerit | 2:d9c7430ae953 | 748 | double halfPippo= tempoTraBecchi_mS/2.0f; |
nerit | 3:c0f11ca4df02 | 749 | if ((scostamento2 > 1.0f)&&(scostamento2<halfPippo)){ |
nerit | 3:c0f11ca4df02 | 750 | percento = 1.0f+(pippo);///3.0f); |
nerit | 3:c0f11ca4df02 | 751 | }else if ((scostamento > 1.0f)&&(scostamento<halfPippo)){ |
nerit | 3:c0f11ca4df02 | 752 | percento = 1.0f-(pippo);///1.0f); |
nerit | 2:d9c7430ae953 | 753 | } |
nerit | 2:d9c7430ae953 | 754 | if (abs(percento) > 1.15f){percento=1.15f;} |
nerit | 2:d9c7430ae953 | 755 | if (abs(percento) < 0.80f){percento=0.80f;} |
nerit | 2:d9c7430ae953 | 756 | #if defined(pcSerial) |
nerit | 2:d9c7430ae953 | 757 | #if defined(Qnc) |
nerit | 2:d9c7430ae953 | 758 | pc.printf(" s1: %f", scostamento); |
nerit | 2:d9c7430ae953 | 759 | pc.printf(" s2: %f", scostamento2); |
nerit | 2:d9c7430ae953 | 760 | pc.printf(" pc: %f", percento); |
nerit | 3:c0f11ca4df02 | 761 | pc.printf(" en: %d\n",quinconceActive); |
nerit | 1:e88bf5011af6 | 762 | #endif |
nerit | 2:d9c7430ae953 | 763 | #endif |
nerit | 0:1e09cd7d66b4 | 764 | } |
nerit | 0:1e09cd7d66b4 | 765 | } |
nerit | 0:1e09cd7d66b4 | 766 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
nerit | 0:1e09cd7d66b4 | 767 | // MAIN SECTION |
nerit | 3:c0f11ca4df02 | 768 | // --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
nerit | 0:1e09cd7d66b4 | 769 | |
nerit | 0:1e09cd7d66b4 | 770 | int main() |
nerit | 0:1e09cd7d66b4 | 771 | { |
nerit | 0:1e09cd7d66b4 | 772 | wd.Configure(2); //watchdog set at xx seconds |
nerit | 0:1e09cd7d66b4 | 773 | |
nerit | 0:1e09cd7d66b4 | 774 | for (int a=0; a<5;a++){ |
nerit | 0:1e09cd7d66b4 | 775 | mediaSpeed[a]=0; |
nerit | 0:1e09cd7d66b4 | 776 | } |
nerit | 0:1e09cd7d66b4 | 777 | |
nerit | 0:1e09cd7d66b4 | 778 | // Stepper driver init and set |
nerit | 0:1e09cd7d66b4 | 779 | TBmotorRst=0; // reset stepper driver |
nerit | 0:1e09cd7d66b4 | 780 | TBmotorDirecti=0; // reset stepper direction |
nerit | 0:1e09cd7d66b4 | 781 | // M1 M2 M3 RESOLUTION |
nerit | 0:1e09cd7d66b4 | 782 | // 0 0 0 1/2 |
nerit | 0:1e09cd7d66b4 | 783 | // 1 0 0 1/8 |
nerit | 0:1e09cd7d66b4 | 784 | // 0 1 0 1/16 |
nerit | 0:1e09cd7d66b4 | 785 | // 1 1 0 1/32 |
nerit | 0:1e09cd7d66b4 | 786 | // 0 0 1 1/64 |
nerit | 0:1e09cd7d66b4 | 787 | // 1 0 1 1/128 |
nerit | 0:1e09cd7d66b4 | 788 | // 0 1 1 1/10 |
nerit | 0:1e09cd7d66b4 | 789 | // 1 1 1 1/20 |
nerit | 0:1e09cd7d66b4 | 790 | if (TBmotorSteps==400){ |
nerit | 0:1e09cd7d66b4 | 791 | TBmotor_M1=0; |
nerit | 0:1e09cd7d66b4 | 792 | TBmotor_M2=0; |
nerit | 0:1e09cd7d66b4 | 793 | TBmotor_M3=0; |
nerit | 0:1e09cd7d66b4 | 794 | }else if (TBmotorSteps==1600){ |
nerit | 0:1e09cd7d66b4 | 795 | TBmotor_M1=1; |
nerit | 0:1e09cd7d66b4 | 796 | TBmotor_M2=0; |
nerit | 0:1e09cd7d66b4 | 797 | TBmotor_M3=0; |
nerit | 0:1e09cd7d66b4 | 798 | }else if (TBmotorSteps==3200){ |
nerit | 0:1e09cd7d66b4 | 799 | TBmotor_M1=0; |
nerit | 0:1e09cd7d66b4 | 800 | TBmotor_M2=1; |
nerit | 0:1e09cd7d66b4 | 801 | TBmotor_M3=0; |
nerit | 0:1e09cd7d66b4 | 802 | }else if (TBmotorSteps==6400){ |
nerit | 0:1e09cd7d66b4 | 803 | TBmotor_M1=1; |
nerit | 0:1e09cd7d66b4 | 804 | TBmotor_M2=1; |
nerit | 0:1e09cd7d66b4 | 805 | TBmotor_M3=0; |
nerit | 0:1e09cd7d66b4 | 806 | }else if (TBmotorSteps==12800){ |
nerit | 0:1e09cd7d66b4 | 807 | TBmotor_M1=0; |
nerit | 0:1e09cd7d66b4 | 808 | TBmotor_M2=0; |
nerit | 0:1e09cd7d66b4 | 809 | TBmotor_M3=1; |
nerit | 0:1e09cd7d66b4 | 810 | }else if (TBmotorSteps==25600){ |
nerit | 0:1e09cd7d66b4 | 811 | TBmotor_M1=1; |
nerit | 0:1e09cd7d66b4 | 812 | TBmotor_M2=0; |
nerit | 0:1e09cd7d66b4 | 813 | TBmotor_M3=1; |
nerit | 0:1e09cd7d66b4 | 814 | }else if (TBmotorSteps==2000){ |
nerit | 0:1e09cd7d66b4 | 815 | TBmotor_M1=0; |
nerit | 0:1e09cd7d66b4 | 816 | TBmotor_M2=1; |
nerit | 0:1e09cd7d66b4 | 817 | TBmotor_M3=1; |
nerit | 0:1e09cd7d66b4 | 818 | }else if (TBmotorSteps==4000){ |
nerit | 0:1e09cd7d66b4 | 819 | TBmotor_M1=1; |
nerit | 0:1e09cd7d66b4 | 820 | TBmotor_M2=1; |
nerit | 0:1e09cd7d66b4 | 821 | TBmotor_M3=1; |
nerit | 0:1e09cd7d66b4 | 822 | } |
nerit | 0:1e09cd7d66b4 | 823 | TBmotorRst=1; |
nerit | 0:1e09cd7d66b4 | 824 | |
nerit | 0:1e09cd7d66b4 | 825 | // DC reset ad set |
nerit | 0:1e09cd7d66b4 | 826 | int decima = 100; |
nerit | 0:1e09cd7d66b4 | 827 | wait_ms(200); |
nerit | 0:1e09cd7d66b4 | 828 | SD_CurrentStart=floor(SDcurrent.read()*decima)/decima; |
nerit | 0:1e09cd7d66b4 | 829 | wait_ms(2); |
nerit | 0:1e09cd7d66b4 | 830 | SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima; |
nerit | 0:1e09cd7d66b4 | 831 | wait_ms(1); |
nerit | 0:1e09cd7d66b4 | 832 | SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima; |
nerit | 0:1e09cd7d66b4 | 833 | wait_ms(3); |
nerit | 0:1e09cd7d66b4 | 834 | SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima; |
nerit | 0:1e09cd7d66b4 | 835 | SD_CurrentStart=(floor((SD_CurrentStart/4.0f)*decima)/decima)-0.01f; |
nerit | 0:1e09cd7d66b4 | 836 | wait_ms(100); |
nerit | 0:1e09cd7d66b4 | 837 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 838 | |
nerit | 0:1e09cd7d66b4 | 839 | speedTimer.start(); // speed pulse timer |
nerit | 0:1e09cd7d66b4 | 840 | intraPickTimer.start(); |
nerit | 0:1e09cd7d66b4 | 841 | speedTimeOut.start(); |
nerit | 0:1e09cd7d66b4 | 842 | speedFilter.start(); |
nerit | 0:1e09cd7d66b4 | 843 | seedFilter.start(); |
nerit | 0:1e09cd7d66b4 | 844 | TBfilter.start(); |
nerit | 0:1e09cd7d66b4 | 845 | sincroTimer.start(); |
nerit | 0:1e09cd7d66b4 | 846 | rotationTimeOut.start(); |
nerit | 0:1e09cd7d66b4 | 847 | metalTimer.start(); |
nerit | 0:1e09cd7d66b4 | 848 | quincTime.start(); |
nerit | 1:e88bf5011af6 | 849 | quincTimeSD.start(); |
nerit | 0:1e09cd7d66b4 | 850 | |
nerit | 0:1e09cd7d66b4 | 851 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 852 | // controls for check DC motor current |
nerit | 0:1e09cd7d66b4 | 853 | //currentCheck.attach(&DC_CheckCurrent, 0.10f); |
nerit | 0:1e09cd7d66b4 | 854 | pwmCheck.rise(&startDelay); |
nerit | 0:1e09cd7d66b4 | 855 | //tbCorrection.attach(&correction,0.1f; |
nerit | 0:1e09cd7d66b4 | 856 | |
nerit | 0:1e09cd7d66b4 | 857 | if (inProva==0){ |
nerit | 0:1e09cd7d66b4 | 858 | tractorSpeedRead.rise(&tractorReadSpeed); |
nerit | 0:1e09cd7d66b4 | 859 | #if !defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 860 | quinconceIn.rise(&quincTrigga); |
nerit | 0:1e09cd7d66b4 | 861 | quinconceIn.fall(&quincTrigga); |
nerit | 0:1e09cd7d66b4 | 862 | #endif |
nerit | 0:1e09cd7d66b4 | 863 | tftUpdate.attach(&videoUpdate,0.50f); |
nerit | 0:1e09cd7d66b4 | 864 | seedCorrection.attach(&seedCorrect,0.005f); // con 16 becchi a 4,5Kmh ci sono 37mS tra un becco e l'altro, quindi 8 correzioni di tb |
nerit | 0:1e09cd7d66b4 | 865 | if (speedFromPick==0){ |
nerit | 0:1e09cd7d66b4 | 866 | ElementPosition.rise(&sd25Fall); |
nerit | 0:1e09cd7d66b4 | 867 | } |
nerit | 0:1e09cd7d66b4 | 868 | }else{ |
nerit | 0:1e09cd7d66b4 | 869 | tftUpdate.attach(&videoUpdate,0.125f); |
nerit | 0:1e09cd7d66b4 | 870 | } |
nerit | 0:1e09cd7d66b4 | 871 | |
nerit | 0:1e09cd7d66b4 | 872 | aggiornaParametri(); |
nerit | 0:1e09cd7d66b4 | 873 | |
nerit | 0:1e09cd7d66b4 | 874 | SDmotorPWM.period_us(periodoSD); // frequency 1KHz pilotaggio motore DC |
nerit | 0:1e09cd7d66b4 | 875 | SDmotorPWM.write(0.0f); // duty cycle = stop |
nerit | 0:1e09cd7d66b4 | 876 | TBmotorDirecti=0; // tb motor direction set |
nerit | 0:1e09cd7d66b4 | 877 | |
nerit | 0:1e09cd7d66b4 | 878 | #if defined(provaStepper) |
nerit | 0:1e09cd7d66b4 | 879 | TBmotorRst=1; |
nerit | 0:1e09cd7d66b4 | 880 | TBticker.attach_us(&step_TBPulseOut,3000.0f); // clock time are seconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 881 | #endif // end prova stepper |
nerit | 0:1e09cd7d66b4 | 882 | |
nerit | 0:1e09cd7d66b4 | 883 | #if defined(canbusActive) |
nerit | 0:1e09cd7d66b4 | 884 | can1.attach(&leggiCAN, CAN::RxIrq); |
nerit | 0:1e09cd7d66b4 | 885 | #endif |
nerit | 0:1e09cd7d66b4 | 886 | |
nerit | 0:1e09cd7d66b4 | 887 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 888 | // MAIN LOOP |
nerit | 0:1e09cd7d66b4 | 889 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 890 | while (true){ |
nerit | 0:1e09cd7d66b4 | 891 | // ripetitore segnale di velocità |
nerit | 0:1e09cd7d66b4 | 892 | if (tractorSpeedRead==0){speedClock=0;} |
nerit | 0:1e09cd7d66b4 | 893 | |
nerit | 0:1e09cd7d66b4 | 894 | // inversione segnali ingressi |
nerit | 3:c0f11ca4df02 | 895 | seedWheelZeroPinInput = !seedWheelZeroPinInputRev; |
nerit | 0:1e09cd7d66b4 | 896 | TBzeroPinInput = !TBzeroPinInputRev; |
nerit | 0:1e09cd7d66b4 | 897 | |
nerit | 0:1e09cd7d66b4 | 898 | // se quinconce attivo ed unita' master invia segnale di sincro |
nerit | 0:1e09cd7d66b4 | 899 | #if defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 900 | if (seedWheelZeroPinInput==1){ |
nerit | 0:1e09cd7d66b4 | 901 | quinconceOut=1; |
nerit | 0:1e09cd7d66b4 | 902 | } |
nerit | 3:c0f11ca4df02 | 903 | if ((double)(prePosSD-500) >= (SDsectorStep/2.0f)){ |
nerit | 0:1e09cd7d66b4 | 904 | quinconceOut=0; |
nerit | 0:1e09cd7d66b4 | 905 | } |
nerit | 0:1e09cd7d66b4 | 906 | #endif |
nerit | 0:1e09cd7d66b4 | 907 | |
nerit | 0:1e09cd7d66b4 | 908 | #if defined(overWriteCanSimulation) |
nerit | 0:1e09cd7d66b4 | 909 | leggiCAN(); |
nerit | 0:1e09cd7d66b4 | 910 | #endif |
nerit | 0:1e09cd7d66b4 | 911 | |
nerit | 0:1e09cd7d66b4 | 912 | // simulazione velocita |
nerit | 0:1e09cd7d66b4 | 913 | if (enableSimula==1){ |
nerit | 0:1e09cd7d66b4 | 914 | double TMT = 0.0f; |
nerit | 0:1e09cd7d66b4 | 915 | if (speedSimula > 0){ |
nerit | 0:1e09cd7d66b4 | 916 | TMT = (double)(speedSimula) * 100.0f /3600.0f; |
nerit | 0:1e09cd7d66b4 | 917 | pulseSpeedInterval = pulseDistance / TMT; |
nerit | 0:1e09cd7d66b4 | 918 | }else{ |
nerit | 0:1e09cd7d66b4 | 919 | pulseSpeedInterval = 10000.0f; |
nerit | 0:1e09cd7d66b4 | 920 | } |
nerit | 0:1e09cd7d66b4 | 921 | if (avviaSimula==1){ |
nerit | 0:1e09cd7d66b4 | 922 | if(oldSimulaSpeed!=pulseSpeedInterval){ |
nerit | 0:1e09cd7d66b4 | 923 | spedSimclock.attach_us(&speedSimulationClock,pulseSpeedInterval); |
nerit | 0:1e09cd7d66b4 | 924 | oldSimulaSpeed=pulseSpeedInterval; |
nerit | 0:1e09cd7d66b4 | 925 | } |
nerit | 0:1e09cd7d66b4 | 926 | }else{ |
nerit | 0:1e09cd7d66b4 | 927 | oldSimulaSpeed=10000.0f; |
nerit | 0:1e09cd7d66b4 | 928 | spedSimclock.detach(); |
nerit | 0:1e09cd7d66b4 | 929 | } |
nerit | 0:1e09cd7d66b4 | 930 | }else{ |
nerit | 0:1e09cd7d66b4 | 931 | spedSimclock.detach(); |
nerit | 0:1e09cd7d66b4 | 932 | } |
nerit | 0:1e09cd7d66b4 | 933 | |
nerit | 0:1e09cd7d66b4 | 934 | //******************************************************* |
nerit | 0:1e09cd7d66b4 | 935 | // determina se sono in bassa velocità per il controllo di TB |
nerit | 0:1e09cd7d66b4 | 936 | if (speedOfSeedWheel<=minSeedSpeed){ |
nerit | 0:1e09cd7d66b4 | 937 | if (lowSpeedRequired==0){ |
nerit | 0:1e09cd7d66b4 | 938 | ritardaLowSpeed.reset(); |
nerit | 0:1e09cd7d66b4 | 939 | ritardaLowSpeed.start(); |
nerit | 0:1e09cd7d66b4 | 940 | } |
nerit | 0:1e09cd7d66b4 | 941 | lowSpeedRequired=1; |
nerit | 0:1e09cd7d66b4 | 942 | }else{ |
nerit | 0:1e09cd7d66b4 | 943 | if (lowSpeedRequired==1){ |
nerit | 0:1e09cd7d66b4 | 944 | lowSpeedRequired=0; |
nerit | 0:1e09cd7d66b4 | 945 | ritardaLowSpeed.reset(); |
nerit | 0:1e09cd7d66b4 | 946 | ritardaLowSpeed.stop(); |
nerit | 0:1e09cd7d66b4 | 947 | } |
nerit | 0:1e09cd7d66b4 | 948 | } |
nerit | 0:1e09cd7d66b4 | 949 | |
nerit | 0:1e09cd7d66b4 | 950 | if (ritardaLowSpeed.read_ms()> 2000){ |
nerit | 0:1e09cd7d66b4 | 951 | lowSpeed=1; |
nerit | 0:1e09cd7d66b4 | 952 | }else{ |
nerit | 0:1e09cd7d66b4 | 953 | lowSpeed=0; |
nerit | 0:1e09cd7d66b4 | 954 | } |
nerit | 0:1e09cd7d66b4 | 955 | |
nerit | 0:1e09cd7d66b4 | 956 | |
nerit | 0:1e09cd7d66b4 | 957 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 958 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 959 | // LOGICAL CONTROLS |
nerit | 0:1e09cd7d66b4 | 960 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 961 | //************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 962 | |
nerit | 0:1e09cd7d66b4 | 963 | if (inProva==0){ |
nerit | 0:1e09cd7d66b4 | 964 | if ((startCycleSimulation==0)&&(enableSimula==0)){zeroRequestBuf=1;runRequestBuf=0;enableCycle=1; |
nerit | 0:1e09cd7d66b4 | 965 | }else{zeroRequestBuf=1;runRequestBuf=0;enableCycle=1;} |
nerit | 0:1e09cd7d66b4 | 966 | if ((tractorSpeedRead==0)&&(speedFilter.read_ms()>3)){oldTractorSpeedRead=0;} |
nerit | 0:1e09cd7d66b4 | 967 | // ---------------------------------------- |
nerit | 0:1e09cd7d66b4 | 968 | // filtra il segnale dei becchi per misurare il tempo di intervallo tra loro |
nerit | 0:1e09cd7d66b4 | 969 | // ---------------------------------------- |
nerit | 0:1e09cd7d66b4 | 970 | if (seedWheelZeroPinInput==0){ |
nerit | 0:1e09cd7d66b4 | 971 | if(seedFilter.read_ms()>=4){ |
nerit | 0:1e09cd7d66b4 | 972 | oldSeedWheelZeroPinInput=0; |
nerit | 0:1e09cd7d66b4 | 973 | SDzeroDebounced=0; |
nerit | 0:1e09cd7d66b4 | 974 | } |
nerit | 0:1e09cd7d66b4 | 975 | } |
nerit | 0:1e09cd7d66b4 | 976 | if ((seedWheelZeroPinInput==1)&&(oldSeedWheelZeroPinInput==0)){ |
nerit | 0:1e09cd7d66b4 | 977 | timeIntraPick = (double)intraPickTimer.read_ms(); |
nerit | 0:1e09cd7d66b4 | 978 | prePosSD=500; // preposizionamento SD |
nerit | 0:1e09cd7d66b4 | 979 | intraPickTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 980 | rotationTimeOut.reset(); |
nerit | 0:1e09cd7d66b4 | 981 | seedFilter.reset(); |
nerit | 0:1e09cd7d66b4 | 982 | sincroTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 983 | oldSeedWheelZeroPinInput=1; |
nerit | 1:e88bf5011af6 | 984 | quincTimeSD.reset(); |
nerit | 0:1e09cd7d66b4 | 985 | SDzeroDebounced=1; |
nerit | 0:1e09cd7d66b4 | 986 | SDwheelTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 987 | if (quincCnt<10){ |
nerit | 0:1e09cd7d66b4 | 988 | quincCnt++; |
nerit | 0:1e09cd7d66b4 | 989 | } |
nerit | 1:e88bf5011af6 | 990 | if (quincCnt >9){ |
nerit | 0:1e09cd7d66b4 | 991 | quincEnable=1; |
nerit | 0:1e09cd7d66b4 | 992 | }else{ |
nerit | 0:1e09cd7d66b4 | 993 | quincEnable=0; |
nerit | 0:1e09cd7d66b4 | 994 | } |
nerit | 1:e88bf5011af6 | 995 | if (cntQuinc<10){ |
nerit | 1:e88bf5011af6 | 996 | cntQuinc++; |
nerit | 1:e88bf5011af6 | 997 | } |
nerit | 0:1e09cd7d66b4 | 998 | if ((aspettaStart==0)&&(lowSpeed==1)){ |
nerit | 0:1e09cd7d66b4 | 999 | beccoPronto=1; |
nerit | 0:1e09cd7d66b4 | 1000 | } |
nerit | 0:1e09cd7d66b4 | 1001 | SDzeroCyclePulse=1; |
nerit | 0:1e09cd7d66b4 | 1002 | lockStart=0; |
nerit | 0:1e09cd7d66b4 | 1003 | double fase1=0.0f; |
nerit | 0:1e09cd7d66b4 | 1004 | forzaFase=0; |
nerit | 0:1e09cd7d66b4 | 1005 | double limite=fixedStepGiroSD/pickNumber; |
nerit | 0:1e09cd7d66b4 | 1006 | if (pickCounterLow< 0xFF){ |
nerit | 0:1e09cd7d66b4 | 1007 | pickCounterLow++; |
nerit | 0:1e09cd7d66b4 | 1008 | }else{ |
nerit | 0:1e09cd7d66b4 | 1009 | pickCounterHig++; |
nerit | 0:1e09cd7d66b4 | 1010 | pickCounterLow=0; |
nerit | 0:1e09cd7d66b4 | 1011 | } |
nerit | 0:1e09cd7d66b4 | 1012 | if (tamburoStandard==0){ |
nerit | 0:1e09cd7d66b4 | 1013 | fase1=TBdeltaStep; |
nerit | 0:1e09cd7d66b4 | 1014 | }else{ |
nerit | 0:1e09cd7d66b4 | 1015 | if(speedForCorrection >= speedOfSeedWheel){ |
nerit | 0:1e09cd7d66b4 | 1016 | fase1=TBdeltaStep; |
nerit | 0:1e09cd7d66b4 | 1017 | }else{ |
nerit | 0:1e09cd7d66b4 | 1018 | //fase1=(TBdeltaStep)-(((speedOfSeedWheel-speedForCorrection)/1.25f)*(TBfaseStep)); |
nerit | 0:1e09cd7d66b4 | 1019 | fase1=(TBdeltaStep)-(((speedOfSeedWheel)/1.25f)*(TBfaseStep)); |
nerit | 0:1e09cd7d66b4 | 1020 | } |
nerit | 0:1e09cd7d66b4 | 1021 | if (fase1 > limite){ |
nerit | 0:1e09cd7d66b4 | 1022 | fase1 -= limite; // se la fase calcolata supera gli step del settore riporta il valore nell'arco precedente (es. fase 1 800, limite 750, risulta 50) |
nerit | 0:1e09cd7d66b4 | 1023 | //forzaFase=1; |
nerit | 0:1e09cd7d66b4 | 1024 | } |
nerit | 0:1e09cd7d66b4 | 1025 | if ((fase1 > (limite -20.0f))&&(fase1<(limite +5.0f))){ |
nerit | 0:1e09cd7d66b4 | 1026 | fase1 = limite -20.0f; // se la fase è molto vicina al limite interpone uno spazio minimo di lavoro del sincronismo |
nerit | 0:1e09cd7d66b4 | 1027 | forzaFase=1; |
nerit | 0:1e09cd7d66b4 | 1028 | } |
nerit | 0:1e09cd7d66b4 | 1029 | trigRepos=1; |
nerit | 0:1e09cd7d66b4 | 1030 | } |
nerit | 0:1e09cd7d66b4 | 1031 | fase = (uint32_t)fase1+500; |
nerit | 0:1e09cd7d66b4 | 1032 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1033 | #if defined(inCorre) |
nerit | 0:1e09cd7d66b4 | 1034 | pc.printf(" limite %f", limite); |
nerit | 0:1e09cd7d66b4 | 1035 | pc.printf(" delta %f", TBdeltaStep); |
nerit | 0:1e09cd7d66b4 | 1036 | pc.printf(" faseStep %f", TBfaseStep); |
nerit | 0:1e09cd7d66b4 | 1037 | pc.printf(" fase %d",fase); |
nerit | 0:1e09cd7d66b4 | 1038 | pc.printf(" forzaFase %d",forzaFase); |
nerit | 0:1e09cd7d66b4 | 1039 | pc.printf(" trigRepos %d", trigRepos); |
nerit | 0:1e09cd7d66b4 | 1040 | pc.printf(" ActualSD: %d",SDactualPosition); |
nerit | 0:1e09cd7d66b4 | 1041 | pc.printf(" SpeedWheel: %f",speedOfSeedWheel); |
nerit | 0:1e09cd7d66b4 | 1042 | pc.printf(" SPEED: %f \n",tractorSpeed_MtS_timed); |
nerit | 0:1e09cd7d66b4 | 1043 | #endif |
nerit | 0:1e09cd7d66b4 | 1044 | #endif |
nerit | 0:1e09cd7d66b4 | 1045 | if (timeIntraPick >= (memoIntraPick*2)){ |
nerit | 0:1e09cd7d66b4 | 1046 | if ((aspettaStart==0)&&(zeroRequestBuf==0)){ |
nerit | 0:1e09cd7d66b4 | 1047 | if (firstStart==0){ |
nerit | 0:1e09cd7d66b4 | 1048 | all_pickSignal=1; |
nerit | 0:1e09cd7d66b4 | 1049 | } |
nerit | 0:1e09cd7d66b4 | 1050 | } |
nerit | 0:1e09cd7d66b4 | 1051 | } |
nerit | 0:1e09cd7d66b4 | 1052 | memoIntraPick = timeIntraPick; |
nerit | 0:1e09cd7d66b4 | 1053 | if (speedFromPick==1){ |
nerit | 0:1e09cd7d66b4 | 1054 | speedOfSeedWheel=((seedPerimeter / pickNumber)/timeIntraPick)*1000.0f; |
nerit | 0:1e09cd7d66b4 | 1055 | } |
nerit | 0:1e09cd7d66b4 | 1056 | if ((tractorSpeed_MtS_timed==0.0f)&&(zeroCycle==0)&&(zeroCycleEnd==1)){ |
nerit | 0:1e09cd7d66b4 | 1057 | if ((firstStart==0)&&(simOk==0)&&(enableSimula==0)&&(zeroCycleEnd==1)){ |
nerit | 0:1e09cd7d66b4 | 1058 | all_noSpeedSen=1; |
nerit | 0:1e09cd7d66b4 | 1059 | } |
nerit | 0:1e09cd7d66b4 | 1060 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1061 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 1062 | pc.printf("allarme no speed sensor"); |
nerit | 0:1e09cd7d66b4 | 1063 | #endif |
nerit | 0:1e09cd7d66b4 | 1064 | #endif |
nerit | 0:1e09cd7d66b4 | 1065 | } |
nerit | 0:1e09cd7d66b4 | 1066 | pulseRised2=1; |
nerit | 0:1e09cd7d66b4 | 1067 | #if defined(speedMaster) |
nerit | 0:1e09cd7d66b4 | 1068 | double oldLastPr = (double)oldLastPulseRead*1.2f; |
nerit | 0:1e09cd7d66b4 | 1069 | if((double)speedTimeOut.read_us()> (oldLastPr)){ |
nerit | 0:1e09cd7d66b4 | 1070 | if ((firstStart==0)&&(simOk==0)&&(enableSimula==0)&&(zeroCycleEnd==1)){ |
nerit | 0:1e09cd7d66b4 | 1071 | all_speedError =1; |
nerit | 0:1e09cd7d66b4 | 1072 | } |
nerit | 0:1e09cd7d66b4 | 1073 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1074 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 1075 | pc.printf("allarme errore speed sensor"); |
nerit | 0:1e09cd7d66b4 | 1076 | #endif |
nerit | 0:1e09cd7d66b4 | 1077 | #endif |
nerit | 0:1e09cd7d66b4 | 1078 | |
nerit | 0:1e09cd7d66b4 | 1079 | } |
nerit | 0:1e09cd7d66b4 | 1080 | #endif |
nerit | 0:1e09cd7d66b4 | 1081 | //******************************************* |
nerit | 0:1e09cd7d66b4 | 1082 | // esegue calcolo clock per la generazione della posizione teorica |
nerit | 0:1e09cd7d66b4 | 1083 | // la realtà in base al segnale di presenza del becco |
nerit | 0:1e09cd7d66b4 | 1084 | realSpeed = speedOfSeedWheel; |
nerit | 0:1e09cd7d66b4 | 1085 | realGiroSD = seedPerimeter / realSpeed; |
nerit | 0:1e09cd7d66b4 | 1086 | tempoBecco = (realGiroSD/360.0f)*16000.0f; |
nerit | 0:1e09cd7d66b4 | 1087 | frequenzaReale = fixedStepGiroSD/realGiroSD; |
nerit | 0:1e09cd7d66b4 | 1088 | semiPeriodoReale = (1000000.0f/frequenzaReale); |
nerit | 0:1e09cd7d66b4 | 1089 | tempoTraBecchi_mS = 0.0f; |
nerit | 0:1e09cd7d66b4 | 1090 | seedWheelRPM = (speedOfSeedWheel)*K_WheelRPM ; // calcola i giri al minuto della ruota di semina 7.37 31,75 |
nerit | 0:1e09cd7d66b4 | 1091 | rapportoRuote = pickNumber/cellsNumber; // 0.67 calcola il rapporto tra il numero di becchi ed il numero di celle 0.8 1,00 |
nerit | 0:1e09cd7d66b4 | 1092 | TBrpm = seedWheelRPM*rapportoRuote; // 5.896 31,75 |
nerit | 0:1e09cd7d66b4 | 1093 | TBgiroStep = TBmotorSteps*TBreductionRatio; |
nerit | 0:1e09cd7d66b4 | 1094 | K_TBfrequency = TBgiroStep/60.0f; // 1600 * 1.65625f /60 = 44 44,00 |
nerit | 0:1e09cd7d66b4 | 1095 | TBfrequency = (TBrpm*K_TBfrequency); // 130Hz a 0,29Mts 1397,00 a 1,25mt/s con 15 becchi e 15 celle |
nerit | 0:1e09cd7d66b4 | 1096 | TBperiod=1000000.0f/TBfrequency; // 715uS |
nerit | 0:1e09cd7d66b4 | 1097 | } |
nerit | 0:1e09cd7d66b4 | 1098 | // ---------------------------------------- |
nerit | 0:1e09cd7d66b4 | 1099 | // check SD fase |
nerit | 0:1e09cd7d66b4 | 1100 | if ((prePosSD >= fase)||(forzaFase==1)){//&&(prePosSD < (fase +30))){ |
nerit | 0:1e09cd7d66b4 | 1101 | forzaFase=0; |
nerit | 0:1e09cd7d66b4 | 1102 | if (trigRepos==1){ |
nerit | 0:1e09cd7d66b4 | 1103 | SDactualPosition=0; |
nerit | 0:1e09cd7d66b4 | 1104 | if ((countCicli<30)&&(trigCicli==0)){countCicli++;trigCicli=1;} |
nerit | 0:1e09cd7d66b4 | 1105 | if(countCicli>=cicliAspettaStart){aspettaStart=0;} |
nerit | 0:1e09cd7d66b4 | 1106 | if ((lowSpeed==0)&&(aspettaStart==0)&&(lockStart==0)){syncroCheck=1;beccoPronto=0;} |
nerit | 0:1e09cd7d66b4 | 1107 | if (trigTB==0){ |
nerit | 0:1e09cd7d66b4 | 1108 | inhibit=1; |
nerit | 0:1e09cd7d66b4 | 1109 | trigSD=1; |
nerit | 0:1e09cd7d66b4 | 1110 | }else{ |
nerit | 0:1e09cd7d66b4 | 1111 | inhibit=0; |
nerit | 0:1e09cd7d66b4 | 1112 | trigTB=0; |
nerit | 0:1e09cd7d66b4 | 1113 | trigSD=0; |
nerit | 0:1e09cd7d66b4 | 1114 | } |
nerit | 0:1e09cd7d66b4 | 1115 | trigRepos=0; |
nerit | 0:1e09cd7d66b4 | 1116 | } |
nerit | 0:1e09cd7d66b4 | 1117 | }else{ |
nerit | 0:1e09cd7d66b4 | 1118 | trigCicli=0; |
nerit | 0:1e09cd7d66b4 | 1119 | } |
nerit | 0:1e09cd7d66b4 | 1120 | // ---------------------------------------- |
nerit | 0:1e09cd7d66b4 | 1121 | // filtra il segnale del tamburo per lo stop in fase del tamburo stesso |
nerit | 0:1e09cd7d66b4 | 1122 | if (TBzeroPinInput==0){if (TBfilter.read_ms()>=5){oldTBzeroPinInput=0;}} |
nerit | 0:1e09cd7d66b4 | 1123 | if ((TBzeroPinInput==1)&&(oldTBzeroPinInput==0)){ |
nerit | 0:1e09cd7d66b4 | 1124 | oldTBzeroPinInput=1; |
nerit | 0:1e09cd7d66b4 | 1125 | if (loadDaCanInCorso==0){ |
nerit | 0:1e09cd7d66b4 | 1126 | stopCicloTB=1; |
nerit | 0:1e09cd7d66b4 | 1127 | startCicloTB=0; |
nerit | 0:1e09cd7d66b4 | 1128 | } |
nerit | 0:1e09cd7d66b4 | 1129 | TBfilter.reset(); |
nerit | 0:1e09cd7d66b4 | 1130 | TBzeroCyclePulse=1; |
nerit | 0:1e09cd7d66b4 | 1131 | TBactualPosition=0; |
nerit | 0:1e09cd7d66b4 | 1132 | if (cellsCounterLow < 0xFF){ |
nerit | 0:1e09cd7d66b4 | 1133 | cellsCounterLow++; |
nerit | 0:1e09cd7d66b4 | 1134 | }else{ |
nerit | 0:1e09cd7d66b4 | 1135 | cellsCounterHig++; |
nerit | 0:1e09cd7d66b4 | 1136 | cellsCounterLow=0; |
nerit | 0:1e09cd7d66b4 | 1137 | } |
nerit | 0:1e09cd7d66b4 | 1138 | if (loadDaCanInCorso==1){ |
nerit | 0:1e09cd7d66b4 | 1139 | cntCellsForLoad++; |
nerit | 0:1e09cd7d66b4 | 1140 | if (cntCellsForLoad >= 5){ |
nerit | 0:1e09cd7d66b4 | 1141 | stopCicloTB=1; |
nerit | 0:1e09cd7d66b4 | 1142 | cntCellsForLoad=0; |
nerit | 0:1e09cd7d66b4 | 1143 | } |
nerit | 0:1e09cd7d66b4 | 1144 | }else{ |
nerit | 0:1e09cd7d66b4 | 1145 | cntCellsForLoad=0; |
nerit | 0:1e09cd7d66b4 | 1146 | } |
nerit | 0:1e09cd7d66b4 | 1147 | if (trigSD==0){ |
nerit | 0:1e09cd7d66b4 | 1148 | inhibit=1; |
nerit | 0:1e09cd7d66b4 | 1149 | trigTB=1; |
nerit | 0:1e09cd7d66b4 | 1150 | }else{ |
nerit | 0:1e09cd7d66b4 | 1151 | inhibit=0; |
nerit | 0:1e09cd7d66b4 | 1152 | trigTB=0; |
nerit | 0:1e09cd7d66b4 | 1153 | trigSD=0; |
nerit | 0:1e09cd7d66b4 | 1154 | } |
nerit | 0:1e09cd7d66b4 | 1155 | // torna indietro per sbloccare il tamburo |
nerit | 0:1e09cd7d66b4 | 1156 | if ((TBmotorDirecti==1)&&(erroreTamburo==1)){ |
nerit | 0:1e09cd7d66b4 | 1157 | cntCellsForReload++; |
nerit | 0:1e09cd7d66b4 | 1158 | if (cntCellsForReload > 3){ |
nerit | 0:1e09cd7d66b4 | 1159 | TBmotorDirecti=0; |
nerit | 0:1e09cd7d66b4 | 1160 | erroreTamburo=0; |
nerit | 0:1e09cd7d66b4 | 1161 | } |
nerit | 0:1e09cd7d66b4 | 1162 | } |
nerit | 0:1e09cd7d66b4 | 1163 | } |
nerit | 0:1e09cd7d66b4 | 1164 | if ((double)TBactualPosition > ((TBgiroStep/cellsNumber)*1.2f)){ |
nerit | 0:1e09cd7d66b4 | 1165 | if (firstStart==0){ |
nerit | 0:1e09cd7d66b4 | 1166 | all_cellSignal=1; |
nerit | 0:1e09cd7d66b4 | 1167 | } |
nerit | 0:1e09cd7d66b4 | 1168 | if (erroreTamburo==0){ |
nerit | 0:1e09cd7d66b4 | 1169 | erroreTamburo=1; |
nerit | 0:1e09cd7d66b4 | 1170 | TBmotorDirecti=1; |
nerit | 0:1e09cd7d66b4 | 1171 | cntCellsForReload=0; |
nerit | 0:1e09cd7d66b4 | 1172 | cntTbError++; |
nerit | 0:1e09cd7d66b4 | 1173 | } |
nerit | 0:1e09cd7d66b4 | 1174 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1175 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 1176 | pc.printf("allarme error cells"); |
nerit | 0:1e09cd7d66b4 | 1177 | #endif |
nerit | 0:1e09cd7d66b4 | 1178 | #endif |
nerit | 0:1e09cd7d66b4 | 1179 | } |
nerit | 0:1e09cd7d66b4 | 1180 | if (((double)TBactualPosition > ((TBgiroStep/cellsNumber)*3.0f))||(cntTbError>2)){ |
nerit | 0:1e09cd7d66b4 | 1181 | if (firstStart==0){ |
nerit | 0:1e09cd7d66b4 | 1182 | all_noStepRota=1; |
nerit | 0:1e09cd7d66b4 | 1183 | } |
nerit | 0:1e09cd7d66b4 | 1184 | cntTbError=0; |
nerit | 0:1e09cd7d66b4 | 1185 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1186 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 1187 | pc.printf("allarme no cells sensor"); |
nerit | 0:1e09cd7d66b4 | 1188 | #endif |
nerit | 0:1e09cd7d66b4 | 1189 | #endif |
nerit | 0:1e09cd7d66b4 | 1190 | } |
nerit | 0:1e09cd7d66b4 | 1191 | // ---------------------------------------- |
nerit | 0:1e09cd7d66b4 | 1192 | // read and manage joystick |
nerit | 0:1e09cd7d66b4 | 1193 | // WARNING - ENABLE CYCLE IS SOFTWARE ALWAYS ACTIVE |
nerit | 0:1e09cd7d66b4 | 1194 | if (enableCycle==1){ |
nerit | 0:1e09cd7d66b4 | 1195 | if(runRequestBuf==1){ |
nerit | 0:1e09cd7d66b4 | 1196 | if (OldStartCycle!=runRequestBuf){ |
nerit | 0:1e09cd7d66b4 | 1197 | if((startCycle==0)&&(zeroCycleEnd==1)){ |
nerit | 0:1e09cd7d66b4 | 1198 | startCycle=1; |
nerit | 0:1e09cd7d66b4 | 1199 | OldStartCycle = runRequestBuf; |
nerit | 0:1e09cd7d66b4 | 1200 | oldZeroCycle=0; |
nerit | 0:1e09cd7d66b4 | 1201 | } |
nerit | 0:1e09cd7d66b4 | 1202 | } |
nerit | 0:1e09cd7d66b4 | 1203 | }else{ |
nerit | 0:1e09cd7d66b4 | 1204 | startCycle=0; |
nerit | 0:1e09cd7d66b4 | 1205 | pntMedia=0; |
nerit | 0:1e09cd7d66b4 | 1206 | } |
nerit | 0:1e09cd7d66b4 | 1207 | if (azzeraDaCan==1){ |
nerit | 0:1e09cd7d66b4 | 1208 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 1209 | zeroRequestBuf=1; |
nerit | 0:1e09cd7d66b4 | 1210 | oldZeroCycle=0; |
nerit | 0:1e09cd7d66b4 | 1211 | } |
nerit | 0:1e09cd7d66b4 | 1212 | azzeraDaCan=0; |
nerit | 0:1e09cd7d66b4 | 1213 | } |
nerit | 0:1e09cd7d66b4 | 1214 | if (loadDaCan==1){ |
nerit | 0:1e09cd7d66b4 | 1215 | if (tractorSpeed_MtS_timed==0.0f){ |
nerit | 0:1e09cd7d66b4 | 1216 | ciclaTB(); |
nerit | 0:1e09cd7d66b4 | 1217 | } |
nerit | 0:1e09cd7d66b4 | 1218 | } |
nerit | 0:1e09cd7d66b4 | 1219 | if ((zeroRequestBuf==1)){ |
nerit | 0:1e09cd7d66b4 | 1220 | if (oldZeroCycle!=zeroRequestBuf){ |
nerit | 0:1e09cd7d66b4 | 1221 | zeroCycle=1; |
nerit | 0:1e09cd7d66b4 | 1222 | zeroCycleEnd=0; |
nerit | 0:1e09cd7d66b4 | 1223 | SDzeroed=0; |
nerit | 0:1e09cd7d66b4 | 1224 | TBzeroed=0; |
nerit | 0:1e09cd7d66b4 | 1225 | zeroTrigger=0; |
nerit | 0:1e09cd7d66b4 | 1226 | oldZeroCycle = zeroRequestBuf; |
nerit | 0:1e09cd7d66b4 | 1227 | } |
nerit | 0:1e09cd7d66b4 | 1228 | } |
nerit | 0:1e09cd7d66b4 | 1229 | }else{ |
nerit | 0:1e09cd7d66b4 | 1230 | startCycle=0; |
nerit | 0:1e09cd7d66b4 | 1231 | zeroCycle=0; |
nerit | 0:1e09cd7d66b4 | 1232 | } |
nerit | 0:1e09cd7d66b4 | 1233 | |
nerit | 0:1e09cd7d66b4 | 1234 | //*************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 1235 | // pulseRised define the event of speed wheel pulse occurs |
nerit | 0:1e09cd7d66b4 | 1236 | // |
nerit | 0:1e09cd7d66b4 | 1237 | double maxInterval = pulseDistance/minWorkSpeed; |
nerit | 0:1e09cd7d66b4 | 1238 | double minIntervalPulse = pulseDistance/maxWorkSpeed; |
nerit | 0:1e09cd7d66b4 | 1239 | if (pulseRised==1){ |
nerit | 0:1e09cd7d66b4 | 1240 | if (enableSpeed<10){enableSpeed++;} |
nerit | 0:1e09cd7d66b4 | 1241 | pulseRised=0;pulseRised1=1;speedMediaCalc(); |
nerit | 0:1e09cd7d66b4 | 1242 | // calcola velocità trattore |
nerit | 0:1e09cd7d66b4 | 1243 | if(enableSpeed>=2){ |
nerit | 0:1e09cd7d66b4 | 1244 | if ((pulseSpeedInterval>=0.0f)){ //minIntervalPulse)&&(pulseSpeedInterval<maxInterval)){ |
nerit | 0:1e09cd7d66b4 | 1245 | tractorSpeed_MtS_timed = ((pulseDistance / pulseSpeedInterval)); // tractor speed (unit= Mt/S) from pulse time interval |
nerit | 0:1e09cd7d66b4 | 1246 | if (checkSDrotation==0){ |
nerit | 0:1e09cd7d66b4 | 1247 | checkSDrotation=1; |
nerit | 0:1e09cd7d66b4 | 1248 | SDwheelTimer.start(); |
nerit | 0:1e09cd7d66b4 | 1249 | } |
nerit | 0:1e09cd7d66b4 | 1250 | } |
nerit | 0:1e09cd7d66b4 | 1251 | } |
nerit | 0:1e09cd7d66b4 | 1252 | if ((pulseSpeedInterval>=minIntervalPulse)&&(pulseSpeedInterval<maxInterval)){ |
nerit | 0:1e09cd7d66b4 | 1253 | enableSDcontrol =1; |
nerit | 0:1e09cd7d66b4 | 1254 | } |
nerit | 0:1e09cd7d66b4 | 1255 | speedTimeOut.reset(); |
nerit | 0:1e09cd7d66b4 | 1256 | }else{ |
nerit | 0:1e09cd7d66b4 | 1257 | double oldLastPr = (double)oldLastPulseRead*1.7f; |
nerit | 0:1e09cd7d66b4 | 1258 | if((double)speedTimeOut.read_us()> (oldLastPr)){ |
nerit | 0:1e09cd7d66b4 | 1259 | tractorSpeed_MtS_timed = 0.0f; |
nerit | 0:1e09cd7d66b4 | 1260 | enableSDcontrol =0; |
nerit | 0:1e09cd7d66b4 | 1261 | pntMedia=0; |
nerit | 0:1e09cd7d66b4 | 1262 | speedTimeOut.reset(); |
nerit | 0:1e09cd7d66b4 | 1263 | enableSpeed=0; |
nerit | 0:1e09cd7d66b4 | 1264 | quincCnt=0; |
nerit | 0:1e09cd7d66b4 | 1265 | } |
nerit | 0:1e09cd7d66b4 | 1266 | } |
nerit | 0:1e09cd7d66b4 | 1267 | // esegue il controllo di velocità minima |
nerit | 0:1e09cd7d66b4 | 1268 | if ((double)speedTimer.read_ms()>=maxInterval){tractorSpeed_MtS_timed = 0.0f; |
nerit | 0:1e09cd7d66b4 | 1269 | enableSDcontrol =0; |
nerit | 0:1e09cd7d66b4 | 1270 | enableSpeed=0; |
nerit | 0:1e09cd7d66b4 | 1271 | } |
nerit | 0:1e09cd7d66b4 | 1272 | //*************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 1273 | // cycle logic control section |
nerit | 0:1e09cd7d66b4 | 1274 | //*************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 1275 | if (enableSimula==1){if(simOk==0){tractorSpeed_MtS_timed=0.0f;}} |
nerit | 0:1e09cd7d66b4 | 1276 | if ((tractorSpeed_MtS_timed>0.01f)){ |
nerit | 0:1e09cd7d66b4 | 1277 | cycleStopRequest=1; |
nerit | 0:1e09cd7d66b4 | 1278 | // calcola il tempo teorico di passaggio becchi sulla base della velocità del trattore |
nerit | 0:1e09cd7d66b4 | 1279 | tempoGiroSD = seedPerimeter / tractorSpeed_MtS_timed; // tempo Teorico impiegato dalla ruota di semina per fare un giro completo (a 4,5Km/h impiega 1,89 secondi) |
nerit | 0:1e09cd7d66b4 | 1280 | if (speedFromPick==1) { |
nerit | 0:1e09cd7d66b4 | 1281 | tempoTraBecchi_mS = (tempoGiroSD / pickNumber)*1000.0f; // tempo tra due impulsi dai becchi in millisecondi ( circa 157mS a 4,5Km/h) |
nerit | 0:1e09cd7d66b4 | 1282 | }else{ |
nerit | 0:1e09cd7d66b4 | 1283 | tempoTraBecchi_mS = (tempoGiroSD / 25.0f)*1000.0f; // tempo tra due impulsi dai becchi in millisecondi ( circa 157mS a 4,5Km/h) |
nerit | 0:1e09cd7d66b4 | 1284 | } |
nerit | 0:1e09cd7d66b4 | 1285 | //******************************************* |
nerit | 0:1e09cd7d66b4 | 1286 | // segue calcolo duty cycle comando motore DC per allinearsi con la velocità del trattore |
nerit | 0:1e09cd7d66b4 | 1287 | double dutyTeorico = 0.00; |
nerit | 0:1e09cd7d66b4 | 1288 | if ((tractorSpeed_MtS_timed>0.0)&&(tractorSpeed_MtS_timed<tabSpeed[0])){dutyTeorico = tabComan[0];} |
nerit | 0:1e09cd7d66b4 | 1289 | for (int ii = 0;ii<16;ii++){ |
nerit | 0:1e09cd7d66b4 | 1290 | if ((tractorSpeed_MtS_timed>=tabSpeed[ii])&&(tractorSpeed_MtS_timed<tabSpeed[ii+1])){ |
nerit | 0:1e09cd7d66b4 | 1291 | dutyTeorico = tabComan[ii+1]; |
nerit | 0:1e09cd7d66b4 | 1292 | } |
nerit | 0:1e09cd7d66b4 | 1293 | } |
nerit | 0:1e09cd7d66b4 | 1294 | if (tractorSpeed_MtS_timed > tabSpeed[16]){dutyTeorico=tractorSpeed_MtS_timed/1.25f;} |
nerit | 2:d9c7430ae953 | 1295 | #if !defined(speedMaster) |
nerit | 2:d9c7430ae953 | 1296 | if (quincEnable==1){ |
nerit | 2:d9c7430ae953 | 1297 | quinCalc(); |
nerit | 2:d9c7430ae953 | 1298 | } |
nerit | 2:d9c7430ae953 | 1299 | #endif |
nerit | 0:1e09cd7d66b4 | 1300 | if ((pulseRised1==1)&&(enableSpeed>3)&&(pulseRised2==1)){ |
nerit | 0:1e09cd7d66b4 | 1301 | double erroreTempo = 0.0f; |
nerit | 0:1e09cd7d66b4 | 1302 | if(speedFromPick==1){ |
nerit | 3:c0f11ca4df02 | 1303 | #if !defined(speedMaster) |
nerit | 3:c0f11ca4df02 | 1304 | double giorgio = timeIntraPick/percento; |
nerit | 3:c0f11ca4df02 | 1305 | //erroreTempo = (double)timeIntraPick - tempoTraBecchi_mS; // errore tra il tempo previsto ed il tempo reale ( >0 se sto andando più piano del previsto) |
nerit | 3:c0f11ca4df02 | 1306 | if (giorgio >0.0f){ |
nerit | 3:c0f11ca4df02 | 1307 | erroreTempo = giorgio - tempoTraBecchi_mS; // errore tra il tempo previsto ed il tempo reale ( >0 se sto andando più piano del previsto) |
nerit | 3:c0f11ca4df02 | 1308 | }else{ |
nerit | 3:c0f11ca4df02 | 1309 | erroreTempo = (double)timeIntraPick - tempoTraBecchi_mS; |
nerit | 3:c0f11ca4df02 | 1310 | } |
nerit | 3:c0f11ca4df02 | 1311 | #else |
nerit | 3:c0f11ca4df02 | 1312 | erroreTempo = (double)timeIntraPick - tempoTraBecchi_mS; |
nerit | 3:c0f11ca4df02 | 1313 | #endif |
nerit | 0:1e09cd7d66b4 | 1314 | }else{ |
nerit | 0:1e09cd7d66b4 | 1315 | erroreTempo = (double)memoTimeHole - tempoTraBecchi_mS; // errore tra il tempo previsto ed il tempo reale ( >0 se sto andando più piano del previsto) |
nerit | 0:1e09cd7d66b4 | 1316 | } |
nerit | 0:1e09cd7d66b4 | 1317 | double errorePercentuale = erroreTempo / tempoTraBecchi_mS; |
nerit | 3:c0f11ca4df02 | 1318 | #if defined(speedMaster) |
nerit | 3:c0f11ca4df02 | 1319 | double k1=errorePercentuale*185.265f; |
nerit | 3:c0f11ca4df02 | 1320 | #else |
nerit | 3:c0f11ca4df02 | 1321 | double k1=errorePercentuale*0.265f; |
nerit | 3:c0f11ca4df02 | 1322 | #endif |
nerit | 1:e88bf5011af6 | 1323 | double k3=0.0f; |
nerit | 1:e88bf5011af6 | 1324 | double k4=0.0f; |
nerit | 1:e88bf5011af6 | 1325 | double k5=0.0f; |
nerit | 1:e88bf5011af6 | 1326 | if (tractorSpeed_MtS_timed <= minSeedSpeed){ |
nerit | 1:e88bf5011af6 | 1327 | k3=0.105; |
nerit | 1:e88bf5011af6 | 1328 | k4=0.207; |
nerit | 1:e88bf5011af6 | 1329 | k5=0.310; |
nerit | 1:e88bf5011af6 | 1330 | }else{ |
nerit | 3:c0f11ca4df02 | 1331 | k3=0.03f; |
nerit | 3:c0f11ca4df02 | 1332 | k4=0.06f; |
nerit | 3:c0f11ca4df02 | 1333 | k5=0.20f; |
nerit | 1:e88bf5011af6 | 1334 | } |
nerit | 3:c0f11ca4df02 | 1335 | double L1 = 0.001f; |
nerit | 3:c0f11ca4df02 | 1336 | double L_1=-0.001; |
nerit | 3:c0f11ca4df02 | 1337 | double L2 = 0.007f; |
nerit | 3:c0f11ca4df02 | 1338 | double L_2=-0.007f; |
nerit | 3:c0f11ca4df02 | 1339 | double L3 = 0.01f; |
nerit | 3:c0f11ca4df02 | 1340 | double L_3=-0.01f; |
nerit | 3:c0f11ca4df02 | 1341 | if ((errorePercentuale > L3)||(errorePercentuale < L_3)){ |
nerit | 1:e88bf5011af6 | 1342 | k1=errorePercentuale*k5; |
nerit | 1:e88bf5011af6 | 1343 | } |
nerit | 3:c0f11ca4df02 | 1344 | if (((errorePercentuale >= L2)&&(errorePercentuale<=L3))||((errorePercentuale <= L_2)&&(errorePercentuale>=L_3))){ |
nerit | 1:e88bf5011af6 | 1345 | k1=errorePercentuale*k4; |
nerit | 1:e88bf5011af6 | 1346 | } |
nerit | 3:c0f11ca4df02 | 1347 | if (((errorePercentuale < L2)&&(errorePercentuale>L1))||((errorePercentuale > L_2)&&(errorePercentuale<L_1))){ |
nerit | 1:e88bf5011af6 | 1348 | k1=errorePercentuale*k3; |
nerit | 1:e88bf5011af6 | 1349 | } |
nerit | 0:1e09cd7d66b4 | 1350 | double memoCorrezione = (dutyTeorico *k1); |
nerit | 1:e88bf5011af6 | 1351 | #if defined(pcSerial) |
nerit | 1:e88bf5011af6 | 1352 | #if defined(Qnc) |
nerit | 1:e88bf5011af6 | 1353 | pc.printf("IntraPick: %f TempoBecchi: %f ErrPerc: %f\n",timeIntraPick, tempoTraBecchi_mS,errorePercentuale); |
nerit | 1:e88bf5011af6 | 1354 | #endif |
nerit | 1:e88bf5011af6 | 1355 | #endif |
nerit | 0:1e09cd7d66b4 | 1356 | correzione = correzione + memoCorrezione; |
nerit | 0:1e09cd7d66b4 | 1357 | pulseRised1=0; |
nerit | 0:1e09cd7d66b4 | 1358 | pulseRised2=0; |
nerit | 0:1e09cd7d66b4 | 1359 | } |
nerit | 0:1e09cd7d66b4 | 1360 | // introduce il controllo di corrente |
nerit | 0:1e09cd7d66b4 | 1361 | if (incrementCurrent){ |
nerit | 0:1e09cd7d66b4 | 1362 | boostDcOut +=0.005f; |
nerit | 0:1e09cd7d66b4 | 1363 | } |
nerit | 0:1e09cd7d66b4 | 1364 | if (reduceCurrent){ |
nerit | 0:1e09cd7d66b4 | 1365 | boostDcOut -=0.005f; |
nerit | 0:1e09cd7d66b4 | 1366 | } |
nerit | 0:1e09cd7d66b4 | 1367 | if (boostDcOut >= 0.2f){ |
nerit | 0:1e09cd7d66b4 | 1368 | boostDcOut=0.2f; |
nerit | 0:1e09cd7d66b4 | 1369 | all_genericals=1; |
nerit | 0:1e09cd7d66b4 | 1370 | } |
nerit | 0:1e09cd7d66b4 | 1371 | if (boostDcOut <=-0.2f){ |
nerit | 0:1e09cd7d66b4 | 1372 | boostDcOut=-0.2f; |
nerit | 0:1e09cd7d66b4 | 1373 | all_genericals=1; |
nerit | 0:1e09cd7d66b4 | 1374 | } |
nerit | 1:e88bf5011af6 | 1375 | //correzione += boostDcOut; |
nerit | 0:1e09cd7d66b4 | 1376 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1377 | #if defined(Qnca) |
nerit | 0:1e09cd7d66b4 | 1378 | pc.printf(" DUTY PRE FINALE: %f",dcActualDuty); |
nerit | 0:1e09cd7d66b4 | 1379 | #endif |
nerit | 0:1e09cd7d66b4 | 1380 | #endif |
nerit | 1:e88bf5011af6 | 1381 | DC_brake=0; |
nerit | 1:e88bf5011af6 | 1382 | DC_forward=1; |
nerit | 1:e88bf5011af6 | 1383 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1384 | |
nerit | 0:1e09cd7d66b4 | 1385 | // il semiperiodoreale è calcolato sulla lettura del passaggio becchi reale |
nerit | 0:1e09cd7d66b4 | 1386 | if (correggiSD == true){ |
nerit | 0:1e09cd7d66b4 | 1387 | seedWheelPeriod = semiPeriodoReale / abs(percento); |
nerit | 0:1e09cd7d66b4 | 1388 | }else{ |
nerit | 0:1e09cd7d66b4 | 1389 | seedWheelPeriod = semiPeriodoReale; |
nerit | 0:1e09cd7d66b4 | 1390 | } |
nerit | 0:1e09cd7d66b4 | 1391 | if (seedWheelPeriod < 180.0f){seedWheelPeriod = 180.0f;} |
nerit | 0:1e09cd7d66b4 | 1392 | if ((oldSeedWheelPeriod!=seedWheelPeriod)&&(seedWheelPeriod >=180.0f )){ |
nerit | 0:1e09cd7d66b4 | 1393 | SDticker.attach_us(&step_SDPulseOut,seedWheelPeriod); // clock time are milliseconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 1394 | oldSeedWheelPeriod=seedWheelPeriod; |
nerit | 0:1e09cd7d66b4 | 1395 | } |
nerit | 0:1e09cd7d66b4 | 1396 | |
nerit | 0:1e09cd7d66b4 | 1397 | //if (correzione > (dutyTeorico*0.20)){correzione = dutyTeorico*0.20;} |
nerit | 1:e88bf5011af6 | 1398 | if (correzione > 0.30f){correzione = 0.30f;} |
nerit | 1:e88bf5011af6 | 1399 | if (correzione < -0.30f){correzione = -0.30f;} |
nerit | 0:1e09cd7d66b4 | 1400 | if((enableSDcontrol==1)){ |
nerit | 0:1e09cd7d66b4 | 1401 | if (correzioneAttiva==1){ |
nerit | 0:1e09cd7d66b4 | 1402 | dcActualDuty = dutyTeorico + correzione; |
nerit | 1:e88bf5011af6 | 1403 | //if (dcActualDuty<dcStarting){dcActualDuty=dcStarting;} |
nerit | 0:1e09cd7d66b4 | 1404 | } |
nerit | 0:1e09cd7d66b4 | 1405 | }else{ |
nerit | 0:1e09cd7d66b4 | 1406 | dcActualDuty = dutyTeorico; |
nerit | 0:1e09cd7d66b4 | 1407 | } |
nerit | 0:1e09cd7d66b4 | 1408 | if (dcActualDuty <0.0f){dcActualDuty=0.0f;} |
nerit | 0:1e09cd7d66b4 | 1409 | if (dcActualDuty > 1.0f){dcActualDuty = dcMaxSpeed;} |
nerit | 0:1e09cd7d66b4 | 1410 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1411 | #if defined(Qnca) |
nerit | 0:1e09cd7d66b4 | 1412 | pc.printf(" DUTY FINALE: %f \n",dcActualDuty); |
nerit | 0:1e09cd7d66b4 | 1413 | #endif |
nerit | 0:1e09cd7d66b4 | 1414 | #endif |
nerit | 0:1e09cd7d66b4 | 1415 | SDmotorPWM.write(dcActualDuty); |
nerit | 0:1e09cd7d66b4 | 1416 | // allarme |
nerit | 0:1e09cd7d66b4 | 1417 | if (SDwheelTimer.read_ms()>4000){ |
nerit | 0:1e09cd7d66b4 | 1418 | if (firstStart==0){ |
nerit | 0:1e09cd7d66b4 | 1419 | all_noDcRotati=1; |
nerit | 0:1e09cd7d66b4 | 1420 | } |
nerit | 0:1e09cd7d66b4 | 1421 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1422 | #if defined(VediAllarmi) |
nerit | 0:1e09cd7d66b4 | 1423 | pc.printf("allarme no DC rotation"); |
nerit | 0:1e09cd7d66b4 | 1424 | #endif |
nerit | 0:1e09cd7d66b4 | 1425 | #endif |
nerit | 0:1e09cd7d66b4 | 1426 | |
nerit | 0:1e09cd7d66b4 | 1427 | } |
nerit | 0:1e09cd7d66b4 | 1428 | |
nerit | 0:1e09cd7d66b4 | 1429 | //*************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 1430 | // CONTROLLA TAMBURO |
nerit | 0:1e09cd7d66b4 | 1431 | //*************************************************************************************************************** |
nerit | 0:1e09cd7d66b4 | 1432 | if(lowSpeed==0){ |
nerit | 0:1e09cd7d66b4 | 1433 | if (syncroCheck==1){ |
nerit | 0:1e09cd7d66b4 | 1434 | syncroCheck=0; |
nerit | 0:1e09cd7d66b4 | 1435 | lockStart=1; |
nerit | 0:1e09cd7d66b4 | 1436 | periodo = TBperiod; |
nerit | 0:1e09cd7d66b4 | 1437 | if (aspettaStart==0){cambiaTB(periodo);} |
nerit | 0:1e09cd7d66b4 | 1438 | } |
nerit | 0:1e09cd7d66b4 | 1439 | // controllo di stop |
nerit | 0:1e09cd7d66b4 | 1440 | double memoIntraP = (double)memoIntraPick*1.8f; |
nerit | 0:1e09cd7d66b4 | 1441 | if ((double)rotationTimeOut.read_ms()> (memoIntraP)){ |
nerit | 0:1e09cd7d66b4 | 1442 | syncroCheck=0; |
nerit | 0:1e09cd7d66b4 | 1443 | aspettaStart=1; |
nerit | 0:1e09cd7d66b4 | 1444 | countCicli=0; |
nerit | 0:1e09cd7d66b4 | 1445 | if (TBzeroCyclePulse==1){TBticker.detach();} |
nerit | 0:1e09cd7d66b4 | 1446 | } |
nerit | 0:1e09cd7d66b4 | 1447 | }else{ // fine ciclo fuori da low speed |
nerit | 0:1e09cd7d66b4 | 1448 | syncroCheck=0; |
nerit | 0:1e09cd7d66b4 | 1449 | lockStart=0; |
nerit | 0:1e09cd7d66b4 | 1450 | if (beccoPronto==1){ |
nerit | 0:1e09cd7d66b4 | 1451 | if (tamburoStandard==1){ |
nerit | 0:1e09cd7d66b4 | 1452 | double ritardoMassimo = 0.0f; |
nerit | 0:1e09cd7d66b4 | 1453 | if(speedFromPick==1){ |
nerit | 0:1e09cd7d66b4 | 1454 | ritardoMassimo = (double)timeIntraPick; |
nerit | 0:1e09cd7d66b4 | 1455 | }else{ |
nerit | 0:1e09cd7d66b4 | 1456 | ritardoMassimo = (double)memoTimeHole; |
nerit | 0:1e09cd7d66b4 | 1457 | } |
nerit | 0:1e09cd7d66b4 | 1458 | int tempoDiSincro = (int)((double)(ritardoMassimo - ((tempoBecco/2.0f)+((speedOfSeedWheel/1.25f)*ritardoMassimo)))); // |
nerit | 0:1e09cd7d66b4 | 1459 | if (tempoDiSincro <= 1){tempoDiSincro=1;} |
nerit | 0:1e09cd7d66b4 | 1460 | if ((sincroTimer.read_ms()>= tempoDiSincro)){ |
nerit | 0:1e09cd7d66b4 | 1461 | if (tractorSpeed_MtS_timed >= minWorkSpeed){startCicloTB=1;} |
nerit | 0:1e09cd7d66b4 | 1462 | beccoPronto=0; |
nerit | 0:1e09cd7d66b4 | 1463 | } |
nerit | 0:1e09cd7d66b4 | 1464 | }else{ |
nerit | 0:1e09cd7d66b4 | 1465 | // tamburo per zucca |
nerit | 0:1e09cd7d66b4 | 1466 | if (speedOfSeedWheel >= minWorkSpeed){startCicloTB=1;} |
nerit | 0:1e09cd7d66b4 | 1467 | beccoPronto=0; |
nerit | 0:1e09cd7d66b4 | 1468 | } |
nerit | 0:1e09cd7d66b4 | 1469 | } |
nerit | 0:1e09cd7d66b4 | 1470 | ciclaTB(); |
nerit | 0:1e09cd7d66b4 | 1471 | } |
nerit | 0:1e09cd7d66b4 | 1472 | //************************************************************* |
nerit | 0:1e09cd7d66b4 | 1473 | }else{ // fine ciclo con velocita maggiore di 0 |
nerit | 0:1e09cd7d66b4 | 1474 | SDwheelTimer.stop(); |
nerit | 0:1e09cd7d66b4 | 1475 | SDwheelTimer.reset(); |
nerit | 0:1e09cd7d66b4 | 1476 | checkSDrotation=0; |
nerit | 0:1e09cd7d66b4 | 1477 | oldFaseLavoro=0; |
nerit | 0:1e09cd7d66b4 | 1478 | aspettaStart=1; |
nerit | 0:1e09cd7d66b4 | 1479 | countCicli=0; |
nerit | 0:1e09cd7d66b4 | 1480 | startCycle=0; |
nerit | 0:1e09cd7d66b4 | 1481 | oldSeedWheelPeriod=0.0f; |
nerit | 0:1e09cd7d66b4 | 1482 | oldPeriodoTB=0.0f; |
nerit | 0:1e09cd7d66b4 | 1483 | correzione=0.0f; |
nerit | 0:1e09cd7d66b4 | 1484 | OLDpulseSpeedInterval=1000.01f; |
nerit | 0:1e09cd7d66b4 | 1485 | cicloTbinCorso=0; |
nerit | 0:1e09cd7d66b4 | 1486 | cntTbError=0; |
nerit | 0:1e09cd7d66b4 | 1487 | if (cycleStopRequest==1){ |
nerit | 0:1e09cd7d66b4 | 1488 | zeroDelay.reset(); |
nerit | 0:1e09cd7d66b4 | 1489 | zeroDelay.start(); |
nerit | 0:1e09cd7d66b4 | 1490 | runRequestBuf=0; |
nerit | 0:1e09cd7d66b4 | 1491 | zeroRequestBuf=1; |
nerit | 0:1e09cd7d66b4 | 1492 | cycleStopRequest=0; |
nerit | 0:1e09cd7d66b4 | 1493 | SDzeroCyclePulse=0; |
nerit | 0:1e09cd7d66b4 | 1494 | TBzeroCyclePulse=0; |
nerit | 0:1e09cd7d66b4 | 1495 | zeroCycleEnd=0; |
nerit | 0:1e09cd7d66b4 | 1496 | zeroCycle=1; |
nerit | 0:1e09cd7d66b4 | 1497 | zeroTrigger=0; |
nerit | 0:1e09cd7d66b4 | 1498 | } |
nerit | 0:1e09cd7d66b4 | 1499 | } |
nerit | 0:1e09cd7d66b4 | 1500 | //************************************************************************************************* |
nerit | 0:1e09cd7d66b4 | 1501 | // ciclo di azzeramento motori |
nerit | 0:1e09cd7d66b4 | 1502 | if ((zeroCycleEnd==0)&&(zeroCycle==1)){//&&(zeroDelay.read_ms()>10000)){ |
nerit | 0:1e09cd7d66b4 | 1503 | if (zeroTrigger==0){ |
nerit | 0:1e09cd7d66b4 | 1504 | TBticker.attach_us(&step_TBPulseOut,1000.0f); // clock time are seconds and attach seed motor stepper controls |
nerit | 0:1e09cd7d66b4 | 1505 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1506 | DC_brake=1; |
nerit | 0:1e09cd7d66b4 | 1507 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1508 | frenata=0; |
nerit | 0:1e09cd7d66b4 | 1509 | zeroTrigger=1; |
nerit | 0:1e09cd7d66b4 | 1510 | ritardoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1511 | ritardoComandoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1512 | ritardoComandoStop.start(); |
nerit | 0:1e09cd7d66b4 | 1513 | timeOutZeroSD.start(); |
nerit | 0:1e09cd7d66b4 | 1514 | quincTimeSet.reset(); |
nerit | 0:1e09cd7d66b4 | 1515 | } |
nerit | 0:1e09cd7d66b4 | 1516 | int tempoFrenata=300; |
nerit | 0:1e09cd7d66b4 | 1517 | if (((ritardoStop.read_ms()>tempoFrenata)&&(SDzeroDebounced==0))||(accensione==1)||(ritardoComandoStop.read_ms()>400)){ |
nerit | 0:1e09cd7d66b4 | 1518 | accensione=0; |
nerit | 0:1e09cd7d66b4 | 1519 | avvicinamento=1; |
nerit | 0:1e09cd7d66b4 | 1520 | avvicinamentoOn.reset(); |
nerit | 0:1e09cd7d66b4 | 1521 | avvicinamentoOn.start(); |
nerit | 0:1e09cd7d66b4 | 1522 | SDmotorPWM.write(0.32f); // duty cycle = 60% of power |
nerit | 0:1e09cd7d66b4 | 1523 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1524 | DC_brake=0; |
nerit | 0:1e09cd7d66b4 | 1525 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1526 | ritardoComandoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1527 | ritardoComandoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1528 | } |
nerit | 0:1e09cd7d66b4 | 1529 | if (avvicinamento==1){ |
nerit | 0:1e09cd7d66b4 | 1530 | if(avvicinamentoOn.read_ms()>300){ |
nerit | 0:1e09cd7d66b4 | 1531 | SDmotorPWM.write(0.7f); |
nerit | 0:1e09cd7d66b4 | 1532 | avvicinamentoOn.reset(); |
nerit | 0:1e09cd7d66b4 | 1533 | avvicinamentoOff.reset(); |
nerit | 0:1e09cd7d66b4 | 1534 | avvicinamentoOff.start(); |
nerit | 0:1e09cd7d66b4 | 1535 | } |
nerit | 0:1e09cd7d66b4 | 1536 | if(avvicinamentoOff.read_ms()>100){ |
nerit | 0:1e09cd7d66b4 | 1537 | SDmotorPWM.write(0.32f); |
nerit | 0:1e09cd7d66b4 | 1538 | avvicinamentoOff.reset(); |
nerit | 0:1e09cd7d66b4 | 1539 | avvicinamentoOff.stop(); |
nerit | 0:1e09cd7d66b4 | 1540 | avvicinamentoOn.start(); |
nerit | 0:1e09cd7d66b4 | 1541 | } |
nerit | 0:1e09cd7d66b4 | 1542 | }else{ |
nerit | 0:1e09cd7d66b4 | 1543 | avvicinamentoOn.stop(); |
nerit | 0:1e09cd7d66b4 | 1544 | avvicinamentoOff.stop(); |
nerit | 0:1e09cd7d66b4 | 1545 | avvicinamentoOn.reset(); |
nerit | 0:1e09cd7d66b4 | 1546 | avvicinamentoOff.reset(); |
nerit | 0:1e09cd7d66b4 | 1547 | } |
nerit | 0:1e09cd7d66b4 | 1548 | if (frenata==0){ |
nerit | 0:1e09cd7d66b4 | 1549 | if (SDzeroCyclePulse==1){ |
nerit | 0:1e09cd7d66b4 | 1550 | SDticker.detach(); |
nerit | 0:1e09cd7d66b4 | 1551 | frenata=1; |
nerit | 0:1e09cd7d66b4 | 1552 | quincTimeSet.reset(); |
nerit | 0:1e09cd7d66b4 | 1553 | quincTimeSet.start(); |
nerit | 0:1e09cd7d66b4 | 1554 | ritardoStop.start(); |
nerit | 0:1e09cd7d66b4 | 1555 | //ritardoComandoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1556 | //ritardoComandoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1557 | } |
nerit | 0:1e09cd7d66b4 | 1558 | }else{ |
nerit | 0:1e09cd7d66b4 | 1559 | if (quinconceActive==0){ |
nerit | 0:1e09cd7d66b4 | 1560 | if (SDzeroCyclePulse==1){ |
nerit | 0:1e09cd7d66b4 | 1561 | avvicinamento=0; |
nerit | 0:1e09cd7d66b4 | 1562 | DC_brake=1; |
nerit | 0:1e09cd7d66b4 | 1563 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1564 | SDzeroed=1; |
nerit | 0:1e09cd7d66b4 | 1565 | ritardoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1566 | ritardoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1567 | } |
nerit | 0:1e09cd7d66b4 | 1568 | }else{ |
nerit | 0:1e09cd7d66b4 | 1569 | if (quincTimeSet.read_ms()>500){ |
nerit | 0:1e09cd7d66b4 | 1570 | avvicinamento=0; |
nerit | 0:1e09cd7d66b4 | 1571 | DC_brake=1; |
nerit | 0:1e09cd7d66b4 | 1572 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1573 | SDzeroed=1; |
nerit | 0:1e09cd7d66b4 | 1574 | ritardoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1575 | ritardoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1576 | quincTimeSet.stop(); |
nerit | 0:1e09cd7d66b4 | 1577 | } |
nerit | 0:1e09cd7d66b4 | 1578 | } |
nerit | 0:1e09cd7d66b4 | 1579 | } |
nerit | 0:1e09cd7d66b4 | 1580 | // azzera tutto in time out |
nerit | 0:1e09cd7d66b4 | 1581 | if (timeOutZeroSD.read_ms()>=10000){ |
nerit | 0:1e09cd7d66b4 | 1582 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1583 | #if defined(canDataReceived) |
nerit | 0:1e09cd7d66b4 | 1584 | pc.printf("allarme no zero"); |
nerit | 0:1e09cd7d66b4 | 1585 | #endif |
nerit | 0:1e09cd7d66b4 | 1586 | #endif |
nerit | 0:1e09cd7d66b4 | 1587 | if (firstStart==0){ |
nerit | 0:1e09cd7d66b4 | 1588 | all_no_Zeroing=1; |
nerit | 0:1e09cd7d66b4 | 1589 | } |
nerit | 0:1e09cd7d66b4 | 1590 | avvicinamento=0; |
nerit | 0:1e09cd7d66b4 | 1591 | DC_brake=1; |
nerit | 0:1e09cd7d66b4 | 1592 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1593 | SDzeroed=1; |
nerit | 0:1e09cd7d66b4 | 1594 | ritardoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1595 | ritardoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1596 | avvicinamentoOn.stop(); |
nerit | 0:1e09cd7d66b4 | 1597 | avvicinamentoOff.stop(); |
nerit | 0:1e09cd7d66b4 | 1598 | avvicinamentoOn.reset(); |
nerit | 0:1e09cd7d66b4 | 1599 | avvicinamentoOff.reset(); |
nerit | 0:1e09cd7d66b4 | 1600 | ritardoComandoStop.reset(); |
nerit | 0:1e09cd7d66b4 | 1601 | ritardoComandoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1602 | timeOutZeroSD.stop(); |
nerit | 0:1e09cd7d66b4 | 1603 | timeOutZeroSD.reset(); |
nerit | 0:1e09cd7d66b4 | 1604 | } |
nerit | 0:1e09cd7d66b4 | 1605 | if (TBzeroCyclePulse==1){ |
nerit | 0:1e09cd7d66b4 | 1606 | TBticker.detach(); |
nerit | 0:1e09cd7d66b4 | 1607 | TBzeroed=1; |
nerit | 0:1e09cd7d66b4 | 1608 | } |
nerit | 0:1e09cd7d66b4 | 1609 | if ((SDzeroed==1)&&(TBzeroed==1)){ |
nerit | 0:1e09cd7d66b4 | 1610 | avvicinamentoOn.stop(); |
nerit | 0:1e09cd7d66b4 | 1611 | avvicinamentoOff.stop(); |
nerit | 0:1e09cd7d66b4 | 1612 | ritardoComandoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1613 | ritardoStop.stop(); |
nerit | 0:1e09cd7d66b4 | 1614 | zeroCycleEnd=1; |
nerit | 0:1e09cd7d66b4 | 1615 | zeroCycle=0; |
nerit | 0:1e09cd7d66b4 | 1616 | zeroTrigger=0; |
nerit | 0:1e09cd7d66b4 | 1617 | runRequestBuf=1; |
nerit | 0:1e09cd7d66b4 | 1618 | zeroRequestBuf=0; |
nerit | 0:1e09cd7d66b4 | 1619 | cycleStopRequest=0; |
nerit | 0:1e09cd7d66b4 | 1620 | SDzeroed=0; |
nerit | 0:1e09cd7d66b4 | 1621 | TBzeroed=0; |
nerit | 0:1e09cd7d66b4 | 1622 | timeOutZeroSD.stop(); |
nerit | 0:1e09cd7d66b4 | 1623 | timeOutZeroSD.reset(); |
nerit | 0:1e09cd7d66b4 | 1624 | } |
nerit | 0:1e09cd7d66b4 | 1625 | } |
nerit | 0:1e09cd7d66b4 | 1626 | |
nerit | 0:1e09cd7d66b4 | 1627 | //************************************************************************************************* |
nerit | 0:1e09cd7d66b4 | 1628 | if (enableCycle==0){ |
nerit | 0:1e09cd7d66b4 | 1629 | zeroTrigger=0; |
nerit | 0:1e09cd7d66b4 | 1630 | SDmotorPWM=0; |
nerit | 0:1e09cd7d66b4 | 1631 | SDmotorInA=0; |
nerit | 0:1e09cd7d66b4 | 1632 | SDmotorInB=0; |
nerit | 0:1e09cd7d66b4 | 1633 | } |
nerit | 0:1e09cd7d66b4 | 1634 | SDzeroCyclePulse=0; |
nerit | 0:1e09cd7d66b4 | 1635 | TBzeroCyclePulse=0; |
nerit | 0:1e09cd7d66b4 | 1636 | //************************************************************************************************* |
nerit | 0:1e09cd7d66b4 | 1637 | }else{//end ciclo normale |
nerit | 0:1e09cd7d66b4 | 1638 | //************************************************************************************************* |
nerit | 0:1e09cd7d66b4 | 1639 | // task di prova della scheda |
nerit | 0:1e09cd7d66b4 | 1640 | //************************************************************************************************* |
nerit | 0:1e09cd7d66b4 | 1641 | #if defined(provaScheda) |
nerit | 0:1e09cd7d66b4 | 1642 | clocca++; |
nerit | 0:1e09cd7d66b4 | 1643 | //led = !led; |
nerit | 0:1e09cd7d66b4 | 1644 | //txMsg.clear(); |
nerit | 0:1e09cd7d66b4 | 1645 | //txMsg << clocca; |
nerit | 0:1e09cd7d66b4 | 1646 | //test.printf("aogs \n"); |
nerit | 0:1e09cd7d66b4 | 1647 | //if(can1.write(txMsg)){ |
nerit | 0:1e09cd7d66b4 | 1648 | #if defined(pcSerial) |
nerit | 0:1e09cd7d66b4 | 1649 | pc.printf("Can write OK \n"); |
nerit | 0:1e09cd7d66b4 | 1650 | #endif |
nerit | 0:1e09cd7d66b4 | 1651 | //} |
nerit | 0:1e09cd7d66b4 | 1652 | switch (clocca){ |
nerit | 0:1e09cd7d66b4 | 1653 | case 1: |
nerit | 0:1e09cd7d66b4 | 1654 | TBmotorStepOut=1; // define step command for up down motor driver |
nerit | 0:1e09cd7d66b4 | 1655 | break; |
nerit | 0:1e09cd7d66b4 | 1656 | case 2: |
nerit | 0:1e09cd7d66b4 | 1657 | SDmotorPWM=1; // define step command for seeding whell motor driver |
nerit | 0:1e09cd7d66b4 | 1658 | break; |
nerit | 0:1e09cd7d66b4 | 1659 | case 3: |
nerit | 0:1e09cd7d66b4 | 1660 | speedClock=1; // define input of |
nerit | 0:1e09cd7d66b4 | 1661 | break; |
nerit | 0:1e09cd7d66b4 | 1662 | case 4: |
nerit | 0:1e09cd7d66b4 | 1663 | break; |
nerit | 0:1e09cd7d66b4 | 1664 | case 5: |
nerit | 0:1e09cd7d66b4 | 1665 | SDmotorInA=1; |
nerit | 0:1e09cd7d66b4 | 1666 | SDmotorInB=0; |
nerit | 0:1e09cd7d66b4 | 1667 | break; |
nerit | 0:1e09cd7d66b4 | 1668 | case 6: |
nerit | 0:1e09cd7d66b4 | 1669 | break; |
nerit | 0:1e09cd7d66b4 | 1670 | case 7: |
nerit | 0:1e09cd7d66b4 | 1671 | break; |
nerit | 0:1e09cd7d66b4 | 1672 | case 8: |
nerit | 0:1e09cd7d66b4 | 1673 | break; |
nerit | 0:1e09cd7d66b4 | 1674 | case 9: |
nerit | 0:1e09cd7d66b4 | 1675 | break; |
nerit | 0:1e09cd7d66b4 | 1676 | case 10: |
nerit | 0:1e09cd7d66b4 | 1677 | break; |
nerit | 0:1e09cd7d66b4 | 1678 | case 11: |
nerit | 0:1e09cd7d66b4 | 1679 | break; |
nerit | 0:1e09cd7d66b4 | 1680 | case 12: |
nerit | 0:1e09cd7d66b4 | 1681 | break; |
nerit | 0:1e09cd7d66b4 | 1682 | case 13: |
nerit | 0:1e09cd7d66b4 | 1683 | break; |
nerit | 0:1e09cd7d66b4 | 1684 | case 14: |
nerit | 0:1e09cd7d66b4 | 1685 | SDmotorPWM=1; // power mosfet 2 command out |
nerit | 0:1e09cd7d66b4 | 1686 | break; |
nerit | 0:1e09cd7d66b4 | 1687 | case 15: |
nerit | 0:1e09cd7d66b4 | 1688 | break; |
nerit | 0:1e09cd7d66b4 | 1689 | case 16: |
nerit | 0:1e09cd7d66b4 | 1690 | case 17: |
nerit | 0:1e09cd7d66b4 | 1691 | break; |
nerit | 0:1e09cd7d66b4 | 1692 | case 18: |
nerit | 0:1e09cd7d66b4 | 1693 | TBmotorStepOut=0; // define step command for up down motor driver |
nerit | 0:1e09cd7d66b4 | 1694 | SDmotorPWM=0; // define step command for seeding whell motor driver |
nerit | 0:1e09cd7d66b4 | 1695 | speedClock=0; // define input of |
nerit | 0:1e09cd7d66b4 | 1696 | SDmotorInA=0; |
nerit | 0:1e09cd7d66b4 | 1697 | SDmotorInB=0; |
nerit | 0:1e09cd7d66b4 | 1698 | SDmotorPWM=0; // power mosfet 2 command out |
nerit | 0:1e09cd7d66b4 | 1699 | break; |
nerit | 0:1e09cd7d66b4 | 1700 | default: |
nerit | 0:1e09cd7d66b4 | 1701 | clocca=0; |
nerit | 0:1e09cd7d66b4 | 1702 | break; |
nerit | 0:1e09cd7d66b4 | 1703 | } |
nerit | 0:1e09cd7d66b4 | 1704 | wait_ms(100); |
nerit | 0:1e09cd7d66b4 | 1705 | #endif // end prova scheda |
nerit | 0:1e09cd7d66b4 | 1706 | |
nerit | 0:1e09cd7d66b4 | 1707 | #if defined(provaDC) |
nerit | 0:1e09cd7d66b4 | 1708 | int rampa=1000; |
nerit | 0:1e09cd7d66b4 | 1709 | int pausa=3000; |
nerit | 0:1e09cd7d66b4 | 1710 | switch (clocca){ |
nerit | 0:1e09cd7d66b4 | 1711 | case 0: |
nerit | 0:1e09cd7d66b4 | 1712 | DC_brake=0; |
nerit | 0:1e09cd7d66b4 | 1713 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1714 | duty_DC+=0.01f; |
nerit | 0:1e09cd7d66b4 | 1715 | if (duty_DC>=0.2f){ |
nerit | 0:1e09cd7d66b4 | 1716 | duty_DC=0.2f; |
nerit | 0:1e09cd7d66b4 | 1717 | clocca=1; |
nerit | 0:1e09cd7d66b4 | 1718 | } |
nerit | 0:1e09cd7d66b4 | 1719 | wait_ms(rampa); |
nerit | 0:1e09cd7d66b4 | 1720 | break; |
nerit | 0:1e09cd7d66b4 | 1721 | case 1: |
nerit | 0:1e09cd7d66b4 | 1722 | wait_ms(pausa*4); |
nerit | 0:1e09cd7d66b4 | 1723 | clocca=2; |
nerit | 0:1e09cd7d66b4 | 1724 | break; |
nerit | 0:1e09cd7d66b4 | 1725 | case 2: |
nerit | 0:1e09cd7d66b4 | 1726 | DC_brake=0; |
nerit | 0:1e09cd7d66b4 | 1727 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1728 | duty_DC-=0.01f; |
nerit | 0:1e09cd7d66b4 | 1729 | if (duty_DC<=0.0f){ |
nerit | 0:1e09cd7d66b4 | 1730 | duty_DC=0.0f; |
nerit | 0:1e09cd7d66b4 | 1731 | clocca=3; |
nerit | 0:1e09cd7d66b4 | 1732 | } |
nerit | 0:1e09cd7d66b4 | 1733 | wait_ms(rampa); |
nerit | 0:1e09cd7d66b4 | 1734 | break; |
nerit | 0:1e09cd7d66b4 | 1735 | case 3: |
nerit | 0:1e09cd7d66b4 | 1736 | wait_ms(pausa); |
nerit | 0:1e09cd7d66b4 | 1737 | clocca=4; |
nerit | 0:1e09cd7d66b4 | 1738 | break; |
nerit | 0:1e09cd7d66b4 | 1739 | case 4: |
nerit | 0:1e09cd7d66b4 | 1740 | DC_brake=0; |
nerit | 0:1e09cd7d66b4 | 1741 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1742 | duty_DC+=0.01f; |
nerit | 0:1e09cd7d66b4 | 1743 | if (duty_DC>=1.0f){ |
nerit | 0:1e09cd7d66b4 | 1744 | duty_DC=1.0f; |
nerit | 0:1e09cd7d66b4 | 1745 | clocca=5; |
nerit | 0:1e09cd7d66b4 | 1746 | } |
nerit | 0:1e09cd7d66b4 | 1747 | wait_ms(rampa); |
nerit | 0:1e09cd7d66b4 | 1748 | break; |
nerit | 0:1e09cd7d66b4 | 1749 | case 5: |
nerit | 0:1e09cd7d66b4 | 1750 | wait_ms(pausa); |
nerit | 0:1e09cd7d66b4 | 1751 | clocca=6; |
nerit | 0:1e09cd7d66b4 | 1752 | break; |
nerit | 0:1e09cd7d66b4 | 1753 | case 6: |
nerit | 0:1e09cd7d66b4 | 1754 | DC_brake=0; |
nerit | 0:1e09cd7d66b4 | 1755 | DC_forward=1; |
nerit | 0:1e09cd7d66b4 | 1756 | duty_DC-=0.01f; |
nerit | 0:1e09cd7d66b4 | 1757 | if (duty_DC<=0.0f){ |
nerit | 0:1e09cd7d66b4 | 1758 | duty_DC=0.0f; |
nerit | 0:1e09cd7d66b4 | 1759 | clocca=7; |
nerit | 0:1e09cd7d66b4 | 1760 | } |
nerit | 0:1e09cd7d66b4 | 1761 | wait_ms(rampa); |
nerit | 0:1e09cd7d66b4 | 1762 | break; |
nerit | 0:1e09cd7d66b4 | 1763 | case 7: |
nerit | 0:1e09cd7d66b4 | 1764 | wait_ms(pausa); |
nerit | 0:1e09cd7d66b4 | 1765 | clocca=0; |
nerit | 0:1e09cd7d66b4 | 1766 | break; |
nerit | 0:1e09cd7d66b4 | 1767 | default: |
nerit | 0:1e09cd7d66b4 | 1768 | break; |
nerit | 0:1e09cd7d66b4 | 1769 | } |
nerit | 0:1e09cd7d66b4 | 1770 | if (oldDuty_DC != duty_DC){ |
nerit | 0:1e09cd7d66b4 | 1771 | SDmotorPWM.write(duty_DC); // duty cycle = stop |
nerit | 0:1e09cd7d66b4 | 1772 | oldDuty_DC=duty_DC; |
nerit | 0:1e09cd7d66b4 | 1773 | DC_prepare(); |
nerit | 0:1e09cd7d66b4 | 1774 | } |
nerit | 0:1e09cd7d66b4 | 1775 | #endif |
nerit | 0:1e09cd7d66b4 | 1776 | }//end in prova |
nerit | 0:1e09cd7d66b4 | 1777 | wd.Service(); // kick the dog before the timeout |
nerit | 0:1e09cd7d66b4 | 1778 | } // end while |
nerit | 0:1e09cd7d66b4 | 1779 | }// end main |
nerit | 0:1e09cd7d66b4 | 1780 |