tr

Dependencies:   mbed CANMsg

Committer:
nerit
Date:
Tue Oct 02 07:05:52 2018 +0000
Revision:
9:503e2aba047c
Parent:
8:0e643ea7834f
Child:
10:d85ed006056e
Versione del 24 luglio 2018

Who changed what in which revision?

UserRevisionLine numberNew 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 5:3b95bbfe2dc9 105 // rise of seed speed motor encoder
nerit 5:3b95bbfe2dc9 106 void encoRise(){
nerit 5:3b95bbfe2dc9 107 timeHole=metalTimer.read_us();
nerit 5:3b95bbfe2dc9 108 int memo_TimeHole= (memoTimeHole + timeHole)/ (int)2;
nerit 5:3b95bbfe2dc9 109 memoTimeHole = timeHole;
nerit 5:3b95bbfe2dc9 110 metalTimer.reset();
nerit 5:3b95bbfe2dc9 111 if (encoder==true){
nerit 5:3b95bbfe2dc9 112 speedOfSeedWheel=((seedPerimeter/((SDreductionRatio*25.5f)))/(double)memo_TimeHole)*1000000.0f; //mtS
nerit 7:c9fd242538d9 113 pulseRised2=1;
nerit 5:3b95bbfe2dc9 114 }
nerit 5:3b95bbfe2dc9 115 }
nerit 7:c9fd242538d9 116 // rise of seed presence sensor
nerit 7:c9fd242538d9 117 void seedSensorTask(){
nerit 7:c9fd242538d9 118 seedSee=1;
nerit 7:c9fd242538d9 119 }
nerit 0:1e09cd7d66b4 120 //**************************************************
nerit 0:1e09cd7d66b4 121 // generate speed clock when speed is simulated from Tritecnica display
nerit 0:1e09cd7d66b4 122 void speedSimulationClock(){
nerit 0:1e09cd7d66b4 123 lastPulseRead=speedTimer.read_us();
nerit 0:1e09cd7d66b4 124 oldLastPulseRead=lastPulseRead;
nerit 0:1e09cd7d66b4 125 speedTimer.reset();
nerit 0:1e09cd7d66b4 126 pulseRised=1;
nerit 7:c9fd242538d9 127 speedFilter.reset();
nerit 0:1e09cd7d66b4 128 }
nerit 0:1e09cd7d66b4 129 //*******************************************************
nerit 0:1e09cd7d66b4 130 // interrupt task for tractor speed reading
nerit 0:1e09cd7d66b4 131 //*******************************************************
nerit 0:1e09cd7d66b4 132 void tractorReadSpeed(){
nerit 0:1e09cd7d66b4 133 if ((oldTractorSpeedRead==0)){
nerit 0:1e09cd7d66b4 134 lastPulseRead=speedTimer.read_us();
nerit 0:1e09cd7d66b4 135 oldLastPulseRead=lastPulseRead;
nerit 0:1e09cd7d66b4 136 speedTimer.reset();
nerit 0:1e09cd7d66b4 137 pulseRised=1;
nerit 0:1e09cd7d66b4 138 oldTractorSpeedRead=1;
nerit 6:3fca0ca1949e 139 spazioCoperto+= pulseDistance;
nerit 0:1e09cd7d66b4 140 }
nerit 0:1e09cd7d66b4 141 speedFilter.reset();
nerit 0:1e09cd7d66b4 142 speedClock=1;
nerit 0:1e09cd7d66b4 143 }
nerit 0:1e09cd7d66b4 144 //*******************************************************
nerit 0:1e09cd7d66b4 145 void speedMediaCalc(){
nerit 0:1e09cd7d66b4 146 double lastPd=(double) lastPulseRead/1000.0f;
nerit 0:1e09cd7d66b4 147 pulseSpeedInterval = (mediaSpeed[0]+lastPd)/2.0f;
nerit 0:1e09cd7d66b4 148 if (enableSimula==1){
nerit 0:1e09cd7d66b4 149 double TMT = (double)(speedSimula) * 100.0f /3600.0f;
nerit 0:1e09cd7d66b4 150 pulseSpeedInterval = pulseDistance / TMT;
nerit 0:1e09cd7d66b4 151 }
nerit 0:1e09cd7d66b4 152 mediaSpeed[0]=lastPd;
nerit 0:1e09cd7d66b4 153 OLDpulseSpeedInterval=pulseSpeedInterval;
nerit 0:1e09cd7d66b4 154 }
nerit 0:1e09cd7d66b4 155
nerit 0:1e09cd7d66b4 156 //*******************************************************
nerit 0:1e09cd7d66b4 157 // clocked task for manage virtual encoder of seed wheel i/o
nerit 0:1e09cd7d66b4 158 //*******************************************************
nerit 0:1e09cd7d66b4 159 //*******************************************************
nerit 0:1e09cd7d66b4 160 void step_SDPulseOut(){
nerit 0:1e09cd7d66b4 161 SDactualPosition++;
nerit 0:1e09cd7d66b4 162 prePosSD++;
nerit 5:3b95bbfe2dc9 163 #if defined(speedMaster)
nerit 5:3b95bbfe2dc9 164 posForQuinc++;
nerit 5:3b95bbfe2dc9 165 #endif
nerit 0:1e09cd7d66b4 166 }
nerit 0:1e09cd7d66b4 167 //*******************************************************
nerit 0:1e09cd7d66b4 168 void step_TBPulseOut(){
nerit 0:1e09cd7d66b4 169 TBmotorStepOut=!TBmotorStepOut;
nerit 0:1e09cd7d66b4 170 if (TBmotorStepOut==0){
nerit 9:503e2aba047c 171 if (TBmotorDirecti==1){
nerit 9:503e2aba047c 172 TBactualPosition++;
nerit 9:503e2aba047c 173 }else{
nerit 9:503e2aba047c 174 TBactualPosition--;
nerit 9:503e2aba047c 175 }
nerit 0:1e09cd7d66b4 176 }
nerit 0:1e09cd7d66b4 177 }
nerit 0:1e09cd7d66b4 178 //*******************************************************
nerit 0:1e09cd7d66b4 179 // aggiornamento parametri di lavoro fissi e da Tritecnica
nerit 0:1e09cd7d66b4 180 void aggiornaParametri(){
nerit 0:1e09cd7d66b4 181 speedPerimeter = Pi * speedWheelDiameter ; // perimeter of speed wheel
nerit 0:1e09cd7d66b4 182 pulseDistance = (speedPerimeter / speedWheelPulse)*1000.0f; // linear space between speed wheel pulse
nerit 0:1e09cd7d66b4 183 seedPerimeter = Pi * (seedWheelDiameter-(deepOfSeed*2.0f)); // perimeter of seed wheel
nerit 0:1e09cd7d66b4 184 intraPickDistance = seedPerimeter/pickNumber;
nerit 0:1e09cd7d66b4 185 K_WheelRPM = 60.0f/seedPerimeter; // calcola il K per i giri al minuto della ruota di semina
nerit 0:1e09cd7d66b4 186 K_WhellFrequency = (seedWheelMotorSteps*SDreductionRatio)/60.0f; // calcola il K per la frequenza di comando del motore di semina
nerit 0:1e09cd7d66b4 187 rapportoRuote = pickNumber/cellsNumber; // calcola il rapporto tra il numero di becchi ed il numero di celle
nerit 0:1e09cd7d66b4 188 K_percentuale = TBmotorSteps*TBreductionRatio;
nerit 0:1e09cd7d66b4 189 SDsectorStep = (double)fixedStepGiroSD / (double)pickNumber;
nerit 0:1e09cd7d66b4 190 TBsectorStep = (TBmotorSteps*TBreductionRatio)/cellsNumber;
nerit 0:1e09cd7d66b4 191 KcorT = (SDsectorStep/TBsectorStep);///2.0f;
nerit 0:1e09cd7d66b4 192 angoloFase=angoloPh;
nerit 0:1e09cd7d66b4 193 avvioGradi=angoloAv;
nerit 0:1e09cd7d66b4 194 stepGrado=fixedStepGiroSD/360.0f;
nerit 0:1e09cd7d66b4 195 TBdeltaStep=(fixedStepGiroSD/pickNumber)+(stepGrado*avvioGradi);
nerit 0:1e09cd7d66b4 196 TBfaseStep = (stepGrado*angoloFase);
nerit 0:1e09cd7d66b4 197 K_WheelRPM = 60.0f/seedPerimeter; // calcola il K per i giri al minuto della ruota di semina 25.4 25,40
nerit 7:c9fd242538d9 198 TBgiroStep = TBmotorSteps*TBreductionRatio;
nerit 7:c9fd242538d9 199 K_TBfrequency = TBgiroStep/60.0f; // 1600 * 1.65625f /60 = 44 44,00
nerit 0:1e09cd7d66b4 200 if (speedFromPick==1) {
nerit 0:1e09cd7d66b4 201 intraPickDistance = seedPerimeter/pickNumber;
nerit 0:1e09cd7d66b4 202 }else{
nerit 0:1e09cd7d66b4 203 intraPickDistance = seedPerimeter/25.0f; // 25 è il numero di fori presenti nel disco di semina
nerit 0:1e09cd7d66b4 204 }
nerit 0:1e09cd7d66b4 205 }
nerit 0:1e09cd7d66b4 206 //*******************************************************
nerit 0:1e09cd7d66b4 207 void cambiaTB(double perio){
nerit 0:1e09cd7d66b4 208 // update TB frequency
nerit 0:1e09cd7d66b4 209 double TBper=0.0f;
nerit 0:1e09cd7d66b4 210 if (aspettaStart==0){
nerit 0:1e09cd7d66b4 211 if (perio<250.0f){perio=500.0f;}
nerit 0:1e09cd7d66b4 212 double scala =0.0f;
nerit 0:1e09cd7d66b4 213 if (lowSpeed==1){
nerit 0:1e09cd7d66b4 214 scala =2.0f;
nerit 0:1e09cd7d66b4 215 }else{
nerit 0:1e09cd7d66b4 216 scala =1.8f;
nerit 0:1e09cd7d66b4 217 }
nerit 0:1e09cd7d66b4 218 TBper=perio/scala;
nerit 0:1e09cd7d66b4 219 if (oldPeriodoTB!=TBper){
nerit 0:1e09cd7d66b4 220 if (TBper >= 250.0f){
nerit 0:1e09cd7d66b4 221 TBticker.attach_us(&step_TBPulseOut,TBper); // clock time are milliseconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 222 }else{
nerit 0:1e09cd7d66b4 223 TBticker.detach();
nerit 0:1e09cd7d66b4 224 }
nerit 0:1e09cd7d66b4 225 oldPeriodoTB=TBper;
nerit 0:1e09cd7d66b4 226 }
nerit 0:1e09cd7d66b4 227 }
nerit 0:1e09cd7d66b4 228 }
nerit 0:1e09cd7d66b4 229 //*******************************************************
nerit 0:1e09cd7d66b4 230 void seedCorrect(){
nerit 0:1e09cd7d66b4 231 /*
nerit 0:1e09cd7d66b4 232 posError determina la posizione relativa di TB rispetto ad SD
nerit 0:1e09cd7d66b4 233 la reale posizione di SD viene modificata in funzione della velocità per
nerit 0:1e09cd7d66b4 234 traslare la posizione relativa di TB. All'aumentare della velocità la posizione
nerit 0:1e09cd7d66b4 235 di SD viene incrementata così che TB acceleri per raggiungerla in modo da rilasciare il seme prima
nerit 0:1e09cd7d66b4 236 La taratura del sistema avviene determinando prima il valore di angoloFase alla minima velocità,
nerit 0:1e09cd7d66b4 237 poi, alla massima velocità, dovrebbe spostarsi la posizione relativa con una variabile proporzionale alla velocità, ma c'è un però.
nerit 0:1e09cd7d66b4 238 Il problema è che il momento di avvio determina una correzione dell'angolo di partenza del tamburo
nerit 0:1e09cd7d66b4 239 angolo che viene rideterminato ogni volta che il sensore becchi legge un transito.
nerit 0:1e09cd7d66b4 240 Di fatto c'è una concorrenza tra l'angolo di avvio determinato e la correzione di posizione relativa
nerit 0:1e09cd7d66b4 241 del tamburo. E' molto probabile che convenga modificare solo la posizione relativa e non anche l'angolo di avvio
nerit 0:1e09cd7d66b4 242 Ancora di più se viene eliminata la parte gestita da ciclata.
nerit 0:1e09cd7d66b4 243 In questo modo dovrebbe esserci solo un andamento in accelerazione di TB che viene poi eventualmente decelerato
nerit 0:1e09cd7d66b4 244 dal passaggio sul sensore di TB. Funzione corretta perchè il sincronismo tra i sensori genera l'inibizione della correzione
nerit 0:1e09cd7d66b4 245 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 246 Appena il sensore di TB viene impegnato allora viene abilitato il controllo di fase del tamburo.
nerit 0:1e09cd7d66b4 247 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 248 il tamburo non risenta della condizione di reset della posizione di SD mentre lui è ancora nella fase precedente. Si fermerebbe.
nerit 0:1e09cd7d66b4 249
nerit 0:1e09cd7d66b4 250 // La considerazione finale è che mantenendo l'angolo di avvio fisso e regolato sulla bassa velocità, intervenendo solo sulla correzione
nerit 0:1e09cd7d66b4 251 // di posizione in questa routine, dovrebbe essere possibile seminare correttamente a tutte le velocità regolando solo 2 parametri.
nerit 0:1e09cd7d66b4 252 */
nerit 0:1e09cd7d66b4 253 /*
nerit 0:1e09cd7d66b4 254 SDsectorStep = (double)fixedStepGiroSD / (double)pickNumber;
nerit 0:1e09cd7d66b4 255 TBsectorStep = (TBmotorSteps*TBreductionRatio)/cellsNumber;
nerit 0:1e09cd7d66b4 256 KcorT = (SDsectorStep/TBsectorStep);
nerit 0:1e09cd7d66b4 257 angoloFase=angoloPh;
nerit 0:1e09cd7d66b4 258 stepGrado=fixedStepGiroSD/360.0f;
nerit 0:1e09cd7d66b4 259 avvioGradi = costante da terminale tritecnica
nerit 0:1e09cd7d66b4 260 TBdeltaStep=(fixedStepGiroSD/pickNumber)-(stepGrado*avvioGradi);
nerit 0:1e09cd7d66b4 261 TBfaseStep = (stepGrado*angoloFase);
nerit 0:1e09cd7d66b4 262 */
nerit 0:1e09cd7d66b4 263
nerit 0:1e09cd7d66b4 264 if ((tractorSpeed_MtS_timed>0.01f)){
nerit 0:1e09cd7d66b4 265 if (inhibit==0){
nerit 0:1e09cd7d66b4 266 double posError =0.0f;
nerit 0:1e09cd7d66b4 267 double posSD=((double)SDactualPosition)/KcorT;
nerit 0:1e09cd7d66b4 268 posError = posSD - (double)TBactualPosition;
nerit 0:1e09cd7d66b4 269 // interviene sulla velocità di TB per raggiungere la corretta posizione relativa
nerit 0:1e09cd7d66b4 270 if((lowSpeed==0)&&(aspettaStart==0)){
nerit 0:1e09cd7d66b4 271 if (posError>50.0f){posError=50.0f;}
nerit 0:1e09cd7d66b4 272 if (posError<-50.0f){posError=-50.0f;}
nerit 0:1e09cd7d66b4 273 if ((posError >=1.0f)||(posError<=-1.0f)){
nerit 0:1e09cd7d66b4 274 ePpos = periodo /(1.0f+ ((posError/100.0f)));
nerit 0:1e09cd7d66b4 275 cambiaTB(ePpos);
nerit 0:1e09cd7d66b4 276 }
nerit 0:1e09cd7d66b4 277 }
nerit 0:1e09cd7d66b4 278 }
nerit 4:d32258ec411f 279 }
nerit 4:d32258ec411f 280 }
nerit 4:d32258ec411f 281 //*******************************************************
nerit 4:d32258ec411f 282 void videoUpdate(){
nerit 4:d32258ec411f 283 for(int aa=0;aa<4;aa++){speedForDisplay[aa]=speedForDisplay[aa+1];}
nerit 4:d32258ec411f 284 speedForDisplay[4]=tractorSpeed_MtS_timed;
nerit 4:d32258ec411f 285 totalSpeed=0.0f;
nerit 4:d32258ec411f 286 for (int aa=0; aa<5; aa++){totalSpeed += speedForDisplay[aa];}
nerit 4:d32258ec411f 287 totalSpeed = totalSpeed / 5.0f;
nerit 0:1e09cd7d66b4 288 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 289 #if defined(SDreset)
nerit 0:1e09cd7d66b4 290 pc.printf("Fase: %d",fase);
nerit 0:1e09cd7d66b4 291 pc.printf(" PrePosSD: %d",prePosSD);
nerit 0:1e09cd7d66b4 292 pc.printf(" PosSD: %d",SDactualPosition);
nerit 0:1e09cd7d66b4 293 pc.printf(" speed: %f",tractorSpeed_MtS_timed);
nerit 0:1e09cd7d66b4 294 pc.printf(" Trigger: %d \n", trigRepos);
nerit 0:1e09cd7d66b4 295 #endif
nerit 0:1e09cd7d66b4 296 #endif
nerit 0:1e09cd7d66b4 297 }
nerit 0:1e09cd7d66b4 298 //*******************************************************
nerit 0:1e09cd7d66b4 299 void ciclaTB(){
nerit 0:1e09cd7d66b4 300 if ((startCicloTB==1)&&(cicloTbinCorso==0)){
nerit 0:1e09cd7d66b4 301 TBticker.attach_us(&step_TBPulseOut,TBperiod/2.5f); // clock time are milliseconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 302 cicloTbinCorso = 1;
nerit 0:1e09cd7d66b4 303 startCicloTB=0;
nerit 0:1e09cd7d66b4 304 }
nerit 0:1e09cd7d66b4 305 if ((loadDaCan==1)&&(loadDaCanInCorso==0)){
nerit 0:1e09cd7d66b4 306 TBticker.attach_us(&step_TBPulseOut,1000.0f); // clock time are milliseconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 307 loadDaCanInCorso=1;
nerit 0:1e09cd7d66b4 308 stopCicloTB=0;
nerit 0:1e09cd7d66b4 309 }
nerit 0:1e09cd7d66b4 310 if ((stopCicloTB==1)&&(TBactualPosition>5)){
nerit 0:1e09cd7d66b4 311 TBticker.detach();
nerit 0:1e09cd7d66b4 312 cicloTbinCorso = 0;
nerit 0:1e09cd7d66b4 313 stopCicloTB=0;
nerit 0:1e09cd7d66b4 314 loadDaCanInCorso=0;
nerit 0:1e09cd7d66b4 315 loadDaCan=0;
nerit 0:1e09cd7d66b4 316 }
nerit 0:1e09cd7d66b4 317 }
nerit 7:c9fd242538d9 318 // ------------------------------------------------------------------------------------------------------------------------------------------------------------------
nerit 7:c9fd242538d9 319 void stepSetting(){
nerit 7:c9fd242538d9 320 // Stepper driver init and set
nerit 7:c9fd242538d9 321 TBmotorRst=1; // reset stepper driver
nerit 9:503e2aba047c 322 if (tractorSpeed_MtS_timed==0.0f){
nerit 9:503e2aba047c 323 TBmotorDirecti=1; // reset stepper direction
nerit 9:503e2aba047c 324 }
nerit 7:c9fd242538d9 325 // M1 M2 M3 RESOLUTION
nerit 7:c9fd242538d9 326 // 0 0 0 1/2
nerit 7:c9fd242538d9 327 // 1 0 0 1/8
nerit 7:c9fd242538d9 328 // 0 1 0 1/16
nerit 7:c9fd242538d9 329 // 1 1 0 1/32
nerit 7:c9fd242538d9 330 // 0 0 1 1/64
nerit 7:c9fd242538d9 331 // 1 0 1 1/128
nerit 7:c9fd242538d9 332 // 0 1 1 1/10
nerit 7:c9fd242538d9 333 // 1 1 1 1/20
nerit 7:c9fd242538d9 334 if (TBmotorSteps==400){
nerit 7:c9fd242538d9 335 TBmotor_M1=1;
nerit 7:c9fd242538d9 336 TBmotor_M2=1;
nerit 7:c9fd242538d9 337 TBmotor_M3=1;
nerit 7:c9fd242538d9 338 }else if (TBmotorSteps==1600){
nerit 7:c9fd242538d9 339 TBmotor_M1=0;
nerit 7:c9fd242538d9 340 TBmotor_M2=1;
nerit 7:c9fd242538d9 341 TBmotor_M3=1;
nerit 7:c9fd242538d9 342 }else if (TBmotorSteps==3200){
nerit 7:c9fd242538d9 343 TBmotor_M1=1;
nerit 7:c9fd242538d9 344 TBmotor_M2=0;
nerit 7:c9fd242538d9 345 TBmotor_M3=1;
nerit 7:c9fd242538d9 346 }else if (TBmotorSteps==6400){
nerit 7:c9fd242538d9 347 TBmotor_M1=0;
nerit 7:c9fd242538d9 348 TBmotor_M2=0;
nerit 7:c9fd242538d9 349 TBmotor_M3=1;
nerit 7:c9fd242538d9 350 }else if (TBmotorSteps==12800){
nerit 7:c9fd242538d9 351 TBmotor_M1=1;
nerit 7:c9fd242538d9 352 TBmotor_M2=1;
nerit 7:c9fd242538d9 353 TBmotor_M3=0;
nerit 7:c9fd242538d9 354 }else if (TBmotorSteps==25600){
nerit 7:c9fd242538d9 355 TBmotor_M1=0;
nerit 7:c9fd242538d9 356 TBmotor_M2=1;
nerit 7:c9fd242538d9 357 TBmotor_M3=0;
nerit 7:c9fd242538d9 358 }else if (TBmotorSteps==2000){
nerit 7:c9fd242538d9 359 TBmotor_M1=1;
nerit 7:c9fd242538d9 360 TBmotor_M2=0;
nerit 7:c9fd242538d9 361 TBmotor_M3=0;
nerit 7:c9fd242538d9 362 }else if (TBmotorSteps==4000){
nerit 7:c9fd242538d9 363 TBmotor_M1=0;
nerit 7:c9fd242538d9 364 TBmotor_M2=0;
nerit 7:c9fd242538d9 365 TBmotor_M3=0;
nerit 7:c9fd242538d9 366 }
nerit 7:c9fd242538d9 367 TBmotorRst=0;
nerit 7:c9fd242538d9 368 }
nerit 7:c9fd242538d9 369 //****************************************
nerit 7:c9fd242538d9 370 void dcSetting(){
nerit 7:c9fd242538d9 371 if ((speedFromPick==0)&&(encoder==false)){
nerit 7:c9fd242538d9 372 DcEncoder.rise(&sd25Fall);
nerit 7:c9fd242538d9 373 }
nerit 7:c9fd242538d9 374 if (encoder==true){
nerit 7:c9fd242538d9 375 DcEncoder.rise(&encoRise);
nerit 7:c9fd242538d9 376 //ElementPosition.fall(&encoRise);
nerit 7:c9fd242538d9 377 }
nerit 7:c9fd242538d9 378 }
nerit 0:1e09cd7d66b4 379 //*******************************************************
nerit 0:1e09cd7d66b4 380 void allarmi(){
nerit 0:1e09cd7d66b4 381 uint8_t alarmLowRegister1=0x00;
nerit 0:1e09cd7d66b4 382 alarmLowRegister=0x00;
nerit 0:1e09cd7d66b4 383 alarmHighRegister=0x80;
nerit 0:1e09cd7d66b4 384
nerit 0:1e09cd7d66b4 385 //alarmLowRegister=alarmLowRegister+(all_semiFiniti*0x01); // manca il sensore
nerit 0:1e09cd7d66b4 386 alarmLowRegister=alarmLowRegister+(all_pickSignal*0x02); // fatto
nerit 0:1e09cd7d66b4 387 alarmLowRegister=alarmLowRegister+(all_cellSignal*0x04); // fatto
nerit 0:1e09cd7d66b4 388 alarmLowRegister=alarmLowRegister+(all_lowBattery*0x08); // fatto
nerit 0:1e09cd7d66b4 389 alarmLowRegister=alarmLowRegister+(all_overCurrDC*0x10); // fatto
nerit 0:1e09cd7d66b4 390 alarmLowRegister=alarmLowRegister+(all_stopSistem*0x20); // verificarne la necessità
nerit 0:1e09cd7d66b4 391 //alarmLowRegister=alarmLowRegister+(all_upElements*0x40); // manca il sensore
nerit 7:c9fd242538d9 392 if (seedSensorEnable==true){
nerit 7:c9fd242538d9 393 alarmLowRegister=alarmLowRegister+(all_noSeedOnCe*0x80); // manca il sensore
nerit 7:c9fd242538d9 394 }
nerit 0:1e09cd7d66b4 395
nerit 0:1e09cd7d66b4 396 //alarmLowRegister1=alarmLowRegister1+(all_cfgnErrors*0x01); // da scrivere
nerit 0:1e09cd7d66b4 397 alarmLowRegister1=alarmLowRegister1+(all_noDcRotati*0x02); // fatto
nerit 0:1e09cd7d66b4 398 alarmLowRegister1=alarmLowRegister1+(all_noStepRota*0x04); // fatto
nerit 0:1e09cd7d66b4 399 alarmLowRegister1=alarmLowRegister1+(all_speedError*0x08); // fatto
nerit 0:1e09cd7d66b4 400 alarmLowRegister1=alarmLowRegister1+(all_noSpeedSen*0x10); // fatto
nerit 0:1e09cd7d66b4 401 alarmLowRegister1=alarmLowRegister1+(all_no_Zeroing*0x20); // fatto
nerit 0:1e09cd7d66b4 402 alarmLowRegister1=alarmLowRegister1+(all_genericals*0x40);
nerit 0:1e09cd7d66b4 403 if (alarmLowRegister1 > 0){
nerit 0:1e09cd7d66b4 404 alarmHighRegister = 0x81;
nerit 0:1e09cd7d66b4 405 alarmLowRegister = alarmLowRegister1;
nerit 0:1e09cd7d66b4 406 }
nerit 0:1e09cd7d66b4 407
nerit 0:1e09cd7d66b4 408 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 409 #if defined(VediAllarmi)
nerit 0:1e09cd7d66b4 410 if (all_pickSignal==1){pc.printf("AllarmeBecchi\n");}
nerit 0:1e09cd7d66b4 411 if (all_cellSignal==1){pc.printf("AllarmeCelle\n");}
nerit 0:1e09cd7d66b4 412 if (all_lowBattery==1){pc.printf("AllarmeBassaCorrente\n");}
nerit 0:1e09cd7d66b4 413 if (all_overCurrDC==1){pc.printf("AllarmeAltaCorrente\n");}
nerit 0:1e09cd7d66b4 414 if (all_stopSistem==1){pc.printf("AllarmeStop\n");}
nerit 0:1e09cd7d66b4 415 if (all_noDcRotati==1){pc.printf("AllarmeDCnoRotation\n");}
nerit 0:1e09cd7d66b4 416 if (all_noStepRota==1){pc.printf("AllarmeNoStepRotation\n");}
nerit 0:1e09cd7d66b4 417 if (all_speedError==1){pc.printf("AllarmeSpeedError\n");}
nerit 0:1e09cd7d66b4 418 if (all_noSpeedSen==1){pc.printf("AllarmeNoSpeedSensor\n");}
nerit 0:1e09cd7d66b4 419 if (all_no_Zeroing==1){pc.printf("AllarmeNoZero\n");}
nerit 0:1e09cd7d66b4 420 if (all_genericals==1){pc.printf("AllarmeGenerico\n");}
nerit 0:1e09cd7d66b4 421 pc.printf("Code: 0x%x%x\n",alarmHighRegister,alarmLowRegister);
nerit 0:1e09cd7d66b4 422 #endif
nerit 0:1e09cd7d66b4 423 #endif
nerit 0:1e09cd7d66b4 424 all_semiFiniti=0;
nerit 0:1e09cd7d66b4 425 all_pickSignal=0;
nerit 0:1e09cd7d66b4 426 all_cellSignal=0;
nerit 0:1e09cd7d66b4 427 all_lowBattery=0;
nerit 0:1e09cd7d66b4 428 all_overCurrDC=0;
nerit 0:1e09cd7d66b4 429 all_stopSistem=0;
nerit 0:1e09cd7d66b4 430 all_upElements=0;
nerit 0:1e09cd7d66b4 431 all_noSeedOnCe=0;
nerit 0:1e09cd7d66b4 432 all_cfgnErrors=0;
nerit 0:1e09cd7d66b4 433 all_noDcRotati=0;
nerit 0:1e09cd7d66b4 434 all_noStepRota=0;
nerit 0:1e09cd7d66b4 435 all_speedError=0;
nerit 0:1e09cd7d66b4 436 all_noSpeedSen=0;
nerit 0:1e09cd7d66b4 437 all_no_Zeroing=0;
nerit 0:1e09cd7d66b4 438 all_genericals=0;
nerit 0:1e09cd7d66b4 439 }
nerit 0:1e09cd7d66b4 440 //*******************************************************
nerit 0:1e09cd7d66b4 441 #if defined(speedMaster)
nerit 0:1e09cd7d66b4 442 void upDateSincro(){
nerit 0:1e09cd7d66b4 443 char val1[8]={0,0,0,0,0,0,0,0};
nerit 7:c9fd242538d9 444 val1[3]=(posForQuinc /0x00FF0000)&0x000000FF;
nerit 7:c9fd242538d9 445 val1[2]=(posForQuinc /0x0000FF00)&0x000000FF;
nerit 7:c9fd242538d9 446 val1[1]=(posForQuinc /0x000000FF)&0x000000FF;
nerit 7:c9fd242538d9 447 val1[0]=posForQuinc & 0x000000FF;
nerit 7:c9fd242538d9 448 //double pass = tractorSpeed_MtS_timed*100.0f;
nerit 7:c9fd242538d9 449 double pass = speedOfSeedWheel*100.0f;
nerit 5:3b95bbfe2dc9 450 val1[4]=(uint8_t)(pass)&0x000000FF;
nerit 5:3b95bbfe2dc9 451 val1[5]=(prePosSD /0x0000FF00)&0x000000FF;
nerit 5:3b95bbfe2dc9 452 val1[6]=(prePosSD /0x000000FF)&0x000000FF;
nerit 5:3b95bbfe2dc9 453 val1[7]=prePosSD & 0x000000FF;
nerit 0:1e09cd7d66b4 454 #if defined(canbusActive)
nerit 0:1e09cd7d66b4 455 #if defined(speedMaster)
nerit 0:1e09cd7d66b4 456 if(can1.write(CANMessage(TX_SI, *&val1,8))){
nerit 0:1e09cd7d66b4 457 checkState=0;
nerit 0:1e09cd7d66b4 458 }
nerit 0:1e09cd7d66b4 459 #endif
nerit 0:1e09cd7d66b4 460 #endif
nerit 0:1e09cd7d66b4 461 }
nerit 0:1e09cd7d66b4 462 #endif
nerit 0:1e09cd7d66b4 463 //*******************************************************
nerit 0:1e09cd7d66b4 464 void upDateSpeed(){
nerit 0:1e09cd7d66b4 465 /*
nerit 0:1e09cd7d66b4 466 aggiorna dati OPUSA3
nerit 0:1e09cd7d66b4 467 val1[0] contiene il dato di velocità
nerit 0:1e09cd7d66b4 468 val1[1] contiene il byte basso della tabella allarmi
nerit 0:1e09cd7d66b4 469 uint8_t all_semiFiniti = 0; // semi finiti (generato dal relativo sensore)
nerit 0:1e09cd7d66b4 470 uint8_t all_pickSignal = 0; // errore segnale becchi (generato dal tempo tra un becco ed il successivo)
nerit 0:1e09cd7d66b4 471 uint8_t all_cellSignal = 0; // errore segnale celle (generato dal sensore tamburo )
nerit 0:1e09cd7d66b4 472 uint8_t all_lowBattery = 0; // allarme batteria (valore interno di tritecnica)
nerit 0:1e09cd7d66b4 473 uint8_t all_overCurrDC = 0; // sovracorrente motore DC (generato dal sensore di corrente)
nerit 0:1e09cd7d66b4 474 uint8_t all_stopSistem = 0; // sistema in stop (a tempo con ruota ferma)
nerit 0:1e09cd7d66b4 475 uint8_t all_upElements = 0; // elementi sollevati (generato dal relativo sensore)
nerit 0:1e09cd7d66b4 476 uint8_t all_noSeedOnCe = 0; // fallanza di semina (manca il seme nella cella)
nerit 0:1e09cd7d66b4 477 uint8_t all_cfgnErrors = 0; // errore di configurazione (incongruenza dei parametri impostati)
nerit 0:1e09cd7d66b4 478 uint8_t all_noDcRotati = 0; // ruota di semina bloccata (arriva la velocità ma non i becchi)
nerit 0:1e09cd7d66b4 479 uint8_t all_noStepRota = 0; // tamburo di semina bloccato (comando il tamburo ma non ricevo il sensore)
nerit 0:1e09cd7d66b4 480 uint8_t all_speedError = 0; // errore sensore velocità (tempo impulsi non costante)
nerit 0:1e09cd7d66b4 481 uint8_t all_noSpeedSen = 0; // mancanza segnale di velocità (sento i becchi ma non la velocita)
nerit 0:1e09cd7d66b4 482 uint8_t all_no_Zeroing = 0; // mancato azzeramento sistema (generato dal timeout del comando motore DC)
nerit 0:1e09cd7d66b4 483 uint8_t all_genericals = 0; // allarme generico
nerit 0:1e09cd7d66b4 484 val1[2] contiene il byte alto della tabella di allarmi
nerit 0:1e09cd7d66b4 485 val1[3] contiene i segnali per la diagnostica
nerit 0:1e09cd7d66b4 486 bit 0= sensore ruota fonica
nerit 0:1e09cd7d66b4 487 bit 1= sensore celle
nerit 0:1e09cd7d66b4 488 bit 2= sensore posizione
nerit 0:1e09cd7d66b4 489 bit 3= sensore becchi
nerit 0:1e09cd7d66b4 490 bit 4= motore DC
nerit 0:1e09cd7d66b4 491 bit 5= controller
nerit 0:1e09cd7d66b4 492 bit 6= motore stepper
nerit 0:1e09cd7d66b4 493 */
nerit 0:1e09cd7d66b4 494 char val1[8]={0,0,0,0,0,0,0,0};
nerit 0:1e09cd7d66b4 495
nerit 0:1e09cd7d66b4 496 val1[3]=0;
nerit 0:1e09cd7d66b4 497 val1[3]=val1[3]+(tractorSpeedRead*0x01);
nerit 3:c0f11ca4df02 498 val1[3]=val1[3]+(TBzeroPinInput*0x02);
nerit 7:c9fd242538d9 499 val1[3]=val1[3]+(DcEncoder*0x04);
nerit 3:c0f11ca4df02 500 val1[3]=val1[3]+(seedWheelZeroPinInput*0x08);
nerit 0:1e09cd7d66b4 501 #if defined(simulaPerCan)
nerit 0:1e09cd7d66b4 502 if (buttonUser==0){
nerit 0:1e09cd7d66b4 503 val1[1]=0x02;
nerit 0:1e09cd7d66b4 504 }else{
nerit 0:1e09cd7d66b4 505 val1[1]=0x00;
nerit 0:1e09cd7d66b4 506 }
nerit 0:1e09cd7d66b4 507 val1[3]=valore;
nerit 0:1e09cd7d66b4 508 valore+=1;
nerit 0:1e09cd7d66b4 509 if(valore>50){
nerit 0:1e09cd7d66b4 510 valore=0;
nerit 0:1e09cd7d66b4 511 }
nerit 0:1e09cd7d66b4 512 tractorSpeed_MtS_timed=valore;
nerit 0:1e09cd7d66b4 513 #endif
nerit 0:1e09cd7d66b4 514 allarmi();
nerit 0:1e09cd7d66b4 515 valore = totalSpeed*36.0f; // tractorSpeed_MtS_timed*36.0f;
nerit 0:1e09cd7d66b4 516 val1[0]=valore;
nerit 0:1e09cd7d66b4 517 val1[1]=alarmHighRegister; // registro alto allarmi. Parte sempre da 0x80
nerit 0:1e09cd7d66b4 518 val1[2]=alarmLowRegister; // registro basso allarmi
nerit 0:1e09cd7d66b4 519 //val1[3]=val1[3];// registro di stato degli ingressi
nerit 0:1e09cd7d66b4 520 val1[4]=resetComandi;
nerit 0:1e09cd7d66b4 521 val1[5]=cellsCounterLow;
nerit 0:1e09cd7d66b4 522 val1[6]=cellsCounterHig;
nerit 0:1e09cd7d66b4 523 #if defined(canbusActive)
nerit 0:1e09cd7d66b4 524 if(can1.write(CANMessage(TX_ID, *&val1,8))){
nerit 0:1e09cd7d66b4 525 checkState=0;
nerit 0:1e09cd7d66b4 526 }
nerit 0:1e09cd7d66b4 527 #endif
nerit 0:1e09cd7d66b4 528 }
nerit 0:1e09cd7d66b4 529 //*******************************************************
nerit 0:1e09cd7d66b4 530 void leggiCAN(){
nerit 0:1e09cd7d66b4 531 #if defined(canbusActive)
nerit 0:1e09cd7d66b4 532 if(can1.read(rxMsg)) {
nerit 0:1e09cd7d66b4 533 if (firstStart==1){
nerit 0:1e09cd7d66b4 534 #if defined(speedMaster)
nerit 5:3b95bbfe2dc9 535 sincUpdate.attach(&upDateSincro,0.009f);
nerit 7:c9fd242538d9 536 canUpdate.attach(&upDateSpeed,0.21f);
nerit 7:c9fd242538d9 537 #else
nerit 7:c9fd242538d9 538 canUpdate.attach(&upDateSpeed,0.407f);
nerit 0:1e09cd7d66b4 539 #endif
nerit 0:1e09cd7d66b4 540 firstStart=0;
nerit 0:1e09cd7d66b4 541 }
nerit 0:1e09cd7d66b4 542
nerit 0:1e09cd7d66b4 543 if (rxMsg.id==RX_ID){
nerit 0:1e09cd7d66b4 544 #if defined(pcSerial)
nerit 7:c9fd242538d9 545 #if defined(canDataReceiveda)
nerit 0:1e09cd7d66b4 546 pc.printf("Messaggio ricevuto\n");
nerit 0:1e09cd7d66b4 547 #endif
nerit 0:1e09cd7d66b4 548 #endif
nerit 0:1e09cd7d66b4 549 }
nerit 0:1e09cd7d66b4 550 if (rxMsg.id==RX_Broadcast){
nerit 0:1e09cd7d66b4 551 #if defined(pcSerial)
nerit 7:c9fd242538d9 552 #if defined(canDataReceivedb)
nerit 0:1e09cd7d66b4 553 pc.printf("BroadCast ricevuto\n");
nerit 0:1e09cd7d66b4 554 #endif
nerit 0:1e09cd7d66b4 555 #endif
nerit 0:1e09cd7d66b4 556 enableSimula= rxMsg.data[0];
nerit 0:1e09cd7d66b4 557 speedSimula = rxMsg.data[1];
nerit 0:1e09cd7d66b4 558 avviaSimula = rxMsg.data[2];
nerit 0:1e09cd7d66b4 559 selezionato = rxMsg.data[3];
nerit 0:1e09cd7d66b4 560 comandiDaCan = rxMsg.data[4];
nerit 0:1e09cd7d66b4 561 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 562 #if defined(canDataReceived)
nerit 7:c9fd242538d9 563 pc.printf("Speed simula %d \n",speedSimula);
nerit 0:1e09cd7d66b4 564 #endif
nerit 0:1e09cd7d66b4 565 #endif
nerit 0:1e09cd7d66b4 566 switch (comandiDaCan){
nerit 0:1e09cd7d66b4 567 case 1:
nerit 0:1e09cd7d66b4 568 case 3:
nerit 0:1e09cd7d66b4 569 azzeraDaCan=1;
nerit 0:1e09cd7d66b4 570 resetComandi=0x01;
nerit 0:1e09cd7d66b4 571 comandiDaCan=0;
nerit 0:1e09cd7d66b4 572 break;
nerit 0:1e09cd7d66b4 573 case 2:
nerit 0:1e09cd7d66b4 574 loadDaCan=1;
nerit 0:1e09cd7d66b4 575 resetComandi=0x02;
nerit 0:1e09cd7d66b4 576 comandiDaCan=0;
nerit 0:1e09cd7d66b4 577 break;
nerit 0:1e09cd7d66b4 578 default:
nerit 0:1e09cd7d66b4 579 comandiDaCan=0;
nerit 0:1e09cd7d66b4 580 resetComandi=0xFF;
nerit 0:1e09cd7d66b4 581 break;
nerit 0:1e09cd7d66b4 582 }
nerit 0:1e09cd7d66b4 583 #if defined(pcSerial)
nerit 7:c9fd242538d9 584 #if defined(canDataReceivedR)
nerit 0:1e09cd7d66b4 585 pc.printf("Comandi: %x\n",resetComandi);
nerit 0:1e09cd7d66b4 586 #endif
nerit 0:1e09cd7d66b4 587 #endif
nerit 0:1e09cd7d66b4 588 if (speedSimula>45){
nerit 0:1e09cd7d66b4 589 speedSimula=45;
nerit 0:1e09cd7d66b4 590 }
nerit 0:1e09cd7d66b4 591 // modulo 1
nerit 0:1e09cd7d66b4 592 if (RX_ID==0x100){
nerit 0:1e09cd7d66b4 593 if ((selezionato&0x01)==0x01){
nerit 0:1e09cd7d66b4 594 simOk=1;
nerit 0:1e09cd7d66b4 595 }else{
nerit 0:1e09cd7d66b4 596 simOk=0;
nerit 0:1e09cd7d66b4 597 }
nerit 0:1e09cd7d66b4 598 }
nerit 0:1e09cd7d66b4 599 // modulo 2
nerit 0:1e09cd7d66b4 600 if (RX_ID==0x102){
nerit 0:1e09cd7d66b4 601 if ((selezionato&0x02)==0x02){
nerit 0:1e09cd7d66b4 602 simOk=1;
nerit 0:1e09cd7d66b4 603 }else{
nerit 0:1e09cd7d66b4 604 simOk=0;
nerit 0:1e09cd7d66b4 605 }
nerit 0:1e09cd7d66b4 606 }
nerit 0:1e09cd7d66b4 607 // modulo 3
nerit 0:1e09cd7d66b4 608 if (RX_ID==0x104){
nerit 0:1e09cd7d66b4 609 if ((selezionato&0x04)==0x04){
nerit 0:1e09cd7d66b4 610 simOk=1;
nerit 0:1e09cd7d66b4 611 }else{
nerit 0:1e09cd7d66b4 612 simOk=0;
nerit 0:1e09cd7d66b4 613 }
nerit 0:1e09cd7d66b4 614 }
nerit 0:1e09cd7d66b4 615 // modulo 4
nerit 0:1e09cd7d66b4 616 if (RX_ID==0x106){
nerit 0:1e09cd7d66b4 617 if ((selezionato&0x08)==0x08){
nerit 0:1e09cd7d66b4 618 simOk=1;
nerit 0:1e09cd7d66b4 619 }else{
nerit 0:1e09cd7d66b4 620 simOk=0;
nerit 0:1e09cd7d66b4 621 }
nerit 0:1e09cd7d66b4 622 }
nerit 0:1e09cd7d66b4 623 // modulo 5
nerit 0:1e09cd7d66b4 624 if (RX_ID==0x108){
nerit 0:1e09cd7d66b4 625 if ((selezionato&0x10)==0x10){
nerit 0:1e09cd7d66b4 626 simOk=1;
nerit 0:1e09cd7d66b4 627 }else{
nerit 0:1e09cd7d66b4 628 simOk=0;
nerit 0:1e09cd7d66b4 629 }
nerit 0:1e09cd7d66b4 630 }
nerit 0:1e09cd7d66b4 631
nerit 0:1e09cd7d66b4 632 }
nerit 0:1e09cd7d66b4 633 if (rxMsg.id==RX_Settings){
nerit 0:1e09cd7d66b4 634 if (tractorSpeed_MtS_timed==0.0f){
nerit 0:1e09cd7d66b4 635 pickNumber = rxMsg.data[0]; // numero di becchi installati sulla ruota di semina
nerit 0:1e09cd7d66b4 636 cellsNumber = rxMsg.data[1]; // numero di celle del tamburo
nerit 0:1e09cd7d66b4 637 deepOfSeed=(rxMsg.data[2]/10000.0f); // deep of seeding
nerit 0:1e09cd7d66b4 638 seedWheelDiameter = ((rxMsg.data[4]*0xFF)+rxMsg.data[3])/10000.0f; // seed wheel diameter setting
nerit 0:1e09cd7d66b4 639 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 640 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 641 aggiornaParametri();
nerit 0:1e09cd7d66b4 642 }
nerit 0:1e09cd7d66b4 643 }
nerit 0:1e09cd7d66b4 644 if (rxMsg.id==RX_AngoloPh){
nerit 0:1e09cd7d66b4 645 if (tractorSpeed_MtS_timed==0.0f){
nerit 0:1e09cd7d66b4 646 #if defined(M1)
nerit 0:1e09cd7d66b4 647 angoloPh = (double) rxMsg.data[0] ;
nerit 0:1e09cd7d66b4 648 aggiornaParametri();
nerit 0:1e09cd7d66b4 649 #endif
nerit 0:1e09cd7d66b4 650 #if defined(M2)
nerit 0:1e09cd7d66b4 651 angoloPh = (double) rxMsg.data[1] ;
nerit 0:1e09cd7d66b4 652 aggiornaParametri();
nerit 0:1e09cd7d66b4 653 #endif
nerit 0:1e09cd7d66b4 654 #if defined(M3)
nerit 0:1e09cd7d66b4 655 angoloPh = (double) rxMsg.data[2] ;
nerit 0:1e09cd7d66b4 656 aggiornaParametri();
nerit 0:1e09cd7d66b4 657 #endif
nerit 0:1e09cd7d66b4 658 #if defined(M4)
nerit 0:1e09cd7d66b4 659 angoloPh = (double) rxMsg.data[3] ;
nerit 0:1e09cd7d66b4 660 aggiornaParametri();
nerit 0:1e09cd7d66b4 661 #endif
nerit 0:1e09cd7d66b4 662 #if defined(M5)
nerit 0:1e09cd7d66b4 663 angoloPh = (double) rxMsg.data[4] ;
nerit 0:1e09cd7d66b4 664 aggiornaParametri();
nerit 0:1e09cd7d66b4 665 #endif
nerit 0:1e09cd7d66b4 666 #if defined(M6)
nerit 0:1e09cd7d66b4 667 angoloPh = (double) rxMsg.data[5] ;
nerit 0:1e09cd7d66b4 668 aggiornaParametri();
nerit 0:1e09cd7d66b4 669 #endif
nerit 0:1e09cd7d66b4 670 }
nerit 0:1e09cd7d66b4 671 }
nerit 0:1e09cd7d66b4 672 if (rxMsg.id==RX_AngoloAv){
nerit 0:1e09cd7d66b4 673 if (tractorSpeed_MtS_timed==0.0f){
nerit 0:1e09cd7d66b4 674 #if defined(M1)
nerit 0:1e09cd7d66b4 675 angoloAv = (double) rxMsg.data[0] ;
nerit 0:1e09cd7d66b4 676 aggiornaParametri();
nerit 0:1e09cd7d66b4 677 #endif
nerit 0:1e09cd7d66b4 678 #if defined(M2)
nerit 0:1e09cd7d66b4 679 angoloAv = (double) rxMsg.data[1] ;
nerit 0:1e09cd7d66b4 680 aggiornaParametri();
nerit 0:1e09cd7d66b4 681 #endif
nerit 0:1e09cd7d66b4 682 #if defined(M3)
nerit 0:1e09cd7d66b4 683 angoloAv = (double) rxMsg.data[2] ;
nerit 0:1e09cd7d66b4 684 aggiornaParametri();
nerit 0:1e09cd7d66b4 685 #endif
nerit 0:1e09cd7d66b4 686 #if defined(M4)
nerit 0:1e09cd7d66b4 687 angoloAv = (double) rxMsg.data[3] ;
nerit 0:1e09cd7d66b4 688 aggiornaParametri();
nerit 0:1e09cd7d66b4 689 #endif
nerit 0:1e09cd7d66b4 690 #if defined(M5)
nerit 0:1e09cd7d66b4 691 angoloAv = (double) rxMsg.data[4] ;
nerit 0:1e09cd7d66b4 692 aggiornaParametri();
nerit 0:1e09cd7d66b4 693 #endif
nerit 0:1e09cd7d66b4 694 #if defined(M6)
nerit 0:1e09cd7d66b4 695 angoloAv = (double) rxMsg.data[5] ;
nerit 0:1e09cd7d66b4 696 aggiornaParametri();
nerit 0:1e09cd7d66b4 697 #endif
nerit 0:1e09cd7d66b4 698 }
nerit 0:1e09cd7d66b4 699 }
nerit 0:1e09cd7d66b4 700 if (rxMsg.id==RX_Quinconce){
nerit 0:1e09cd7d66b4 701 if (tractorSpeed_MtS_timed==0.0f){
nerit 4:d32258ec411f 702 quinconceActive = (uint8_t) rxMsg.data[0];
nerit 5:3b95bbfe2dc9 703 quincPIDminus = (uint8_t) rxMsg.data[1];
nerit 5:3b95bbfe2dc9 704 quincPIDplus = (uint8_t) rxMsg.data[2];
nerit 5:3b95bbfe2dc9 705 quincLIMminus = (uint8_t) rxMsg.data[3];
nerit 5:3b95bbfe2dc9 706 quincLIMplus = (uint8_t) rxMsg.data[4];
nerit 5:3b95bbfe2dc9 707 quincSector = (uint8_t) rxMsg.data[5];
nerit 0:1e09cd7d66b4 708 aggiornaParametri();
nerit 0:1e09cd7d66b4 709 }
nerit 0:1e09cd7d66b4 710 }
nerit 0:1e09cd7d66b4 711 if (rxMsg.id==RX_QuincSinc){
nerit 7:c9fd242538d9 712 masterSinc = (uint32_t) rxMsg.data[3] * 0x00FF0000;
nerit 7:c9fd242538d9 713 masterSinc = masterSinc + ((uint32_t) rxMsg.data[2] * 0x0000FF00);
nerit 7:c9fd242538d9 714 masterSinc = masterSinc + ((uint32_t) rxMsg.data[1] * 0x000000FF);
nerit 7:c9fd242538d9 715 masterSinc = masterSinc + ((uint32_t) rxMsg.data[0]);
nerit 5:3b95bbfe2dc9 716 speedFromMaster = (double)rxMsg.data[4]/100.0f;
nerit 5:3b95bbfe2dc9 717 mast2_Sinc = ((uint32_t) rxMsg.data[5] * 0x0000FF00);
nerit 5:3b95bbfe2dc9 718 mast2_Sinc = mast2_Sinc + ((uint32_t) rxMsg.data[6] * 0x000000FF);
nerit 5:3b95bbfe2dc9 719 mast2_Sinc = mast2_Sinc + ((uint32_t) rxMsg.data[7]);
nerit 5:3b95bbfe2dc9 720 canDataCheck=1;
nerit 0:1e09cd7d66b4 721 }
nerit 6:3fca0ca1949e 722 if (rxMsg.id==RX_Configure){
nerit 6:3fca0ca1949e 723 uint8_t flags = rxMsg.data[0];
nerit 6:3fca0ca1949e 724 uint16_t steps = (uint32_t) rxMsg.data[1]*0xFF00;
nerit 6:3fca0ca1949e 725 steps = steps + ((uint32_t)rxMsg.data[2]);
nerit 7:c9fd242538d9 726 stepSetting();
nerit 6:3fca0ca1949e 727 cellsCountSet = rxMsg.data[3];
nerit 6:3fca0ca1949e 728 if ((flags&0x01)==0x01){
nerit 7:c9fd242538d9 729 if (encoder==false){
nerit 7:c9fd242538d9 730 encoder=true;
nerit 7:c9fd242538d9 731 DcEncoder.rise(NULL);
nerit 7:c9fd242538d9 732 dcSetting();
nerit 7:c9fd242538d9 733 }
nerit 6:3fca0ca1949e 734 }else{
nerit 7:c9fd242538d9 735 if (encoder==true){
nerit 7:c9fd242538d9 736 encoder=false;
nerit 7:c9fd242538d9 737 DcEncoder.rise(NULL);
nerit 7:c9fd242538d9 738 dcSetting();
nerit 7:c9fd242538d9 739 }
nerit 6:3fca0ca1949e 740 }
nerit 6:3fca0ca1949e 741 if ((flags&0x02)==0x02){
nerit 6:3fca0ca1949e 742 tankLevelEnable=true;
nerit 6:3fca0ca1949e 743 }else{
nerit 6:3fca0ca1949e 744 tankLevelEnable=false;
nerit 6:3fca0ca1949e 745 }
nerit 6:3fca0ca1949e 746 if ((flags&0x04)==0x04){
nerit 6:3fca0ca1949e 747 seedSensorEnable=true;
nerit 6:3fca0ca1949e 748 }else{
nerit 6:3fca0ca1949e 749 seedSensorEnable=false;
nerit 6:3fca0ca1949e 750 }
nerit 6:3fca0ca1949e 751 if ((flags&0x08)==0x08){
nerit 6:3fca0ca1949e 752 stendiNylonEnable=true;
nerit 6:3fca0ca1949e 753 }else{
nerit 6:3fca0ca1949e 754 stendiNylonEnable=false;
nerit 6:3fca0ca1949e 755 }
nerit 6:3fca0ca1949e 756 if ((flags&0x10)==0x10){
nerit 6:3fca0ca1949e 757 canDataCheckEnable=true;
nerit 6:3fca0ca1949e 758 }else{
nerit 6:3fca0ca1949e 759 canDataCheckEnable=false;
nerit 6:3fca0ca1949e 760 }
nerit 6:3fca0ca1949e 761 if ((flags&0x20)==0x20){
nerit 6:3fca0ca1949e 762 tamburoStandard=1;
nerit 6:3fca0ca1949e 763 }else{
nerit 6:3fca0ca1949e 764 tamburoStandard=0;
nerit 6:3fca0ca1949e 765 }
nerit 6:3fca0ca1949e 766 if ((flags&0x40)==0x40){
nerit 6:3fca0ca1949e 767 currentCheckEnable=true;
nerit 6:3fca0ca1949e 768 }else{
nerit 6:3fca0ca1949e 769 currentCheckEnable=false;
nerit 6:3fca0ca1949e 770 }
nerit 6:3fca0ca1949e 771 }
nerit 0:1e09cd7d66b4 772 }
nerit 0:1e09cd7d66b4 773 #endif
nerit 0:1e09cd7d66b4 774 #if defined(overWriteCanSimulation)
nerit 0:1e09cd7d66b4 775 enableSimula=1;
nerit 0:1e09cd7d66b4 776 speedSimula=25;
nerit 0:1e09cd7d66b4 777 avviaSimula=1;
nerit 0:1e09cd7d66b4 778 simOk=1;
nerit 0:1e09cd7d66b4 779 #endif
nerit 0:1e09cd7d66b4 780
nerit 0:1e09cd7d66b4 781 }
nerit 0:1e09cd7d66b4 782
nerit 0:1e09cd7d66b4 783 //*******************************************************
nerit 0:1e09cd7d66b4 784 void DC_CheckCurrent(){
nerit 0:1e09cd7d66b4 785
nerit 0:1e09cd7d66b4 786 // TODO: tabella di riferimento assorbimenti alle varie velocità al fine di gestire
nerit 0:1e09cd7d66b4 787 // gli allarmi e le correzioni di velocità
nerit 0:1e09cd7d66b4 788
nerit 0:1e09cd7d66b4 789 //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 790 //int SD_analogIndex[10]={0,0,0,0,0,0,0,0,0,0};
nerit 0:1e09cd7d66b4 791 // Analog reading
nerit 0:1e09cd7d66b4 792 //number = floor(number * 100) / 100;
nerit 0:1e09cd7d66b4 793 //if (pwmCheck==1){
nerit 0:1e09cd7d66b4 794 timeout.detach();
nerit 0:1e09cd7d66b4 795 for (int ii=1;ii<20;ii++){
nerit 0:1e09cd7d66b4 796 SD_analogMatrix[ii]=SD_analogMatrix[ii+1];
nerit 0:1e09cd7d66b4 797 }
nerit 0:1e09cd7d66b4 798 SD_CurrentAnalog = floor(SDcurrent.read()*100)/100; // valore in ingresso compreso tra 0.00 e 1.00
nerit 0:1e09cd7d66b4 799 SD_analogMatrix[20]=SD_CurrentAnalog;
nerit 0:1e09cd7d66b4 800 if (SDmotorPWM==0.0f){
nerit 0:1e09cd7d66b4 801 SD_CurrentStart=SD_CurrentAnalog;
nerit 0:1e09cd7d66b4 802 }
nerit 0:1e09cd7d66b4 803 float sommaTutto=0.0f;
nerit 0:1e09cd7d66b4 804 for (int ii=1;ii<21;ii++){
nerit 0:1e09cd7d66b4 805 sommaTutto=sommaTutto+SD_analogMatrix[ii];
nerit 0:1e09cd7d66b4 806 }
nerit 0:1e09cd7d66b4 807 float SD_CurrentAnalogica=sommaTutto/20.0f;
nerit 0:1e09cd7d66b4 808 SD_CurrentScaled = floor(( (SD_CurrentAnalogica - SD_CurrentStart)*3.3f) / (SD_CurrentFactor/1000.0f)*10)/10;
nerit 0:1e09cd7d66b4 809 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 810 #if defined(correnteAssorbita)
nerit 0:1e09cd7d66b4 811 pc.printf("CorrenteStart: %f ",SD_CurrentStart);
nerit 0:1e09cd7d66b4 812 pc.printf(" CorrenteScaled: %f ",SD_CurrentScaled);
nerit 0:1e09cd7d66b4 813 pc.printf(" CorrenteMedia: %f \n",SD_CurrentAnalogica);
nerit 0:1e09cd7d66b4 814 #endif
nerit 0:1e09cd7d66b4 815 #endif
nerit 0:1e09cd7d66b4 816 reduceCurrent=false;
nerit 0:1e09cd7d66b4 817 incrementCurrent=false;
nerit 0:1e09cd7d66b4 818 /*
nerit 0:1e09cd7d66b4 819 if (SD_CurrentScaled < 3.0f){
nerit 0:1e09cd7d66b4 820 #if defined(canbusActive)
nerit 0:1e09cd7d66b4 821 all_lowBattery=1;
nerit 0:1e09cd7d66b4 822 #endif
nerit 0:1e09cd7d66b4 823 incrementCurrent=true;
nerit 0:1e09cd7d66b4 824 }
nerit 0:1e09cd7d66b4 825 */
nerit 4:d32258ec411f 826 if (SD_CurrentScaled > 10.0f){
nerit 4:d32258ec411f 827 timeCurr.start();
nerit 4:d32258ec411f 828 if (timeCurr.read() > 5.0f){
nerit 4:d32258ec411f 829 #if defined(canbusActive)
nerit 4:d32258ec411f 830 all_overCurrDC=1;
nerit 4:d32258ec411f 831 #endif
nerit 4:d32258ec411f 832 reduceCurrent=true;
nerit 4:d32258ec411f 833 timeCurr.reset();
nerit 4:d32258ec411f 834 }
nerit 4:d32258ec411f 835 }else{
nerit 4:d32258ec411f 836 timeCurr.stop();
nerit 0:1e09cd7d66b4 837 }
nerit 0:1e09cd7d66b4 838 //}
nerit 0:1e09cd7d66b4 839 }
nerit 0:1e09cd7d66b4 840 //*******************************************************
nerit 0:1e09cd7d66b4 841 void DC_prepare(){
nerit 0:1e09cd7d66b4 842 // direction or brake preparation
nerit 7:c9fd242538d9 843 if (DC_brake==1){
nerit 7:c9fd242538d9 844 SDmotorInA=1;
nerit 7:c9fd242538d9 845 SDmotorInB=1;
nerit 7:c9fd242538d9 846 }else{
nerit 7:c9fd242538d9 847 if (DC_forward==0){
nerit 7:c9fd242538d9 848 SDmotorInA=1;
nerit 7:c9fd242538d9 849 SDmotorInB=0;
nerit 7:c9fd242538d9 850 }else{
nerit 7:c9fd242538d9 851 SDmotorInA=0;
nerit 7:c9fd242538d9 852 SDmotorInB=1;
nerit 7:c9fd242538d9 853 }
nerit 7:c9fd242538d9 854 }
nerit 0:1e09cd7d66b4 855 // fault reading
nerit 0:1e09cd7d66b4 856 if (SDmotorInA==1){SD_faultA=1;}else{SD_faultA=0;}
nerit 0:1e09cd7d66b4 857 if (SDmotorInB==1){SD_faultB=1;}else{SD_faultB=0;}
nerit 0:1e09cd7d66b4 858 }
nerit 0:1e09cd7d66b4 859 //*******************************************************
nerit 0:1e09cd7d66b4 860 void startDelay(){
nerit 0:1e09cd7d66b4 861 int ritardo =0;
nerit 0:1e09cd7d66b4 862 ritardo = (int)((float)(dcActualDuty*800.0f));
nerit 0:1e09cd7d66b4 863 timeout.attach_us(&DC_CheckCurrent,ritardo);
nerit 0:1e09cd7d66b4 864 }
nerit 0:1e09cd7d66b4 865 //*******************************************************
nerit 4:d32258ec411f 866 void quincTrigon(){
nerit 4:d32258ec411f 867 quincClock=true;
nerit 4:d32258ec411f 868 }
nerit 4:d32258ec411f 869 void quincTrigof(){
nerit 4:d32258ec411f 870 quincClock=false;
nerit 0:1e09cd7d66b4 871 }
nerit 0:1e09cd7d66b4 872 //*******************************************************
nerit 2:d9c7430ae953 873 void quinCalc(){
nerit 0:1e09cd7d66b4 874 // riceve l'impulso di sincro dal master e fa partire il timer di verifica dell'errore
nerit 2:d9c7430ae953 875 #if !defined(mezzo)
nerit 0:1e09cd7d66b4 876 if ((quincClock==true)&&(oldQuincIn==0)){
nerit 0:1e09cd7d66b4 877 oldQuincIn=1;
nerit 0:1e09cd7d66b4 878 if (quincStart==0){
nerit 5:3b95bbfe2dc9 879 oldQuincTimeSD = (double) quincTimeSD.read_ms();
nerit 0:1e09cd7d66b4 880 quincTime.reset();
nerit 8:0e643ea7834f 881 quincTimeSD.reset();
nerit 0:1e09cd7d66b4 882 quincStart=1;
nerit 0:1e09cd7d66b4 883 }
nerit 0:1e09cd7d66b4 884 }
nerit 2:d9c7430ae953 885 if(quincClock==false){
nerit 0:1e09cd7d66b4 886 oldQuincIn=0;
nerit 0:1e09cd7d66b4 887 }
nerit 2:d9c7430ae953 888 #else
nerit 2:d9c7430ae953 889 if ((((quinconceActive==0)&&(quincClock==true))||((quinconceActive==1)&&(quincClock==false)))&&(oldQuincIn==0)){
nerit 0:1e09cd7d66b4 890 oldQuincIn=1;
nerit 0:1e09cd7d66b4 891 if (quincStart==0){
nerit 5:3b95bbfe2dc9 892 oldQuincTimeSD = (double) quincTimeSD.read_ms();
nerit 0:1e09cd7d66b4 893 quincTime.reset();
nerit 0:1e09cd7d66b4 894 quincStart=1;
nerit 0:1e09cd7d66b4 895 }
nerit 0:1e09cd7d66b4 896 }
nerit 4:d32258ec411f 897 if (quinconceActive==0){
nerit 4:d32258ec411f 898 if (quincClock==false){
nerit 4:d32258ec411f 899 oldQuincIn=0;
nerit 4:d32258ec411f 900 }
nerit 4:d32258ec411f 901 }else{
nerit 4:d32258ec411f 902 if (quincClock==true){
nerit 4:d32258ec411f 903 oldQuincIn=0;
nerit 4:d32258ec411f 904 }
nerit 0:1e09cd7d66b4 905 }
nerit 2:d9c7430ae953 906 #endif
nerit 5:3b95bbfe2dc9 907 //****************************************************************************************
nerit 7:c9fd242538d9 908 if (quincCnt>=4){
nerit 5:3b95bbfe2dc9 909 if (countPicks==0){
nerit 5:3b95bbfe2dc9 910 if ((sincroQui==1)&&(quincStart==0)){
nerit 5:3b95bbfe2dc9 911 // decelera
nerit 5:3b95bbfe2dc9 912 countPicks=1;
nerit 4:d32258ec411f 913 }
nerit 5:3b95bbfe2dc9 914 if ((sincroQui==0)&&(quincStart==1)){
nerit 5:3b95bbfe2dc9 915 // accelera
nerit 5:3b95bbfe2dc9 916 countPicks=2;
nerit 4:d32258ec411f 917 }
nerit 4:d32258ec411f 918 }
nerit 5:3b95bbfe2dc9 919 if ((sincroQui==1)&&(quincStart==1)){
nerit 5:3b95bbfe2dc9 920 if (countPicks==1){ //decelera
nerit 5:3b95bbfe2dc9 921 scostamento = oldQuincTimeSD;
nerit 5:3b95bbfe2dc9 922 if (scostamento < (tempoBecchiPerQuinc*0.75f)){
nerit 5:3b95bbfe2dc9 923 double scostPerc = (scostamento/tempoBecchiPerQuinc);
nerit 7:c9fd242538d9 924 percento -= ((double)quincPIDminus/100.0f)*(scostPerc);
nerit 5:3b95bbfe2dc9 925 #if defined(pcSerial)
nerit 5:3b95bbfe2dc9 926 #if defined(laq)
nerit 5:3b95bbfe2dc9 927 pc.printf("RALL scos2: %f tbpq: %f percento: %f \n",scostamento,tempoBecchiPerQuinc,percento);
nerit 5:3b95bbfe2dc9 928 #endif
nerit 5:3b95bbfe2dc9 929 #endif
nerit 5:3b95bbfe2dc9 930 }
nerit 7:c9fd242538d9 931 //if (scostamento <15.0f){percento=0.0f;}
nerit 5:3b95bbfe2dc9 932 }
nerit 5:3b95bbfe2dc9 933 if (countPicks==2){ //accelera
nerit 5:3b95bbfe2dc9 934 scostamento = (double)quincTime.read_ms();
nerit 5:3b95bbfe2dc9 935 if (scostamento < (tempoBecchiPerQuinc*0.75f)){
nerit 5:3b95bbfe2dc9 936 double scostPerc = (scostamento/tempoBecchiPerQuinc);
nerit 7:c9fd242538d9 937 percento += ((double)quincPIDplus/100.0f)*(scostPerc);
nerit 5:3b95bbfe2dc9 938 #if defined(pcSerial)
nerit 5:3b95bbfe2dc9 939 #if defined(laq)
nerit 5:3b95bbfe2dc9 940 pc.printf(
nerit 5:3b95bbfe2dc9 941 "ACCE scos1: %f tbpq: %f percento: %f \n",scostamento,tempoBecchiPerQuinc,percento);
nerit 5:3b95bbfe2dc9 942 #endif
nerit 5:3b95bbfe2dc9 943 #endif
nerit 5:3b95bbfe2dc9 944 }
nerit 7:c9fd242538d9 945 //if (scostamento <15.0f){percento=0.0f;}
nerit 5:3b95bbfe2dc9 946 }
nerit 5:3b95bbfe2dc9 947 sincroQui=0;
nerit 5:3b95bbfe2dc9 948 quincStart=0;
nerit 5:3b95bbfe2dc9 949 countPicks=0;
nerit 7:c9fd242538d9 950 #if !defined(speedMaster)
nerit 8:0e643ea7834f 951 if (quincCnt>=3){
nerit 7:c9fd242538d9 952 if (speedFromMaster>0.0f){
nerit 8:0e643ea7834f 953 if (enableSimula==0){
nerit 8:0e643ea7834f 954 tractorSpeed_MtS_timed = speedFromMaster + percento;
nerit 8:0e643ea7834f 955 }
nerit 7:c9fd242538d9 956 }
nerit 7:c9fd242538d9 957 }
nerit 7:c9fd242538d9 958 #endif
nerit 5:3b95bbfe2dc9 959 }
nerit 5:3b95bbfe2dc9 960
nerit 5:3b95bbfe2dc9 961 //*******************************************************************
nerit 5:3b95bbfe2dc9 962 if (canDataCheckEnable==true){
nerit 5:3b95bbfe2dc9 963 if (canDataCheck==1){ // sincro da comunicazione can del valore di posizione del tamburo master
nerit 5:3b95bbfe2dc9 964 canDataCheck=0;
nerit 7:c9fd242538d9 965 double parametro = SDsectorStep/3.0f;
nerit 5:3b95bbfe2dc9 966 double differenza=0.0f;
nerit 5:3b95bbfe2dc9 967 #if defined(mezzo)
nerit 5:3b95bbfe2dc9 968 if (quinconceActive==1){
nerit 5:3b95bbfe2dc9 969 differenza = (double)masterSinc - (double)prePosSD;
nerit 5:3b95bbfe2dc9 970 }else{
nerit 5:3b95bbfe2dc9 971 differenza = (double)mast2_Sinc - (double)prePosSD;
nerit 5:3b95bbfe2dc9 972 }
nerit 5:3b95bbfe2dc9 973 #else
nerit 5:3b95bbfe2dc9 974 differenza = (double)mast2_Sinc - (double)prePosSD;
nerit 5:3b95bbfe2dc9 975 #endif
nerit 5:3b95bbfe2dc9 976 if ((differenza > 0.0f)&&(differenza < parametro)){
nerit 5:3b95bbfe2dc9 977 double diffPerc = differenza / parametro;
nerit 7:c9fd242538d9 978 percento += ((double)quincPIDplus/100.0f)*abs(diffPerc);
nerit 5:3b95bbfe2dc9 979 #if defined(pcSerial)
nerit 5:3b95bbfe2dc9 980 #if defined(quinca)
nerit 5:3b95bbfe2dc9 981 pc.printf("m1 %d m2 %d prePo %d diffe %f perce %f parm %f %\n",masterSinc, mast2_Sinc,prePosSD,differenza,percento, parametro);
nerit 5:3b95bbfe2dc9 982 #endif
nerit 5:3b95bbfe2dc9 983 #endif
nerit 5:3b95bbfe2dc9 984 }
nerit 5:3b95bbfe2dc9 985 if ((differenza < 0.0f)&&(abs(differenza) < parametro)){
nerit 5:3b95bbfe2dc9 986 double diffPerc = (double)differenza / parametro;
nerit 7:c9fd242538d9 987 percento -= ((double)quincPIDminus/100.0f)*abs(diffPerc);
nerit 5:3b95bbfe2dc9 988 #if defined(pcSerial)
nerit 5:3b95bbfe2dc9 989 #if defined(quinca)
nerit 5:3b95bbfe2dc9 990 pc.printf("m1 %d m2 %d prePo %d diffe %f perce %f parm %f %\n",masterSinc, mast2_Sinc,prePosSD,differenza,percento, parametro);
nerit 5:3b95bbfe2dc9 991 #endif
nerit 5:3b95bbfe2dc9 992 #endif
nerit 5:3b95bbfe2dc9 993 }
nerit 7:c9fd242538d9 994
nerit 7:c9fd242538d9 995 #if !defined(speedMaster)
nerit 8:0e643ea7834f 996 if (quincCnt>=3){
nerit 7:c9fd242538d9 997 if (speedFromMaster>0.0f){
nerit 8:0e643ea7834f 998 if (enableSimula==0){
nerit 8:0e643ea7834f 999 tractorSpeed_MtS_timed = speedFromMaster + percento;
nerit 8:0e643ea7834f 1000 }
nerit 7:c9fd242538d9 1001 }
nerit 7:c9fd242538d9 1002 }
nerit 7:c9fd242538d9 1003 #endif
nerit 5:3b95bbfe2dc9 1004 }
nerit 5:3b95bbfe2dc9 1005 }
nerit 5:3b95bbfe2dc9 1006
nerit 5:3b95bbfe2dc9 1007 }
nerit 5:3b95bbfe2dc9 1008 if ((percento) > ((double) quincLIMplus/100.0f)){
nerit 5:3b95bbfe2dc9 1009 percento= (double)quincLIMplus/100.0f;
nerit 5:3b95bbfe2dc9 1010 }
nerit 5:3b95bbfe2dc9 1011 if ((percento) < (((double)quincLIMminus*-1.0f)/100.0f)){
nerit 5:3b95bbfe2dc9 1012 percento=((double)quincLIMminus*-1.0f)/100.0f;
nerit 0:1e09cd7d66b4 1013 }
nerit 0:1e09cd7d66b4 1014 }
nerit 7:c9fd242538d9 1015 // ----------------------------------------
nerit 7:c9fd242538d9 1016 #if defined(seedSensor)
nerit 7:c9fd242538d9 1017 void resetDelay(){
nerit 7:c9fd242538d9 1018 delaySeedCheck.reset();
nerit 7:c9fd242538d9 1019 delaySeedCheck.stop();
nerit 7:c9fd242538d9 1020 }
nerit 7:c9fd242538d9 1021 #endif
nerit 0:1e09cd7d66b4 1022 // ------------------------------------------------------------------------------------------------------------------------------------------------------------------
nerit 0:1e09cd7d66b4 1023 // MAIN SECTION
nerit 3:c0f11ca4df02 1024 // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
nerit 0:1e09cd7d66b4 1025
nerit 0:1e09cd7d66b4 1026 int main()
nerit 0:1e09cd7d66b4 1027 {
nerit 5:3b95bbfe2dc9 1028 //wait(1.0f);
nerit 0:1e09cd7d66b4 1029 wd.Configure(2); //watchdog set at xx seconds
nerit 7:c9fd242538d9 1030
nerit 7:c9fd242538d9 1031 stepSetting();
nerit 7:c9fd242538d9 1032
nerit 0:1e09cd7d66b4 1033 for (int a=0; a<5;a++){
nerit 0:1e09cd7d66b4 1034 mediaSpeed[a]=0;
nerit 0:1e09cd7d66b4 1035 }
nerit 0:1e09cd7d66b4 1036
nerit 0:1e09cd7d66b4 1037
nerit 0:1e09cd7d66b4 1038 // DC reset ad set
nerit 0:1e09cd7d66b4 1039 int decima = 100;
nerit 0:1e09cd7d66b4 1040 wait_ms(200);
nerit 0:1e09cd7d66b4 1041 SD_CurrentStart=floor(SDcurrent.read()*decima)/decima;
nerit 0:1e09cd7d66b4 1042 wait_ms(2);
nerit 0:1e09cd7d66b4 1043 SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima;
nerit 0:1e09cd7d66b4 1044 wait_ms(1);
nerit 0:1e09cd7d66b4 1045 SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima;
nerit 0:1e09cd7d66b4 1046 wait_ms(3);
nerit 0:1e09cd7d66b4 1047 SD_CurrentStart+=floor(SDcurrent.read()*decima)/decima;
nerit 0:1e09cd7d66b4 1048 SD_CurrentStart=(floor((SD_CurrentStart/4.0f)*decima)/decima)-0.01f;
nerit 0:1e09cd7d66b4 1049 wait_ms(100);
nerit 0:1e09cd7d66b4 1050 DC_prepare();
nerit 0:1e09cd7d66b4 1051
nerit 0:1e09cd7d66b4 1052 speedTimer.start(); // speed pulse timer
nerit 0:1e09cd7d66b4 1053 intraPickTimer.start();
nerit 0:1e09cd7d66b4 1054 speedTimeOut.start();
nerit 0:1e09cd7d66b4 1055 speedFilter.start();
nerit 0:1e09cd7d66b4 1056 seedFilter.start();
nerit 0:1e09cd7d66b4 1057 TBfilter.start();
nerit 0:1e09cd7d66b4 1058 sincroTimer.start();
nerit 0:1e09cd7d66b4 1059 rotationTimeOut.start();
nerit 0:1e09cd7d66b4 1060 metalTimer.start();
nerit 0:1e09cd7d66b4 1061 quincTime.start();
nerit 1:e88bf5011af6 1062 quincTimeSD.start();
nerit 7:c9fd242538d9 1063 //intraEncoTimer.start();
nerit 0:1e09cd7d66b4 1064
nerit 0:1e09cd7d66b4 1065 //*******************************************************
nerit 0:1e09cd7d66b4 1066 // controls for check DC motor current
nerit 0:1e09cd7d66b4 1067 pwmCheck.rise(&startDelay);
nerit 0:1e09cd7d66b4 1068
nerit 0:1e09cd7d66b4 1069 if (inProva==0){
nerit 0:1e09cd7d66b4 1070 tractorSpeedRead.rise(&tractorReadSpeed);
nerit 0:1e09cd7d66b4 1071 #if !defined(speedMaster)
nerit 4:d32258ec411f 1072 quinconceIn.rise(&quincTrigon);
nerit 4:d32258ec411f 1073 quinconceIn.fall(&quincTrigof);
nerit 0:1e09cd7d66b4 1074 #endif
nerit 5:3b95bbfe2dc9 1075 #if defined(speedMaster)
nerit 5:3b95bbfe2dc9 1076 tftUpdate.attach(&videoUpdate,0.50f);
nerit 5:3b95bbfe2dc9 1077 #endif
nerit 0:1e09cd7d66b4 1078 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 7:c9fd242538d9 1079 dcSetting();
nerit 7:c9fd242538d9 1080 #if defined(seedSensor)
nerit 8:0e643ea7834f 1081 seedCheck.fall(&seedSensorTask);
nerit 7:c9fd242538d9 1082 #endif
nerit 0:1e09cd7d66b4 1083 }else{
nerit 0:1e09cd7d66b4 1084 tftUpdate.attach(&videoUpdate,0.125f);
nerit 0:1e09cd7d66b4 1085 }
nerit 0:1e09cd7d66b4 1086
nerit 0:1e09cd7d66b4 1087 aggiornaParametri();
nerit 0:1e09cd7d66b4 1088
nerit 0:1e09cd7d66b4 1089 SDmotorPWM.period_us(periodoSD); // frequency 1KHz pilotaggio motore DC
nerit 7:c9fd242538d9 1090 SDmotorPWM.write(1.0f); // duty cycle = stop
nerit 7:c9fd242538d9 1091 TBmotorDirecti=1; // tb motor direction set
nerit 0:1e09cd7d66b4 1092
nerit 0:1e09cd7d66b4 1093 #if defined(provaStepper)
nerit 7:c9fd242538d9 1094 TBmotorRst=0;
nerit 7:c9fd242538d9 1095 TBticker.attach_us(&step_TBPulseOut,1000.0f); // clock time are seconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 1096 #endif // end prova stepper
nerit 0:1e09cd7d66b4 1097
nerit 0:1e09cd7d66b4 1098 #if defined(canbusActive)
nerit 0:1e09cd7d66b4 1099 can1.attach(&leggiCAN, CAN::RxIrq);
nerit 0:1e09cd7d66b4 1100 #endif
nerit 0:1e09cd7d66b4 1101
nerit 0:1e09cd7d66b4 1102 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1103 // MAIN LOOP
nerit 0:1e09cd7d66b4 1104 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1105 while (true){
nerit 0:1e09cd7d66b4 1106 // ripetitore segnale di velocità
nerit 0:1e09cd7d66b4 1107 if (tractorSpeedRead==0){speedClock=0;}
nerit 0:1e09cd7d66b4 1108
nerit 0:1e09cd7d66b4 1109 // inversione segnali ingressi
nerit 4:d32258ec411f 1110 #if !defined(simulaBanco)
nerit 4:d32258ec411f 1111 seedWheelZeroPinInput = !seedWheelZeroPinInputRev;
nerit 4:d32258ec411f 1112 #else
nerit 4:d32258ec411f 1113 if ((prePosSD-500) >= SDsectorStep){
nerit 4:d32258ec411f 1114 seedWheelZeroPinInput=1;
nerit 4:d32258ec411f 1115 }
nerit 4:d32258ec411f 1116 if ((prePosSD > 500)&&(prePosSD<580)){
nerit 4:d32258ec411f 1117 seedWheelZeroPinInput=0;
nerit 4:d32258ec411f 1118 }
nerit 4:d32258ec411f 1119 #endif
nerit 0:1e09cd7d66b4 1120 TBzeroPinInput = !TBzeroPinInputRev;
nerit 0:1e09cd7d66b4 1121
nerit 0:1e09cd7d66b4 1122 // se quinconce attivo ed unita' master invia segnale di sincro
nerit 0:1e09cd7d66b4 1123 #if defined(speedMaster)
nerit 0:1e09cd7d66b4 1124 if (seedWheelZeroPinInput==1){
nerit 7:c9fd242538d9 1125 quinconceOut=0;
nerit 0:1e09cd7d66b4 1126 }
nerit 5:3b95bbfe2dc9 1127 if (((double)(prePosSD-500) >= (SDsectorStep/((double)quincSector)))&&(quinconceOut=1)){
nerit 7:c9fd242538d9 1128 quinconceOut=1;
nerit 7:c9fd242538d9 1129 }
nerit 7:c9fd242538d9 1130 if (quinconceActive==1){
nerit 7:c9fd242538d9 1131 if ((quinconceOut==1)&&(oldQuinconceOut==1)){
nerit 5:3b95bbfe2dc9 1132 posForQuinc=500;
nerit 7:c9fd242538d9 1133 oldQuinconceOut=0;
nerit 7:c9fd242538d9 1134 }
nerit 7:c9fd242538d9 1135 if (((double)posForQuinc-500.0f)> (SDsectorStep-200)){
nerit 7:c9fd242538d9 1136 oldQuinconceOut=1;
nerit 7:c9fd242538d9 1137 }
nerit 7:c9fd242538d9 1138 }
nerit 0:1e09cd7d66b4 1139 #endif
nerit 0:1e09cd7d66b4 1140
nerit 0:1e09cd7d66b4 1141 #if defined(overWriteCanSimulation)
nerit 0:1e09cd7d66b4 1142 leggiCAN();
nerit 0:1e09cd7d66b4 1143 #endif
nerit 0:1e09cd7d66b4 1144
nerit 0:1e09cd7d66b4 1145 // simulazione velocita
nerit 0:1e09cd7d66b4 1146 if (enableSimula==1){
nerit 0:1e09cd7d66b4 1147 double TMT = 0.0f;
nerit 0:1e09cd7d66b4 1148 if (speedSimula > 0){
nerit 0:1e09cd7d66b4 1149 TMT = (double)(speedSimula) * 100.0f /3600.0f;
nerit 0:1e09cd7d66b4 1150 pulseSpeedInterval = pulseDistance / TMT;
nerit 0:1e09cd7d66b4 1151 }else{
nerit 0:1e09cd7d66b4 1152 pulseSpeedInterval = 10000.0f;
nerit 0:1e09cd7d66b4 1153 }
nerit 0:1e09cd7d66b4 1154 if (avviaSimula==1){
nerit 0:1e09cd7d66b4 1155 if(oldSimulaSpeed!=pulseSpeedInterval){
nerit 7:c9fd242538d9 1156 #if defined(pcSerial)
nerit 7:c9fd242538d9 1157 #if defined(canDataReceived)
nerit 7:c9fd242538d9 1158 pc.printf("Pulseinterval %f \n",pulseSpeedInterval);
nerit 7:c9fd242538d9 1159 #endif
nerit 7:c9fd242538d9 1160 #endif
nerit 0:1e09cd7d66b4 1161 spedSimclock.attach_us(&speedSimulationClock,pulseSpeedInterval);
nerit 0:1e09cd7d66b4 1162 oldSimulaSpeed=pulseSpeedInterval;
nerit 0:1e09cd7d66b4 1163 }
nerit 0:1e09cd7d66b4 1164 }else{
nerit 0:1e09cd7d66b4 1165 oldSimulaSpeed=10000.0f;
nerit 0:1e09cd7d66b4 1166 spedSimclock.detach();
nerit 0:1e09cd7d66b4 1167 }
nerit 0:1e09cd7d66b4 1168 }else{
nerit 0:1e09cd7d66b4 1169 spedSimclock.detach();
nerit 0:1e09cd7d66b4 1170 }
nerit 0:1e09cd7d66b4 1171
nerit 0:1e09cd7d66b4 1172 //*******************************************************
nerit 0:1e09cd7d66b4 1173 // determina se sono in bassa velocità per il controllo di TB
nerit 0:1e09cd7d66b4 1174 if (speedOfSeedWheel<=minSeedSpeed){
nerit 0:1e09cd7d66b4 1175 if (lowSpeedRequired==0){
nerit 0:1e09cd7d66b4 1176 ritardaLowSpeed.reset();
nerit 0:1e09cd7d66b4 1177 ritardaLowSpeed.start();
nerit 0:1e09cd7d66b4 1178 }
nerit 0:1e09cd7d66b4 1179 lowSpeedRequired=1;
nerit 0:1e09cd7d66b4 1180 }else{
nerit 0:1e09cd7d66b4 1181 if (lowSpeedRequired==1){
nerit 0:1e09cd7d66b4 1182 lowSpeedRequired=0;
nerit 0:1e09cd7d66b4 1183 ritardaLowSpeed.reset();
nerit 0:1e09cd7d66b4 1184 ritardaLowSpeed.stop();
nerit 0:1e09cd7d66b4 1185 }
nerit 0:1e09cd7d66b4 1186 }
nerit 0:1e09cd7d66b4 1187
nerit 0:1e09cd7d66b4 1188 if (ritardaLowSpeed.read_ms()> 2000){
nerit 0:1e09cd7d66b4 1189 lowSpeed=1;
nerit 0:1e09cd7d66b4 1190 }else{
nerit 0:1e09cd7d66b4 1191 lowSpeed=0;
nerit 0:1e09cd7d66b4 1192 }
nerit 0:1e09cd7d66b4 1193
nerit 0:1e09cd7d66b4 1194
nerit 0:1e09cd7d66b4 1195 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1196 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1197 // LOGICAL CONTROLS
nerit 0:1e09cd7d66b4 1198 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1199 //**************************************************************************************************************
nerit 0:1e09cd7d66b4 1200
nerit 0:1e09cd7d66b4 1201 if (inProva==0){
nerit 7:c9fd242538d9 1202 if ((startCycleSimulation==0)&&(enableSimula==0)){
nerit 7:c9fd242538d9 1203 zeroRequestBuf=1;
nerit 7:c9fd242538d9 1204 runRequestBuf=0;
nerit 7:c9fd242538d9 1205 enableCycle=1;
nerit 7:c9fd242538d9 1206 }else{
nerit 7:c9fd242538d9 1207 zeroRequestBuf=1;
nerit 7:c9fd242538d9 1208 runRequestBuf=0;
nerit 7:c9fd242538d9 1209 enableCycle=1;
nerit 7:c9fd242538d9 1210 }
nerit 7:c9fd242538d9 1211 if ((tractorSpeedRead==0)&&(speedFilter.read_ms()>3)){
nerit 7:c9fd242538d9 1212 oldTractorSpeedRead=0;
nerit 7:c9fd242538d9 1213 }
nerit 0:1e09cd7d66b4 1214 // ----------------------------------------
nerit 0:1e09cd7d66b4 1215 // filtra il segnale dei becchi per misurare il tempo di intervallo tra loro
nerit 0:1e09cd7d66b4 1216 // ----------------------------------------
nerit 4:d32258ec411f 1217 if ((seedWheelZeroPinInput==0)&&(oldSeedWheelZeroPinInput==1)){
nerit 0:1e09cd7d66b4 1218 if(seedFilter.read_ms()>=4){
nerit 0:1e09cd7d66b4 1219 oldSeedWheelZeroPinInput=0;
nerit 0:1e09cd7d66b4 1220 SDzeroDebounced=0;
nerit 0:1e09cd7d66b4 1221 }
nerit 0:1e09cd7d66b4 1222 }
nerit 0:1e09cd7d66b4 1223 if ((seedWheelZeroPinInput==1)&&(oldSeedWheelZeroPinInput==0)){
nerit 5:3b95bbfe2dc9 1224 timeIntraPick = (double)intraPickTimer.read_ms();
nerit 0:1e09cd7d66b4 1225 prePosSD=500; // preposizionamento SD
nerit 0:1e09cd7d66b4 1226 intraPickTimer.reset();
nerit 0:1e09cd7d66b4 1227 rotationTimeOut.reset();
nerit 0:1e09cd7d66b4 1228 seedFilter.reset();
nerit 0:1e09cd7d66b4 1229 sincroTimer.reset();
nerit 0:1e09cd7d66b4 1230 oldSeedWheelZeroPinInput=1;
nerit 8:0e643ea7834f 1231 quincTime.reset();
nerit 1:e88bf5011af6 1232 quincTimeSD.reset();
nerit 0:1e09cd7d66b4 1233 SDzeroDebounced=1;
nerit 4:d32258ec411f 1234 sincroQui=1;
nerit 0:1e09cd7d66b4 1235 SDwheelTimer.reset();
nerit 5:3b95bbfe2dc9 1236 #if defined(speedMaster)
nerit 5:3b95bbfe2dc9 1237 if (quinconceActive==0){
nerit 5:3b95bbfe2dc9 1238 posForQuinc=500;
nerit 5:3b95bbfe2dc9 1239 }
nerit 5:3b95bbfe2dc9 1240 #endif
nerit 0:1e09cd7d66b4 1241 if (quincCnt<10){
nerit 0:1e09cd7d66b4 1242 quincCnt++;
nerit 0:1e09cd7d66b4 1243 }
nerit 0:1e09cd7d66b4 1244 if ((aspettaStart==0)&&(lowSpeed==1)){
nerit 0:1e09cd7d66b4 1245 beccoPronto=1;
nerit 0:1e09cd7d66b4 1246 }
nerit 0:1e09cd7d66b4 1247 SDzeroCyclePulse=1;
nerit 0:1e09cd7d66b4 1248 lockStart=0;
nerit 0:1e09cd7d66b4 1249 double fase1=0.0f;
nerit 0:1e09cd7d66b4 1250 forzaFase=0;
nerit 0:1e09cd7d66b4 1251 double limite=fixedStepGiroSD/pickNumber;
nerit 0:1e09cd7d66b4 1252 if (tamburoStandard==0){
nerit 0:1e09cd7d66b4 1253 fase1=TBdeltaStep;
nerit 0:1e09cd7d66b4 1254 }else{
nerit 0:1e09cd7d66b4 1255 if(speedForCorrection >= speedOfSeedWheel){
nerit 0:1e09cd7d66b4 1256 fase1=TBdeltaStep;
nerit 0:1e09cd7d66b4 1257 }else{
nerit 6:3fca0ca1949e 1258 //fase1=(TBdeltaStep)-(((speedOfSeedWheel-speedForCorrection)/maxWorkSpeed)*(TBfaseStep));
nerit 6:3fca0ca1949e 1259 fase1=(TBdeltaStep)-(((speedOfSeedWheel)/maxWorkSpeed)*(TBfaseStep));
nerit 0:1e09cd7d66b4 1260 }
nerit 0:1e09cd7d66b4 1261 if (fase1 > limite){
nerit 0:1e09cd7d66b4 1262 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 1263 //forzaFase=1;
nerit 0:1e09cd7d66b4 1264 }
nerit 0:1e09cd7d66b4 1265 if ((fase1 > (limite -20.0f))&&(fase1<(limite +5.0f))){
nerit 0:1e09cd7d66b4 1266 fase1 = limite -20.0f; // se la fase è molto vicina al limite interpone uno spazio minimo di lavoro del sincronismo
nerit 0:1e09cd7d66b4 1267 forzaFase=1;
nerit 0:1e09cd7d66b4 1268 }
nerit 0:1e09cd7d66b4 1269 trigRepos=1;
nerit 0:1e09cd7d66b4 1270 }
nerit 0:1e09cd7d66b4 1271 fase = (uint32_t)fase1+500;
nerit 0:1e09cd7d66b4 1272 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 1273 #if defined(inCorre)
nerit 0:1e09cd7d66b4 1274 pc.printf(" limite %f", limite);
nerit 0:1e09cd7d66b4 1275 pc.printf(" delta %f", TBdeltaStep);
nerit 0:1e09cd7d66b4 1276 pc.printf(" faseStep %f", TBfaseStep);
nerit 0:1e09cd7d66b4 1277 pc.printf(" fase %d",fase);
nerit 0:1e09cd7d66b4 1278 pc.printf(" forzaFase %d",forzaFase);
nerit 0:1e09cd7d66b4 1279 pc.printf(" trigRepos %d", trigRepos);
nerit 0:1e09cd7d66b4 1280 pc.printf(" ActualSD: %d",SDactualPosition);
nerit 0:1e09cd7d66b4 1281 pc.printf(" SpeedWheel: %f",speedOfSeedWheel);
nerit 0:1e09cd7d66b4 1282 pc.printf(" SPEED: %f \n",tractorSpeed_MtS_timed);
nerit 0:1e09cd7d66b4 1283 #endif
nerit 0:1e09cd7d66b4 1284 #endif
nerit 0:1e09cd7d66b4 1285 if (timeIntraPick >= (memoIntraPick*2)){
nerit 0:1e09cd7d66b4 1286 if ((aspettaStart==0)&&(zeroRequestBuf==0)){
nerit 0:1e09cd7d66b4 1287 if (firstStart==0){
nerit 0:1e09cd7d66b4 1288 all_pickSignal=1;
nerit 0:1e09cd7d66b4 1289 }
nerit 0:1e09cd7d66b4 1290 }
nerit 0:1e09cd7d66b4 1291 }
nerit 0:1e09cd7d66b4 1292 memoIntraPick = timeIntraPick;
nerit 5:3b95bbfe2dc9 1293 if ((speedFromPick==1)&&(encoder==false)){
nerit 0:1e09cd7d66b4 1294 speedOfSeedWheel=((seedPerimeter / pickNumber)/timeIntraPick)*1000.0f;
nerit 0:1e09cd7d66b4 1295 #if defined(pcSerial)
nerit 4:d32258ec411f 1296 #if defined(Qnca)
nerit 4:d32258ec411f 1297 pc.printf("perim: %f pickN: %f sped: %f\n", seedPerimeter, pickNumber,speedOfSeedWheel);
nerit 0:1e09cd7d66b4 1298 #endif
nerit 0:1e09cd7d66b4 1299 #endif
nerit 0:1e09cd7d66b4 1300 }
nerit 7:c9fd242538d9 1301 if (encoder==false){
nerit 7:c9fd242538d9 1302 pulseRised2=1;
nerit 7:c9fd242538d9 1303 }
nerit 4:d32258ec411f 1304 #if defined(speedMaster)
nerit 4:d32258ec411f 1305 if ((tractorSpeed_MtS_timed==0.0f)&&(zeroCycle==0)&&(zeroCycleEnd==1)){
nerit 4:d32258ec411f 1306 if ((firstStart==0)&&(simOk==0)&&(enableSimula==0)&&(zeroCycleEnd==1)){
nerit 4:d32258ec411f 1307 all_noSpeedSen=1;
nerit 4:d32258ec411f 1308 }
nerit 4:d32258ec411f 1309 }
nerit 5:3b95bbfe2dc9 1310 double oldLastPr = (double)oldLastPulseRead*1.5f;
nerit 0:1e09cd7d66b4 1311 if((double)speedTimeOut.read_us()> (oldLastPr)){
nerit 0:1e09cd7d66b4 1312 if ((firstStart==0)&&(simOk==0)&&(enableSimula==0)&&(zeroCycleEnd==1)){
nerit 0:1e09cd7d66b4 1313 all_speedError =1;
nerit 0:1e09cd7d66b4 1314 }
nerit 0:1e09cd7d66b4 1315 }
nerit 0:1e09cd7d66b4 1316 #endif
nerit 0:1e09cd7d66b4 1317 //*******************************************
nerit 0:1e09cd7d66b4 1318 // esegue calcolo clock per la generazione della posizione teorica
nerit 0:1e09cd7d66b4 1319 // la realtà in base al segnale di presenza del becco
nerit 0:1e09cd7d66b4 1320 realSpeed = speedOfSeedWheel;
nerit 0:1e09cd7d66b4 1321 realGiroSD = seedPerimeter / realSpeed;
nerit 0:1e09cd7d66b4 1322 tempoBecco = (realGiroSD/360.0f)*16000.0f;
nerit 0:1e09cd7d66b4 1323 frequenzaReale = fixedStepGiroSD/realGiroSD;
nerit 0:1e09cd7d66b4 1324 semiPeriodoReale = (1000000.0f/frequenzaReale);
nerit 0:1e09cd7d66b4 1325 tempoTraBecchi_mS = 0.0f;
nerit 0:1e09cd7d66b4 1326 seedWheelRPM = (speedOfSeedWheel)*K_WheelRPM ; // calcola i giri al minuto della ruota di semina 7.37 31,75
nerit 0:1e09cd7d66b4 1327 TBrpm = seedWheelRPM*rapportoRuote; // 5.896 31,75
nerit 0:1e09cd7d66b4 1328 TBfrequency = (TBrpm*K_TBfrequency); // 130Hz a 0,29Mts 1397,00 a 1,25mt/s con 15 becchi e 15 celle
nerit 0:1e09cd7d66b4 1329 TBperiod=1000000.0f/TBfrequency; // 715uS
nerit 0:1e09cd7d66b4 1330 }
nerit 0:1e09cd7d66b4 1331 // ----------------------------------------
nerit 0:1e09cd7d66b4 1332 // check SD fase
nerit 0:1e09cd7d66b4 1333 if ((prePosSD >= fase)||(forzaFase==1)){//&&(prePosSD < (fase +30))){
nerit 0:1e09cd7d66b4 1334 forzaFase=0;
nerit 0:1e09cd7d66b4 1335 if (trigRepos==1){
nerit 0:1e09cd7d66b4 1336 SDactualPosition=0;
nerit 0:1e09cd7d66b4 1337 if ((countCicli<30)&&(trigCicli==0)){countCicli++;trigCicli=1;}
nerit 0:1e09cd7d66b4 1338 if(countCicli>=cicliAspettaStart){aspettaStart=0;}
nerit 0:1e09cd7d66b4 1339 if ((lowSpeed==0)&&(aspettaStart==0)&&(lockStart==0)){syncroCheck=1;beccoPronto=0;}
nerit 0:1e09cd7d66b4 1340 if (trigTB==0){
nerit 0:1e09cd7d66b4 1341 inhibit=1;
nerit 0:1e09cd7d66b4 1342 trigSD=1;
nerit 0:1e09cd7d66b4 1343 }else{
nerit 0:1e09cd7d66b4 1344 inhibit=0;
nerit 0:1e09cd7d66b4 1345 trigTB=0;
nerit 0:1e09cd7d66b4 1346 trigSD=0;
nerit 0:1e09cd7d66b4 1347 }
nerit 0:1e09cd7d66b4 1348 trigRepos=0;
nerit 0:1e09cd7d66b4 1349 }
nerit 0:1e09cd7d66b4 1350 }else{
nerit 0:1e09cd7d66b4 1351 trigCicli=0;
nerit 0:1e09cd7d66b4 1352 }
nerit 0:1e09cd7d66b4 1353 // ----------------------------------------
nerit 0:1e09cd7d66b4 1354 // filtra il segnale del tamburo per lo stop in fase del tamburo stesso
nerit 0:1e09cd7d66b4 1355 if (TBzeroPinInput==0){if (TBfilter.read_ms()>=5){oldTBzeroPinInput=0;}}
nerit 0:1e09cd7d66b4 1356 if ((TBzeroPinInput==1)&&(oldTBzeroPinInput==0)){
nerit 0:1e09cd7d66b4 1357 oldTBzeroPinInput=1;
nerit 0:1e09cd7d66b4 1358 if (loadDaCanInCorso==0){
nerit 0:1e09cd7d66b4 1359 stopCicloTB=1;
nerit 0:1e09cd7d66b4 1360 startCicloTB=0;
nerit 0:1e09cd7d66b4 1361 }
nerit 0:1e09cd7d66b4 1362 TBfilter.reset();
nerit 0:1e09cd7d66b4 1363 TBzeroCyclePulse=1;
nerit 0:1e09cd7d66b4 1364 TBactualPosition=0;
nerit 9:503e2aba047c 1365 if (cntTbError>0){
nerit 9:503e2aba047c 1366 cntCellsCorrect++;
nerit 9:503e2aba047c 1367 }
nerit 9:503e2aba047c 1368 if (cntCellsCorrect>3){
nerit 9:503e2aba047c 1369 cntTbError=0;
nerit 9:503e2aba047c 1370 cntCellsCorrect=0;
nerit 9:503e2aba047c 1371 }
nerit 9:503e2aba047c 1372 // conteggio celle erogate
nerit 0:1e09cd7d66b4 1373 if (cellsCounterLow < 0xFF){
nerit 0:1e09cd7d66b4 1374 cellsCounterLow++;
nerit 0:1e09cd7d66b4 1375 }else{
nerit 0:1e09cd7d66b4 1376 cellsCounterHig++;
nerit 0:1e09cd7d66b4 1377 cellsCounterLow=0;
nerit 0:1e09cd7d66b4 1378 }
nerit 9:503e2aba047c 1379 // ciclo conteggio celle per carico manuale
nerit 0:1e09cd7d66b4 1380 if (loadDaCanInCorso==1){
nerit 0:1e09cd7d66b4 1381 cntCellsForLoad++;
nerit 0:1e09cd7d66b4 1382 if (cntCellsForLoad >= 5){
nerit 0:1e09cd7d66b4 1383 stopCicloTB=1;
nerit 0:1e09cd7d66b4 1384 cntCellsForLoad=0;
nerit 0:1e09cd7d66b4 1385 }
nerit 0:1e09cd7d66b4 1386 }else{
nerit 0:1e09cd7d66b4 1387 cntCellsForLoad=0;
nerit 0:1e09cd7d66b4 1388 }
nerit 9:503e2aba047c 1389 // inibizione controllo di sincro per fuori fase
nerit 0:1e09cd7d66b4 1390 if (trigSD==0){
nerit 0:1e09cd7d66b4 1391 inhibit=1;
nerit 0:1e09cd7d66b4 1392 trigTB=1;
nerit 0:1e09cd7d66b4 1393 }else{
nerit 0:1e09cd7d66b4 1394 inhibit=0;
nerit 0:1e09cd7d66b4 1395 trigTB=0;
nerit 0:1e09cd7d66b4 1396 trigSD=0;
nerit 0:1e09cd7d66b4 1397 }
nerit 9:503e2aba047c 1398 // conta le celle indietro per sbloccare il tamburo
nerit 7:c9fd242538d9 1399 if ((TBmotorDirecti==0)&&(erroreTamburo==1)){
nerit 0:1e09cd7d66b4 1400 cntCellsForReload++;
nerit 6:3fca0ca1949e 1401 if (cntCellsForReload >= cellsCountSet){
nerit 9:503e2aba047c 1402 TBmotorDirecti=1; // rotazione normale
nerit 0:1e09cd7d66b4 1403 erroreTamburo=0;
nerit 9:503e2aba047c 1404 cntCellsCorrect=0;
nerit 0:1e09cd7d66b4 1405 }
nerit 0:1e09cd7d66b4 1406 }
nerit 7:c9fd242538d9 1407 #if defined(seedSensor)
nerit 7:c9fd242538d9 1408 resetDelay();
nerit 7:c9fd242538d9 1409 delaySeedCheck.start();
nerit 7:c9fd242538d9 1410 #endif
nerit 0:1e09cd7d66b4 1411 }
nerit 9:503e2aba047c 1412 if ((double)TBactualPosition > ((TBgiroStep/cellsNumber)*1.2f)&&(erroreTamburo==0)){
nerit 0:1e09cd7d66b4 1413 if (firstStart==0){
nerit 5:3b95bbfe2dc9 1414 if (cntTbError>2){
nerit 5:3b95bbfe2dc9 1415 all_cellSignal=1;
nerit 7:c9fd242538d9 1416 #if defined(seedSensor)
nerit 7:c9fd242538d9 1417 resetDelay();
nerit 7:c9fd242538d9 1418 #endif
nerit 5:3b95bbfe2dc9 1419 }
nerit 0:1e09cd7d66b4 1420 }
nerit 0:1e09cd7d66b4 1421 if (erroreTamburo==0){
nerit 0:1e09cd7d66b4 1422 erroreTamburo=1;
nerit 9:503e2aba047c 1423 TBmotorDirecti=0; // rotazione inversa
nerit 0:1e09cd7d66b4 1424 cntCellsForReload=0;
nerit 0:1e09cd7d66b4 1425 cntTbError++;
nerit 7:c9fd242538d9 1426 #if defined(seedSensor)
nerit 7:c9fd242538d9 1427 resetDelay();
nerit 7:c9fd242538d9 1428 #endif
nerit 0:1e09cd7d66b4 1429 }
nerit 0:1e09cd7d66b4 1430 }
nerit 5:3b95bbfe2dc9 1431 if (((double)TBactualPosition > ((TBgiroStep/cellsNumber)*3.0f))||(cntTbError>4)){
nerit 0:1e09cd7d66b4 1432 if (firstStart==0){
nerit 0:1e09cd7d66b4 1433 all_noStepRota=1;
nerit 7:c9fd242538d9 1434 #if defined(seedSensor)
nerit 7:c9fd242538d9 1435 resetDelay();
nerit 7:c9fd242538d9 1436 #endif
nerit 0:1e09cd7d66b4 1437 }
nerit 0:1e09cd7d66b4 1438 cntTbError=0;
nerit 0:1e09cd7d66b4 1439 }
nerit 0:1e09cd7d66b4 1440 // ----------------------------------------
nerit 0:1e09cd7d66b4 1441 // read and manage joystick
nerit 0:1e09cd7d66b4 1442 // WARNING - ENABLE CYCLE IS SOFTWARE ALWAYS ACTIVE
nerit 0:1e09cd7d66b4 1443 if (enableCycle==1){
nerit 0:1e09cd7d66b4 1444 if(runRequestBuf==1){
nerit 0:1e09cd7d66b4 1445 if (OldStartCycle!=runRequestBuf){
nerit 0:1e09cd7d66b4 1446 if((startCycle==0)&&(zeroCycleEnd==1)){
nerit 0:1e09cd7d66b4 1447 startCycle=1;
nerit 0:1e09cd7d66b4 1448 OldStartCycle = runRequestBuf;
nerit 0:1e09cd7d66b4 1449 oldZeroCycle=0;
nerit 0:1e09cd7d66b4 1450 }
nerit 0:1e09cd7d66b4 1451 }
nerit 0:1e09cd7d66b4 1452 }else{
nerit 0:1e09cd7d66b4 1453 startCycle=0;
nerit 0:1e09cd7d66b4 1454 pntMedia=0;
nerit 0:1e09cd7d66b4 1455 }
nerit 0:1e09cd7d66b4 1456 if (azzeraDaCan==1){
nerit 0:1e09cd7d66b4 1457 if (tractorSpeed_MtS_timed==0.0f){
nerit 0:1e09cd7d66b4 1458 zeroRequestBuf=1;
nerit 0:1e09cd7d66b4 1459 oldZeroCycle=0;
nerit 0:1e09cd7d66b4 1460 }
nerit 0:1e09cd7d66b4 1461 azzeraDaCan=0;
nerit 0:1e09cd7d66b4 1462 }
nerit 0:1e09cd7d66b4 1463 if (loadDaCan==1){
nerit 0:1e09cd7d66b4 1464 if (tractorSpeed_MtS_timed==0.0f){
nerit 0:1e09cd7d66b4 1465 ciclaTB();
nerit 0:1e09cd7d66b4 1466 }
nerit 0:1e09cd7d66b4 1467 }
nerit 0:1e09cd7d66b4 1468 if ((zeroRequestBuf==1)){
nerit 0:1e09cd7d66b4 1469 if (oldZeroCycle!=zeroRequestBuf){
nerit 0:1e09cd7d66b4 1470 zeroCycle=1;
nerit 0:1e09cd7d66b4 1471 zeroCycleEnd=0;
nerit 0:1e09cd7d66b4 1472 SDzeroed=0;
nerit 0:1e09cd7d66b4 1473 TBzeroed=0;
nerit 0:1e09cd7d66b4 1474 zeroTrigger=0;
nerit 0:1e09cd7d66b4 1475 oldZeroCycle = zeroRequestBuf;
nerit 0:1e09cd7d66b4 1476 }
nerit 0:1e09cd7d66b4 1477 }
nerit 0:1e09cd7d66b4 1478 }else{
nerit 0:1e09cd7d66b4 1479 startCycle=0;
nerit 0:1e09cd7d66b4 1480 zeroCycle=0;
nerit 0:1e09cd7d66b4 1481 }
nerit 0:1e09cd7d66b4 1482
nerit 0:1e09cd7d66b4 1483 //***************************************************************************************************
nerit 0:1e09cd7d66b4 1484 // pulseRised define the event of speed wheel pulse occurs
nerit 0:1e09cd7d66b4 1485 //
nerit 0:1e09cd7d66b4 1486 double maxInterval = pulseDistance/minWorkSpeed;
nerit 0:1e09cd7d66b4 1487 double minIntervalPulse = pulseDistance/maxWorkSpeed;
nerit 0:1e09cd7d66b4 1488 if (pulseRised==1){
nerit 0:1e09cd7d66b4 1489 if (enableSpeed<10){enableSpeed++;}
nerit 5:3b95bbfe2dc9 1490 pulseRised=0;
nerit 5:3b95bbfe2dc9 1491 pulseRised1=1;
nerit 5:3b95bbfe2dc9 1492 speedMediaCalc();
nerit 0:1e09cd7d66b4 1493 // calcola velocità trattore
nerit 0:1e09cd7d66b4 1494 if(enableSpeed>=2){
nerit 0:1e09cd7d66b4 1495 if ((pulseSpeedInterval>=0.0f)){ //minIntervalPulse)&&(pulseSpeedInterval<maxInterval)){
nerit 8:0e643ea7834f 1496 if((quincCnt<3)||(speedFromMaster==0.0f)||(enableSimula==1)){
nerit 7:c9fd242538d9 1497 tractorSpeed_MtS_timed = ((pulseDistance / pulseSpeedInterval)); // tractor speed (unit= Mt/S) from pulse time interval
nerit 7:c9fd242538d9 1498 }
nerit 7:c9fd242538d9 1499 /*#if !defined(speedMaster)
nerit 5:3b95bbfe2dc9 1500 if (quincCnt>=5){
nerit 5:3b95bbfe2dc9 1501 if (speedFromMaster>0.0f){
nerit 5:3b95bbfe2dc9 1502 tractorSpeed_MtS_timed = speedFromMaster + percento;
nerit 5:3b95bbfe2dc9 1503 }
nerit 5:3b95bbfe2dc9 1504 }
nerit 7:c9fd242538d9 1505 #endif*/
nerit 0:1e09cd7d66b4 1506 if (checkSDrotation==0){
nerit 0:1e09cd7d66b4 1507 checkSDrotation=1;
nerit 0:1e09cd7d66b4 1508 SDwheelTimer.start();
nerit 0:1e09cd7d66b4 1509 }
nerit 0:1e09cd7d66b4 1510 }
nerit 0:1e09cd7d66b4 1511 }
nerit 0:1e09cd7d66b4 1512 speedTimeOut.reset();
nerit 0:1e09cd7d66b4 1513 }else{
nerit 0:1e09cd7d66b4 1514 double oldLastPr = (double)oldLastPulseRead*1.7f;
nerit 0:1e09cd7d66b4 1515 if((double)speedTimeOut.read_us()> (oldLastPr)){
nerit 0:1e09cd7d66b4 1516 tractorSpeed_MtS_timed = 0.0f;
nerit 7:c9fd242538d9 1517 #if defined(seedSensor)
nerit 7:c9fd242538d9 1518 resetDelay();
nerit 7:c9fd242538d9 1519 #endif
nerit 0:1e09cd7d66b4 1520 pntMedia=0;
nerit 0:1e09cd7d66b4 1521 speedTimeOut.reset();
nerit 0:1e09cd7d66b4 1522 enableSpeed=0;
nerit 0:1e09cd7d66b4 1523 quincCnt=0;
nerit 0:1e09cd7d66b4 1524 }
nerit 0:1e09cd7d66b4 1525 }
nerit 7:c9fd242538d9 1526
nerit 7:c9fd242538d9 1527 #if defined(seedSensor)
nerit 7:c9fd242538d9 1528 if (seedSensorEnable==true){
nerit 7:c9fd242538d9 1529 if (delaySeedCheck.read_ms()>100){
nerit 7:c9fd242538d9 1530 if (seedSee==0){
nerit 7:c9fd242538d9 1531 all_noSeedOnCe=1;
nerit 7:c9fd242538d9 1532 }
nerit 7:c9fd242538d9 1533 resetDelay();
nerit 7:c9fd242538d9 1534 }
nerit 7:c9fd242538d9 1535 }
nerit 7:c9fd242538d9 1536 #endif
nerit 0:1e09cd7d66b4 1537 // esegue il controllo di velocità minima
nerit 7:c9fd242538d9 1538 /*if ((double)speedTimer.read_ms()>=maxInterval){
nerit 4:d32258ec411f 1539 tractorSpeed_MtS_timed = 0.0f;
nerit 0:1e09cd7d66b4 1540 enableSpeed=0;
nerit 7:c9fd242538d9 1541 }*/
nerit 6:3fca0ca1949e 1542 // esegue il controllo di velocità massima
nerit 7:c9fd242538d9 1543 /*if ((double)speedTimer.read_ms()<=minIntervalPulse){
nerit 6:3fca0ca1949e 1544 tractorSpeed_MtS_timed = 4.5f;
nerit 7:c9fd242538d9 1545 }*/
nerit 0:1e09cd7d66b4 1546 //***************************************************************************************************************
nerit 0:1e09cd7d66b4 1547 // cycle logic control section
nerit 0:1e09cd7d66b4 1548 //***************************************************************************************************************
nerit 0:1e09cd7d66b4 1549 if (enableSimula==1){if(simOk==0){tractorSpeed_MtS_timed=0.0f;}}
nerit 0:1e09cd7d66b4 1550 if ((tractorSpeed_MtS_timed>0.01f)){
nerit 0:1e09cd7d66b4 1551 cycleStopRequest=1;
nerit 0:1e09cd7d66b4 1552 // calcola il tempo teorico di passaggio becchi sulla base della velocità del trattore
nerit 0:1e09cd7d66b4 1553 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 5:3b95bbfe2dc9 1554 if (encoder==false){
nerit 5:3b95bbfe2dc9 1555 if (speedFromPick==1) {
nerit 5:3b95bbfe2dc9 1556 tempoTraBecchi_mS = (tempoGiroSD / pickNumber)*1000.0f; // tempo tra due impulsi dai becchi in millisecondi ( circa 157mS a 4,5Km/h)
nerit 5:3b95bbfe2dc9 1557 }else{
nerit 5:3b95bbfe2dc9 1558 tempoTraBecchi_mS = (tempoGiroSD / 25.0f)*1000.0f; // tempo tra due impulsi dai becchi in millisecondi ( circa 157mS a 4,5Km/h)
nerit 5:3b95bbfe2dc9 1559 }
nerit 0:1e09cd7d66b4 1560 }else{
nerit 5:3b95bbfe2dc9 1561 tempoTraBecchi_mS = (tempoGiroSD / (SDreductionRatio*25.5f))*1000.0f; // tempo tra due impulsi dai becchi in millisecondi ( circa 157mS a 4,5Km/h)
nerit 5:3b95bbfe2dc9 1562 double pippo=0.0f;
nerit 5:3b95bbfe2dc9 1563 #if !defined(speedMaster)
nerit 5:3b95bbfe2dc9 1564 pippo = seedPerimeter / speedFromMaster;
nerit 5:3b95bbfe2dc9 1565 #endif
nerit 5:3b95bbfe2dc9 1566 tempoBecchiPerQuinc = (pippo / pickNumber)*1000.0f;
nerit 0:1e09cd7d66b4 1567 }
nerit 0:1e09cd7d66b4 1568 //*******************************************
nerit 0:1e09cd7d66b4 1569 // segue calcolo duty cycle comando motore DC per allinearsi con la velocità del trattore
nerit 0:1e09cd7d66b4 1570 double dutyTeorico = 0.00;
nerit 0:1e09cd7d66b4 1571 if ((tractorSpeed_MtS_timed>0.0)&&(tractorSpeed_MtS_timed<tabSpeed[0])){dutyTeorico = tabComan[0];}
nerit 0:1e09cd7d66b4 1572 for (int ii = 0;ii<16;ii++){
nerit 0:1e09cd7d66b4 1573 if ((tractorSpeed_MtS_timed>=tabSpeed[ii])&&(tractorSpeed_MtS_timed<tabSpeed[ii+1])){
nerit 0:1e09cd7d66b4 1574 dutyTeorico = tabComan[ii+1];
nerit 0:1e09cd7d66b4 1575 }
nerit 0:1e09cd7d66b4 1576 }
nerit 6:3fca0ca1949e 1577 if (tractorSpeed_MtS_timed > tabSpeed[16]){dutyTeorico=tractorSpeed_MtS_timed/maxWorkSpeed;}
nerit 2:d9c7430ae953 1578 #if !defined(speedMaster)
nerit 4:d32258ec411f 1579 quinCalc();
nerit 2:d9c7430ae953 1580 #endif
nerit 5:3b95bbfe2dc9 1581 if ((enableSpeed>3)&&(pulseRised2==1)&&(quincCnt>=2)){
nerit 0:1e09cd7d66b4 1582 double erroreTempo = 0.0f;
nerit 5:3b95bbfe2dc9 1583 if(encoder==false){
nerit 5:3b95bbfe2dc9 1584 if(speedFromPick==1){
nerit 3:c0f11ca4df02 1585 erroreTempo = (double)timeIntraPick - tempoTraBecchi_mS;
nerit 5:3b95bbfe2dc9 1586 }else{
nerit 5:3b95bbfe2dc9 1587 erroreTempo = (double)memoTimeHole - tempoTraBecchi_mS; // errore tra il tempo previsto ed il tempo reale ( >0 se sto andando più piano del previsto)
nerit 5:3b95bbfe2dc9 1588 }
nerit 0:1e09cd7d66b4 1589 }else{
nerit 5:3b95bbfe2dc9 1590 erroreTempo = ((double)memoTimeHole/1000.0f) - tempoTraBecchi_mS; // errore tra il tempo previsto ed il tempo reale ( >0 se sto andando più piano del previsto)
nerit 0:1e09cd7d66b4 1591 }
nerit 0:1e09cd7d66b4 1592 double errorePercentuale = erroreTempo / tempoTraBecchi_mS;
nerit 1:e88bf5011af6 1593 double k3=0.0f;
nerit 1:e88bf5011af6 1594 double k4=0.0f;
nerit 1:e88bf5011af6 1595 double k5=0.0f;
nerit 4:d32258ec411f 1596 double k6=0.0f;
nerit 4:d32258ec411f 1597 /*if (tractorSpeed_MtS_timed <= minSeedSpeed){
nerit 4:d32258ec411f 1598 k3=1.030f;
nerit 4:d32258ec411f 1599 k4=5.103f;
nerit 4:d32258ec411f 1600 k5=10.00f;
nerit 4:d32258ec411f 1601 k6=20.50f;
nerit 4:d32258ec411f 1602 }else{*/
nerit 8:0e643ea7834f 1603 #if defined(speedMaster)
nerit 8:0e643ea7834f 1604 k3=0.010f;
nerit 8:0e643ea7834f 1605 #else
nerit 8:0e643ea7834f 1606 k3=0.050f;
nerit 8:0e643ea7834f 1607 #endif
nerit 7:c9fd242538d9 1608 k4=1.103f;
nerit 7:c9fd242538d9 1609 k5=10.00f;
nerit 7:c9fd242538d9 1610 k6=20.50f;
nerit 4:d32258ec411f 1611 //}
nerit 7:c9fd242538d9 1612 double L1 = 0.045f;
nerit 7:c9fd242538d9 1613 double L_1=-0.045f;
nerit 7:c9fd242538d9 1614 double L2 = 0.150f;
nerit 7:c9fd242538d9 1615 double L_2=-0.150f;
nerit 7:c9fd242538d9 1616 double L3 = 0.301f;
nerit 7:c9fd242538d9 1617 double L_3=-0.301f;
nerit 4:d32258ec411f 1618 double k1=0.0f;
nerit 4:d32258ec411f 1619 if ((errorePercentuale > L3)||(errorePercentuale < L_3)){
nerit 4:d32258ec411f 1620 k1=errorePercentuale*k6;
nerit 1:e88bf5011af6 1621 }
nerit 4:d32258ec411f 1622 if (((errorePercentuale >= L2)&&(errorePercentuale<=L3))||((errorePercentuale <= L_2)&&(errorePercentuale>=L_3))){
nerit 1:e88bf5011af6 1623 k1=errorePercentuale*k5;
nerit 1:e88bf5011af6 1624 }
nerit 4:d32258ec411f 1625 if (((errorePercentuale < L2)&&(errorePercentuale>L1))||((errorePercentuale > L_2)&&(errorePercentuale<L_1))){
nerit 1:e88bf5011af6 1626 k1=errorePercentuale*k4;
nerit 1:e88bf5011af6 1627 }
nerit 4:d32258ec411f 1628 if ((errorePercentuale < L1)||(errorePercentuale > L_1)){
nerit 1:e88bf5011af6 1629 k1=errorePercentuale*k3;
nerit 1:e88bf5011af6 1630 }
nerit 4:d32258ec411f 1631 double memoCorrezione = k1;
nerit 4:d32258ec411f 1632 if (quincCnt >= 2){
nerit 4:d32258ec411f 1633 correzione = correzione + memoCorrezione;
nerit 4:d32258ec411f 1634 if (correzione > (1.0f - dutyTeorico)){correzione = (1.0f - dutyTeorico);}
nerit 4:d32258ec411f 1635 if ((correzione < 0.0f)&&(dutyTeorico+correzione<0.0f)){correzione = -1.0f*dutyTeorico;}
nerit 4:d32258ec411f 1636 }
nerit 4:d32258ec411f 1637 pulseRised1=0;
nerit 4:d32258ec411f 1638 pulseRised2=0;
nerit 1:e88bf5011af6 1639 #if defined(pcSerial)
nerit 4:d32258ec411f 1640 #if defined(Qnca)
nerit 5:3b95bbfe2dc9 1641 pc.printf("ErTem: %f K1: %f Corr: %f MemoCorr:%f DutyTeo: %f \n",erroreTempo, k1,correzione, memoCorrezione, dutyTeorico);
nerit 4:d32258ec411f 1642 pc.printf("TsP: %f SpW: %f InPic: %f TBec: %f EPerc: %f Duty:%f \n",tractorSpeed_MtS_timed,speedOfSeedWheel,timeIntraPick, tempoTraBecchi_mS,errorePercentuale, dcActualDuty);
nerit 1:e88bf5011af6 1643 #endif
nerit 1:e88bf5011af6 1644 #endif
nerit 4:d32258ec411f 1645 #if defined(pcSerial)
nerit 4:d32258ec411f 1646 #if defined(Qncb)
nerit 4:d32258ec411f 1647 pc.printf("TsP: %f SpW: %f InPic: %f EPerc: %f Duty:%f \n",tractorSpeed_MtS_timed,speedOfSeedWheel,timeIntraPick, errorePercentuale, dcActualDuty);
nerit 4:d32258ec411f 1648 #endif
nerit 4:d32258ec411f 1649 #endif
nerit 0:1e09cd7d66b4 1650 }
nerit 0:1e09cd7d66b4 1651 // introduce il controllo di corrente
nerit 6:3fca0ca1949e 1652 if (currentCheckEnable==true){
nerit 6:3fca0ca1949e 1653 if (incrementCurrent){
nerit 6:3fca0ca1949e 1654 boostDcOut +=0.005f;
nerit 6:3fca0ca1949e 1655 }
nerit 6:3fca0ca1949e 1656 if (reduceCurrent){
nerit 6:3fca0ca1949e 1657 boostDcOut -=0.005f;
nerit 6:3fca0ca1949e 1658 }
nerit 6:3fca0ca1949e 1659 if (boostDcOut >= 0.2f){
nerit 6:3fca0ca1949e 1660 boostDcOut=0.2f;
nerit 6:3fca0ca1949e 1661 all_genericals=1;
nerit 6:3fca0ca1949e 1662 }
nerit 6:3fca0ca1949e 1663 if (boostDcOut <=-0.2f){
nerit 6:3fca0ca1949e 1664 boostDcOut=-0.2f;
nerit 6:3fca0ca1949e 1665 all_genericals=1;
nerit 6:3fca0ca1949e 1666 }
nerit 6:3fca0ca1949e 1667 correzione += boostDcOut;
nerit 0:1e09cd7d66b4 1668 }
nerit 1:e88bf5011af6 1669 DC_brake=0;
nerit 1:e88bf5011af6 1670 DC_forward=1;
nerit 1:e88bf5011af6 1671 DC_prepare();
nerit 0:1e09cd7d66b4 1672
nerit 0:1e09cd7d66b4 1673 // il semiperiodoreale è calcolato sulla lettura del passaggio becchi reale
nerit 5:3b95bbfe2dc9 1674 seedWheelPeriod = semiPeriodoReale;
nerit 0:1e09cd7d66b4 1675 if (seedWheelPeriod < 180.0f){seedWheelPeriod = 180.0f;}
nerit 0:1e09cd7d66b4 1676 if ((oldSeedWheelPeriod!=seedWheelPeriod)&&(seedWheelPeriod >=180.0f )){
nerit 0:1e09cd7d66b4 1677 SDticker.attach_us(&step_SDPulseOut,seedWheelPeriod); // clock time are milliseconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 1678 oldSeedWheelPeriod=seedWheelPeriod;
nerit 0:1e09cd7d66b4 1679 }
nerit 0:1e09cd7d66b4 1680
nerit 4:d32258ec411f 1681 if((quincCnt>=3)){
nerit 0:1e09cd7d66b4 1682 if (correzioneAttiva==1){
nerit 0:1e09cd7d66b4 1683 dcActualDuty = dutyTeorico + correzione;
nerit 4:d32258ec411f 1684 }else{
nerit 4:d32258ec411f 1685 dcActualDuty = dutyTeorico;
nerit 0:1e09cd7d66b4 1686 }
nerit 0:1e09cd7d66b4 1687 }else{
nerit 0:1e09cd7d66b4 1688 dcActualDuty = dutyTeorico;
nerit 0:1e09cd7d66b4 1689 }
nerit 7:c9fd242538d9 1690 if (dcActualDuty <=0.0f){dcActualDuty=0.05f;}
nerit 7:c9fd242538d9 1691 if (dcActualDuty > 0.95f){dcActualDuty = 0.95f;}//dcMaxSpeed;}
nerit 4:d32258ec411f 1692 if (olddcActualDuty!=dcActualDuty){
nerit 7:c9fd242538d9 1693 SDmotorPWM.write(1.0f-dcActualDuty);
nerit 4:d32258ec411f 1694 olddcActualDuty=dcActualDuty;
nerit 4:d32258ec411f 1695 }
nerit 0:1e09cd7d66b4 1696 // allarme
nerit 0:1e09cd7d66b4 1697 if (SDwheelTimer.read_ms()>4000){
nerit 0:1e09cd7d66b4 1698 if (firstStart==0){
nerit 0:1e09cd7d66b4 1699 all_noDcRotati=1;
nerit 0:1e09cd7d66b4 1700 }
nerit 0:1e09cd7d66b4 1701 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 1702 #if defined(VediAllarmi)
nerit 0:1e09cd7d66b4 1703 pc.printf("allarme no DC rotation");
nerit 0:1e09cd7d66b4 1704 #endif
nerit 0:1e09cd7d66b4 1705 #endif
nerit 0:1e09cd7d66b4 1706
nerit 0:1e09cd7d66b4 1707 }
nerit 0:1e09cd7d66b4 1708
nerit 0:1e09cd7d66b4 1709 //***************************************************************************************************************
nerit 0:1e09cd7d66b4 1710 // CONTROLLA TAMBURO
nerit 0:1e09cd7d66b4 1711 //***************************************************************************************************************
nerit 0:1e09cd7d66b4 1712 if(lowSpeed==0){
nerit 0:1e09cd7d66b4 1713 if (syncroCheck==1){
nerit 0:1e09cd7d66b4 1714 syncroCheck=0;
nerit 0:1e09cd7d66b4 1715 lockStart=1;
nerit 0:1e09cd7d66b4 1716 periodo = TBperiod;
nerit 0:1e09cd7d66b4 1717 if (aspettaStart==0){cambiaTB(periodo);}
nerit 0:1e09cd7d66b4 1718 }
nerit 0:1e09cd7d66b4 1719 // controllo di stop
nerit 0:1e09cd7d66b4 1720 double memoIntraP = (double)memoIntraPick*1.8f;
nerit 0:1e09cd7d66b4 1721 if ((double)rotationTimeOut.read_ms()> (memoIntraP)){
nerit 0:1e09cd7d66b4 1722 syncroCheck=0;
nerit 0:1e09cd7d66b4 1723 aspettaStart=1;
nerit 0:1e09cd7d66b4 1724 countCicli=0;
nerit 0:1e09cd7d66b4 1725 if (TBzeroCyclePulse==1){TBticker.detach();}
nerit 0:1e09cd7d66b4 1726 }
nerit 0:1e09cd7d66b4 1727 }else{ // fine ciclo fuori da low speed
nerit 0:1e09cd7d66b4 1728 syncroCheck=0;
nerit 0:1e09cd7d66b4 1729 lockStart=0;
nerit 0:1e09cd7d66b4 1730 if (beccoPronto==1){
nerit 0:1e09cd7d66b4 1731 if (tamburoStandard==1){
nerit 0:1e09cd7d66b4 1732 double ritardoMassimo = 0.0f;
nerit 5:3b95bbfe2dc9 1733 if (encoder==false){
nerit 5:3b95bbfe2dc9 1734 if(speedFromPick==1){
nerit 5:3b95bbfe2dc9 1735 ritardoMassimo = (double)timeIntraPick;
nerit 5:3b95bbfe2dc9 1736 }else{
nerit 5:3b95bbfe2dc9 1737 ritardoMassimo = (double)memoTimeHole;
nerit 5:3b95bbfe2dc9 1738 }
nerit 5:3b95bbfe2dc9 1739 }else{
nerit 0:1e09cd7d66b4 1740 ritardoMassimo = (double)timeIntraPick;
nerit 0:1e09cd7d66b4 1741 }
nerit 6:3fca0ca1949e 1742 int tempoDiSincro = (int)((double)(ritardoMassimo - ((tempoBecco/2.0f)+((speedOfSeedWheel/maxWorkSpeed)*ritardoMassimo)))); //
nerit 0:1e09cd7d66b4 1743 if (tempoDiSincro <= 1){tempoDiSincro=1;}
nerit 0:1e09cd7d66b4 1744 if ((sincroTimer.read_ms()>= tempoDiSincro)){
nerit 0:1e09cd7d66b4 1745 if (tractorSpeed_MtS_timed >= minWorkSpeed){startCicloTB=1;}
nerit 0:1e09cd7d66b4 1746 beccoPronto=0;
nerit 0:1e09cd7d66b4 1747 }
nerit 0:1e09cd7d66b4 1748 }else{
nerit 0:1e09cd7d66b4 1749 // tamburo per zucca
nerit 0:1e09cd7d66b4 1750 if (speedOfSeedWheel >= minWorkSpeed){startCicloTB=1;}
nerit 0:1e09cd7d66b4 1751 beccoPronto=0;
nerit 0:1e09cd7d66b4 1752 }
nerit 0:1e09cd7d66b4 1753 }
nerit 0:1e09cd7d66b4 1754 ciclaTB();
nerit 0:1e09cd7d66b4 1755 }
nerit 0:1e09cd7d66b4 1756 //*************************************************************
nerit 0:1e09cd7d66b4 1757 }else{ // fine ciclo con velocita maggiore di 0
nerit 0:1e09cd7d66b4 1758 SDwheelTimer.stop();
nerit 0:1e09cd7d66b4 1759 SDwheelTimer.reset();
nerit 7:c9fd242538d9 1760 #if defined(seedSensor)
nerit 7:c9fd242538d9 1761 resetDelay();
nerit 7:c9fd242538d9 1762 #endif
nerit 0:1e09cd7d66b4 1763 checkSDrotation=0;
nerit 0:1e09cd7d66b4 1764 oldFaseLavoro=0;
nerit 0:1e09cd7d66b4 1765 aspettaStart=1;
nerit 0:1e09cd7d66b4 1766 countCicli=0;
nerit 0:1e09cd7d66b4 1767 startCycle=0;
nerit 0:1e09cd7d66b4 1768 oldSeedWheelPeriod=0.0f;
nerit 0:1e09cd7d66b4 1769 oldPeriodoTB=0.0f;
nerit 0:1e09cd7d66b4 1770 correzione=0.0f;
nerit 0:1e09cd7d66b4 1771 OLDpulseSpeedInterval=1000.01f;
nerit 0:1e09cd7d66b4 1772 cicloTbinCorso=0;
nerit 0:1e09cd7d66b4 1773 cntTbError=0;
nerit 0:1e09cd7d66b4 1774 if (cycleStopRequest==1){
nerit 0:1e09cd7d66b4 1775 zeroDelay.reset();
nerit 0:1e09cd7d66b4 1776 zeroDelay.start();
nerit 0:1e09cd7d66b4 1777 runRequestBuf=0;
nerit 0:1e09cd7d66b4 1778 zeroRequestBuf=1;
nerit 0:1e09cd7d66b4 1779 cycleStopRequest=0;
nerit 0:1e09cd7d66b4 1780 SDzeroCyclePulse=0;
nerit 0:1e09cd7d66b4 1781 TBzeroCyclePulse=0;
nerit 0:1e09cd7d66b4 1782 zeroCycleEnd=0;
nerit 0:1e09cd7d66b4 1783 zeroCycle=1;
nerit 0:1e09cd7d66b4 1784 zeroTrigger=0;
nerit 8:0e643ea7834f 1785 noSDzeroRequest=1;
nerit 0:1e09cd7d66b4 1786 }
nerit 0:1e09cd7d66b4 1787 }
nerit 0:1e09cd7d66b4 1788 //*************************************************************************************************
nerit 0:1e09cd7d66b4 1789 // ciclo di azzeramento motori
nerit 0:1e09cd7d66b4 1790 if ((zeroCycleEnd==0)&&(zeroCycle==1)){//&&(zeroDelay.read_ms()>10000)){
nerit 0:1e09cd7d66b4 1791 if (zeroTrigger==0){
nerit 0:1e09cd7d66b4 1792 TBticker.attach_us(&step_TBPulseOut,1000.0f); // clock time are seconds and attach seed motor stepper controls
nerit 0:1e09cd7d66b4 1793 DC_forward=1;
nerit 0:1e09cd7d66b4 1794 DC_brake=1;
nerit 0:1e09cd7d66b4 1795 DC_prepare();
nerit 0:1e09cd7d66b4 1796 frenata=0;
nerit 0:1e09cd7d66b4 1797 zeroTrigger=1;
nerit 0:1e09cd7d66b4 1798 ritardoStop.reset();
nerit 0:1e09cd7d66b4 1799 ritardoComandoStop.reset();
nerit 0:1e09cd7d66b4 1800 ritardoComandoStop.start();
nerit 0:1e09cd7d66b4 1801 timeOutZeroSD.start();
nerit 0:1e09cd7d66b4 1802 quincTimeSet.reset();
nerit 0:1e09cd7d66b4 1803 }
nerit 0:1e09cd7d66b4 1804 int tempoFrenata=300;
nerit 0:1e09cd7d66b4 1805 if (((ritardoStop.read_ms()>tempoFrenata)&&(SDzeroDebounced==0))||(accensione==1)||(ritardoComandoStop.read_ms()>400)){
nerit 0:1e09cd7d66b4 1806 accensione=0;
nerit 0:1e09cd7d66b4 1807 avvicinamento=1;
nerit 0:1e09cd7d66b4 1808 avvicinamentoOn.reset();
nerit 0:1e09cd7d66b4 1809 avvicinamentoOn.start();
nerit 7:c9fd242538d9 1810 SDmotorPWM.write(1.0f-0.32f); // duty cycle = 60% of power
nerit 0:1e09cd7d66b4 1811 DC_forward=1;
nerit 0:1e09cd7d66b4 1812 DC_brake=0;
nerit 0:1e09cd7d66b4 1813 DC_prepare();
nerit 0:1e09cd7d66b4 1814 ritardoComandoStop.reset();
nerit 0:1e09cd7d66b4 1815 ritardoComandoStop.stop();
nerit 0:1e09cd7d66b4 1816 }
nerit 0:1e09cd7d66b4 1817 if (avvicinamento==1){
nerit 0:1e09cd7d66b4 1818 if(avvicinamentoOn.read_ms()>300){
nerit 7:c9fd242538d9 1819 SDmotorPWM.write(1.0f-0.7f);
nerit 0:1e09cd7d66b4 1820 avvicinamentoOn.reset();
nerit 0:1e09cd7d66b4 1821 avvicinamentoOff.reset();
nerit 0:1e09cd7d66b4 1822 avvicinamentoOff.start();
nerit 0:1e09cd7d66b4 1823 }
nerit 0:1e09cd7d66b4 1824 if(avvicinamentoOff.read_ms()>100){
nerit 7:c9fd242538d9 1825 SDmotorPWM.write(1.0f-0.32f);
nerit 0:1e09cd7d66b4 1826 avvicinamentoOff.reset();
nerit 0:1e09cd7d66b4 1827 avvicinamentoOff.stop();
nerit 0:1e09cd7d66b4 1828 avvicinamentoOn.start();
nerit 0:1e09cd7d66b4 1829 }
nerit 0:1e09cd7d66b4 1830 }else{
nerit 0:1e09cd7d66b4 1831 avvicinamentoOn.stop();
nerit 0:1e09cd7d66b4 1832 avvicinamentoOff.stop();
nerit 0:1e09cd7d66b4 1833 avvicinamentoOn.reset();
nerit 0:1e09cd7d66b4 1834 avvicinamentoOff.reset();
nerit 0:1e09cd7d66b4 1835 }
nerit 0:1e09cd7d66b4 1836 if (frenata==0){
nerit 0:1e09cd7d66b4 1837 if (SDzeroCyclePulse==1){
nerit 0:1e09cd7d66b4 1838 SDticker.detach();
nerit 0:1e09cd7d66b4 1839 frenata=1;
nerit 0:1e09cd7d66b4 1840 quincTimeSet.reset();
nerit 0:1e09cd7d66b4 1841 quincTimeSet.start();
nerit 0:1e09cd7d66b4 1842 ritardoStop.start();
nerit 0:1e09cd7d66b4 1843 //ritardoComandoStop.reset();
nerit 0:1e09cd7d66b4 1844 //ritardoComandoStop.stop();
nerit 0:1e09cd7d66b4 1845 }
nerit 0:1e09cd7d66b4 1846 }else{
nerit 7:c9fd242538d9 1847 #if defined(mezzo)
nerit 7:c9fd242538d9 1848 if (quinconceActive==0){
nerit 7:c9fd242538d9 1849 if (SDzeroCyclePulse==1){
nerit 7:c9fd242538d9 1850 avvicinamento=0;
nerit 7:c9fd242538d9 1851 DC_brake=1;
nerit 7:c9fd242538d9 1852 DC_prepare();
nerit 7:c9fd242538d9 1853 SDzeroed=1;
nerit 7:c9fd242538d9 1854 ritardoStop.reset();
nerit 7:c9fd242538d9 1855 ritardoStop.stop();
nerit 7:c9fd242538d9 1856 }
nerit 7:c9fd242538d9 1857 }else{
nerit 7:c9fd242538d9 1858 if (quincTimeSet.read_ms()>700){
nerit 7:c9fd242538d9 1859 avvicinamento=0;
nerit 7:c9fd242538d9 1860 DC_brake=1;
nerit 7:c9fd242538d9 1861 DC_prepare();
nerit 7:c9fd242538d9 1862 SDzeroed=1;
nerit 7:c9fd242538d9 1863 ritardoStop.reset();
nerit 7:c9fd242538d9 1864 ritardoStop.stop();
nerit 7:c9fd242538d9 1865 quincTimeSet.stop();
nerit 7:c9fd242538d9 1866 }
nerit 7:c9fd242538d9 1867 }
nerit 7:c9fd242538d9 1868 #else
nerit 0:1e09cd7d66b4 1869 if (SDzeroCyclePulse==1){
nerit 0:1e09cd7d66b4 1870 avvicinamento=0;
nerit 0:1e09cd7d66b4 1871 DC_brake=1;
nerit 0:1e09cd7d66b4 1872 DC_prepare();
nerit 0:1e09cd7d66b4 1873 SDzeroed=1;
nerit 0:1e09cd7d66b4 1874 ritardoStop.reset();
nerit 0:1e09cd7d66b4 1875 ritardoStop.stop();
nerit 0:1e09cd7d66b4 1876 }
nerit 7:c9fd242538d9 1877 #endif
nerit 0:1e09cd7d66b4 1878 }
nerit 0:1e09cd7d66b4 1879 // azzera tutto in time out
nerit 8:0e643ea7834f 1880 if ((timeOutZeroSD.read_ms()>=10000)||(noSDzeroRequest==1)){
nerit 8:0e643ea7834f 1881 if ((firstStart==0)&&(noSDzeroRequest==0)){
nerit 0:1e09cd7d66b4 1882 all_no_Zeroing=1;
nerit 0:1e09cd7d66b4 1883 }
nerit 0:1e09cd7d66b4 1884 avvicinamento=0;
nerit 0:1e09cd7d66b4 1885 DC_brake=1;
nerit 0:1e09cd7d66b4 1886 DC_prepare();
nerit 0:1e09cd7d66b4 1887 SDzeroed=1;
nerit 0:1e09cd7d66b4 1888 ritardoStop.reset();
nerit 0:1e09cd7d66b4 1889 ritardoStop.stop();
nerit 0:1e09cd7d66b4 1890 avvicinamentoOn.stop();
nerit 0:1e09cd7d66b4 1891 avvicinamentoOff.stop();
nerit 0:1e09cd7d66b4 1892 avvicinamentoOn.reset();
nerit 0:1e09cd7d66b4 1893 avvicinamentoOff.reset();
nerit 0:1e09cd7d66b4 1894 ritardoComandoStop.reset();
nerit 0:1e09cd7d66b4 1895 ritardoComandoStop.stop();
nerit 0:1e09cd7d66b4 1896 timeOutZeroSD.stop();
nerit 0:1e09cd7d66b4 1897 timeOutZeroSD.reset();
nerit 8:0e643ea7834f 1898 noSDzeroRequest=0;
nerit 0:1e09cd7d66b4 1899 }
nerit 0:1e09cd7d66b4 1900 if (TBzeroCyclePulse==1){
nerit 0:1e09cd7d66b4 1901 TBticker.detach();
nerit 0:1e09cd7d66b4 1902 TBzeroed=1;
nerit 0:1e09cd7d66b4 1903 }
nerit 0:1e09cd7d66b4 1904 if ((SDzeroed==1)&&(TBzeroed==1)){
nerit 0:1e09cd7d66b4 1905 avvicinamentoOn.stop();
nerit 0:1e09cd7d66b4 1906 avvicinamentoOff.stop();
nerit 0:1e09cd7d66b4 1907 ritardoComandoStop.stop();
nerit 0:1e09cd7d66b4 1908 ritardoStop.stop();
nerit 0:1e09cd7d66b4 1909 zeroCycleEnd=1;
nerit 0:1e09cd7d66b4 1910 zeroCycle=0;
nerit 0:1e09cd7d66b4 1911 zeroTrigger=0;
nerit 0:1e09cd7d66b4 1912 runRequestBuf=1;
nerit 0:1e09cd7d66b4 1913 zeroRequestBuf=0;
nerit 0:1e09cd7d66b4 1914 cycleStopRequest=0;
nerit 0:1e09cd7d66b4 1915 SDzeroed=0;
nerit 0:1e09cd7d66b4 1916 TBzeroed=0;
nerit 0:1e09cd7d66b4 1917 timeOutZeroSD.stop();
nerit 0:1e09cd7d66b4 1918 timeOutZeroSD.reset();
nerit 0:1e09cd7d66b4 1919 }
nerit 0:1e09cd7d66b4 1920 }
nerit 0:1e09cd7d66b4 1921
nerit 0:1e09cd7d66b4 1922 //*************************************************************************************************
nerit 0:1e09cd7d66b4 1923 if (enableCycle==0){
nerit 0:1e09cd7d66b4 1924 zeroTrigger=0;
nerit 0:1e09cd7d66b4 1925 SDmotorPWM=0;
nerit 0:1e09cd7d66b4 1926 SDmotorInA=0;
nerit 0:1e09cd7d66b4 1927 SDmotorInB=0;
nerit 0:1e09cd7d66b4 1928 }
nerit 0:1e09cd7d66b4 1929 SDzeroCyclePulse=0;
nerit 0:1e09cd7d66b4 1930 TBzeroCyclePulse=0;
nerit 0:1e09cd7d66b4 1931 //*************************************************************************************************
nerit 0:1e09cd7d66b4 1932 }else{//end ciclo normale
nerit 0:1e09cd7d66b4 1933 //*************************************************************************************************
nerit 0:1e09cd7d66b4 1934 // task di prova della scheda
nerit 0:1e09cd7d66b4 1935 //*************************************************************************************************
nerit 0:1e09cd7d66b4 1936 #if defined(provaScheda)
nerit 0:1e09cd7d66b4 1937 clocca++;
nerit 0:1e09cd7d66b4 1938 //led = !led;
nerit 0:1e09cd7d66b4 1939 //txMsg.clear();
nerit 0:1e09cd7d66b4 1940 //txMsg << clocca;
nerit 0:1e09cd7d66b4 1941 //test.printf("aogs \n");
nerit 0:1e09cd7d66b4 1942 //if(can1.write(txMsg)){
nerit 0:1e09cd7d66b4 1943 #if defined(pcSerial)
nerit 0:1e09cd7d66b4 1944 pc.printf("Can write OK \n");
nerit 0:1e09cd7d66b4 1945 #endif
nerit 0:1e09cd7d66b4 1946 //}
nerit 0:1e09cd7d66b4 1947 switch (clocca){
nerit 0:1e09cd7d66b4 1948 case 1:
nerit 0:1e09cd7d66b4 1949 TBmotorStepOut=1; // define step command for up down motor driver
nerit 0:1e09cd7d66b4 1950 break;
nerit 0:1e09cd7d66b4 1951 case 2:
nerit 0:1e09cd7d66b4 1952 SDmotorPWM=1; // define step command for seeding whell motor driver
nerit 0:1e09cd7d66b4 1953 break;
nerit 0:1e09cd7d66b4 1954 case 3:
nerit 0:1e09cd7d66b4 1955 speedClock=1; // define input of
nerit 0:1e09cd7d66b4 1956 break;
nerit 0:1e09cd7d66b4 1957 case 4:
nerit 0:1e09cd7d66b4 1958 break;
nerit 0:1e09cd7d66b4 1959 case 5:
nerit 0:1e09cd7d66b4 1960 SDmotorInA=1;
nerit 0:1e09cd7d66b4 1961 SDmotorInB=0;
nerit 0:1e09cd7d66b4 1962 break;
nerit 0:1e09cd7d66b4 1963 case 6:
nerit 0:1e09cd7d66b4 1964 break;
nerit 0:1e09cd7d66b4 1965 case 7:
nerit 0:1e09cd7d66b4 1966 break;
nerit 0:1e09cd7d66b4 1967 case 8:
nerit 0:1e09cd7d66b4 1968 break;
nerit 0:1e09cd7d66b4 1969 case 9:
nerit 0:1e09cd7d66b4 1970 break;
nerit 0:1e09cd7d66b4 1971 case 10:
nerit 0:1e09cd7d66b4 1972 break;
nerit 0:1e09cd7d66b4 1973 case 11:
nerit 0:1e09cd7d66b4 1974 break;
nerit 0:1e09cd7d66b4 1975 case 12:
nerit 0:1e09cd7d66b4 1976 break;
nerit 0:1e09cd7d66b4 1977 case 13:
nerit 0:1e09cd7d66b4 1978 break;
nerit 0:1e09cd7d66b4 1979 case 14:
nerit 0:1e09cd7d66b4 1980 SDmotorPWM=1; // power mosfet 2 command out
nerit 0:1e09cd7d66b4 1981 break;
nerit 0:1e09cd7d66b4 1982 case 15:
nerit 0:1e09cd7d66b4 1983 break;
nerit 0:1e09cd7d66b4 1984 case 16:
nerit 0:1e09cd7d66b4 1985 case 17:
nerit 0:1e09cd7d66b4 1986 break;
nerit 0:1e09cd7d66b4 1987 case 18:
nerit 0:1e09cd7d66b4 1988 TBmotorStepOut=0; // define step command for up down motor driver
nerit 0:1e09cd7d66b4 1989 SDmotorPWM=0; // define step command for seeding whell motor driver
nerit 0:1e09cd7d66b4 1990 speedClock=0; // define input of
nerit 0:1e09cd7d66b4 1991 SDmotorInA=0;
nerit 0:1e09cd7d66b4 1992 SDmotorInB=0;
nerit 0:1e09cd7d66b4 1993 SDmotorPWM=0; // power mosfet 2 command out
nerit 0:1e09cd7d66b4 1994 break;
nerit 0:1e09cd7d66b4 1995 default:
nerit 0:1e09cd7d66b4 1996 clocca=0;
nerit 0:1e09cd7d66b4 1997 break;
nerit 0:1e09cd7d66b4 1998 }
nerit 0:1e09cd7d66b4 1999 wait_ms(100);
nerit 0:1e09cd7d66b4 2000 #endif // end prova scheda
nerit 0:1e09cd7d66b4 2001
nerit 0:1e09cd7d66b4 2002 #if defined(provaDC)
nerit 0:1e09cd7d66b4 2003 int rampa=1000;
nerit 0:1e09cd7d66b4 2004 int pausa=3000;
nerit 0:1e09cd7d66b4 2005 switch (clocca){
nerit 0:1e09cd7d66b4 2006 case 0:
nerit 0:1e09cd7d66b4 2007 DC_brake=0;
nerit 0:1e09cd7d66b4 2008 DC_forward=1;
nerit 0:1e09cd7d66b4 2009 duty_DC+=0.01f;
nerit 7:c9fd242538d9 2010 if (duty_DC>=1.0f){
nerit 7:c9fd242538d9 2011 duty_DC=1.0f;
nerit 0:1e09cd7d66b4 2012 clocca=1;
nerit 0:1e09cd7d66b4 2013 }
nerit 0:1e09cd7d66b4 2014 wait_ms(rampa);
nerit 0:1e09cd7d66b4 2015 break;
nerit 0:1e09cd7d66b4 2016 case 1:
nerit 0:1e09cd7d66b4 2017 wait_ms(pausa*4);
nerit 0:1e09cd7d66b4 2018 clocca=2;
nerit 0:1e09cd7d66b4 2019 break;
nerit 0:1e09cd7d66b4 2020 case 2:
nerit 0:1e09cd7d66b4 2021 DC_brake=0;
nerit 0:1e09cd7d66b4 2022 DC_forward=1;
nerit 0:1e09cd7d66b4 2023 duty_DC-=0.01f;
nerit 0:1e09cd7d66b4 2024 if (duty_DC<=0.0f){
nerit 0:1e09cd7d66b4 2025 duty_DC=0.0f;
nerit 0:1e09cd7d66b4 2026 clocca=3;
nerit 0:1e09cd7d66b4 2027 }
nerit 0:1e09cd7d66b4 2028 wait_ms(rampa);
nerit 0:1e09cd7d66b4 2029 break;
nerit 0:1e09cd7d66b4 2030 case 3:
nerit 0:1e09cd7d66b4 2031 wait_ms(pausa);
nerit 0:1e09cd7d66b4 2032 clocca=4;
nerit 0:1e09cd7d66b4 2033 break;
nerit 0:1e09cd7d66b4 2034 case 4:
nerit 0:1e09cd7d66b4 2035 DC_brake=0;
nerit 0:1e09cd7d66b4 2036 DC_forward=1;
nerit 0:1e09cd7d66b4 2037 duty_DC+=0.01f;
nerit 0:1e09cd7d66b4 2038 if (duty_DC>=1.0f){
nerit 0:1e09cd7d66b4 2039 duty_DC=1.0f;
nerit 0:1e09cd7d66b4 2040 clocca=5;
nerit 0:1e09cd7d66b4 2041 }
nerit 0:1e09cd7d66b4 2042 wait_ms(rampa);
nerit 0:1e09cd7d66b4 2043 break;
nerit 0:1e09cd7d66b4 2044 case 5:
nerit 0:1e09cd7d66b4 2045 wait_ms(pausa);
nerit 0:1e09cd7d66b4 2046 clocca=6;
nerit 0:1e09cd7d66b4 2047 break;
nerit 0:1e09cd7d66b4 2048 case 6:
nerit 0:1e09cd7d66b4 2049 DC_brake=0;
nerit 0:1e09cd7d66b4 2050 DC_forward=1;
nerit 0:1e09cd7d66b4 2051 duty_DC-=0.01f;
nerit 0:1e09cd7d66b4 2052 if (duty_DC<=0.0f){
nerit 0:1e09cd7d66b4 2053 duty_DC=0.0f;
nerit 0:1e09cd7d66b4 2054 clocca=7;
nerit 0:1e09cd7d66b4 2055 }
nerit 0:1e09cd7d66b4 2056 wait_ms(rampa);
nerit 0:1e09cd7d66b4 2057 break;
nerit 0:1e09cd7d66b4 2058 case 7:
nerit 0:1e09cd7d66b4 2059 wait_ms(pausa);
nerit 0:1e09cd7d66b4 2060 clocca=0;
nerit 0:1e09cd7d66b4 2061 break;
nerit 0:1e09cd7d66b4 2062 default:
nerit 0:1e09cd7d66b4 2063 break;
nerit 0:1e09cd7d66b4 2064 }
nerit 0:1e09cd7d66b4 2065 if (oldDuty_DC != duty_DC){
nerit 7:c9fd242538d9 2066 SDmotorPWM.write(1.0f-duty_DC); // duty cycle = stop
nerit 0:1e09cd7d66b4 2067 oldDuty_DC=duty_DC;
nerit 0:1e09cd7d66b4 2068 DC_prepare();
nerit 0:1e09cd7d66b4 2069 }
nerit 0:1e09cd7d66b4 2070 #endif
nerit 0:1e09cd7d66b4 2071 }//end in prova
nerit 0:1e09cd7d66b4 2072 wd.Service(); // kick the dog before the timeout
nerit 0:1e09cd7d66b4 2073 } // end while
nerit 0:1e09cd7d66b4 2074 }// end main
nerit 0:1e09cd7d66b4 2075