1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
|
/************************************************************************************************************************
* Ids_print.c
* Printing module is responsible for :
* operating the dispensers according to predefined dispensing rate from the UI
**************************************************************************************************************************/
#include "include.h"
#include "ids.h"
#include "ids_ex.h"
#include "../control/control.h"
#include "../general/process.h"
#include "../control/pidalgo.h"
#include "../thread/thread.h"
#include "PMR/Hardware/Hardwaremotor.pb-c.h"
#include "PMR/Hardware/HardwareDispenser.pb-c.h"
#include "PMR/Printing/JobDescriptionFileBrushStop.pb-c.h"
#include "PMR/Printing/JobDescriptionFileSegment.pb-c.h"
#include "PMR/Printing/JobUploadStrategy.pb-c.h"
#include "PMR/Printing/JobSegment.pb-c.h"
#include "PMR/Printing/JobTicket.pb-c.h"
#include "StateMachines/Printing/printingSTM.h"
#include "drivers/motors/motor.h"
#include "drivers/valves/valve.h"
#include "Common/SWUpdate/FileSystem.h"
#include "drivers/Flash_Memory/fatfs/ff.h"
#include "modules/heaters/heaters.h"
#include "drivers/Flash_ram/FlashProgram.h"
typedef struct
{
bool m_isEnabled;
float m_SetParam;
float m_mesuredParam;
float m_preError;
float m_integral;
float m_calculatedError;
bool m_isReady;
PID_Config_Params m_params;
}DispenserControlConfig_t;
HardwarePidControl *DispensersControl;// = (HardwarePidControl *)GENHWCFG_MAP_IN_FLASH + 0x4000;
#define MAX_DYE_DISPENSERS 6
int32_t DispenserSamples[MAX_SYSTEM_DISPENSERS][MAX_CONTROL_SAMPLES] = {0};
int DispenserSamplePointer[MAX_SYSTEM_DISPENSERS] = {0};
double DispenserNormalizedErrorCoEfficient[MAX_SYSTEM_DISPENSERS] = {0};
double lubricant_speed = 0.0;
HardwarePidControlType ThreadDispenserIdToControlId[MAX_SYSTEM_DISPENSERS] = { HARDWARE_PID_CONTROL_TYPE__Dispenser1,HARDWARE_PID_CONTROL_TYPE__Dispenser2,HARDWARE_PID_CONTROL_TYPE__Dispenser3,HARDWARE_PID_CONTROL_TYPE__Dispenser4,HARDWARE_PID_CONTROL_TYPE__Dispenser5,HARDWARE_PID_CONTROL_TYPE__Dispenser6,HARDWARE_PID_CONTROL_TYPE__Dispenser7,HARDWARE_PID_CONTROL_TYPE__Dispenser8};
bool DispenserReady[MAX_SYSTEM_DISPENSERS] = {true};
bool IDS_Active = false;
/******************** STRUCTURES AND ENUMs ********************************************/
uint32_t IDS_Valve_DistanceToSpoolReady(uint32_t deviceID, uint32_t ReadValue);
uint32_t IDS_Valve_PresegmentReady(uint32_t deviceID, uint32_t ReadValue);
uint32_t IDSBrushStopRestartCallback(uint32_t IfIndex, uint32_t readValue);
//bool IDS_isDispenserUsedNextSegment(void *JobDetails,int DispenserId, int SegmentId);
/******************** GLOBAL PARAMETERS ********************************************/
DispenserControlConfig_t DispenserControlConfig[MAX_SYSTEM_DISPENSERS];
uint32_t ControlIdtoDispenserId [MAX_SYSTEM_DISPENSERS] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
int OriginalDispenserSpd_2PPS[MAX_SYSTEM_DISPENSERS] = {0,0,0,0,0,0,0,0};
bool DispenserPreSegmentReady[MAX_SYSTEM_DISPENSERS] = {true,true,true,true,true,true,true,true};
bool DispenserSegmentReady[MAX_SYSTEM_DISPENSERS] = {true,true,true,true,true,true,true,true};
bool DispenserDistanceToSpoolReady[MAX_SYSTEM_DISPENSERS] = {true,true,true,true,true,true,true,true};
bool DispenserUsedInJob[MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false};
bool DispensersAlarmState[ MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false};
int JobBrushStopId = 0;
int lInterSegmentLength = 0;
int InterSegmentStepsLimit = 0,InterSegmentStepsCount = 0;
uint32_t InterSegmentStartSprayCleaner;
uint32_t InterSegmentStartRocking;
uint32_t InterSegmentCenterRockers;
uint32_t LeftRockerSpeed = 20;
uint32_t RighttRockerSpeed = 20;
uint32_t CleaningDispenserSpeed = 40;
uint32_t InterSegmentStartWFCFDispensers;
uint32_t WFCF = 80;
bool EnableCleaning = true;
void IDS_Dispenser_SetPreSegmentWFCFValues(double dispenserpresegmentwfcf, double ids_presegment_wfcf_timebeforesegment)
{
if (ids_presegment_wfcf_timebeforesegment)
InterSegmentStartWFCFDispensers = ids_presegment_wfcf_timebeforesegment;
if (dispenserpresegmentwfcf)
WFCF = dispenserpresegmentwfcf;
}
void IDS_Dispenser_SetPreSegmentCleaningValues(double ids_cleaningspeed,double ids_cleaningstartspraypresegmenttime ,double ids_cleaningstopbeforesegmenttime,double ids_leftcleaningmotorspeed,double ids_rightcleaningmotorspeed)
{
if ( ids_cleaningspeed)
CleaningDispenserSpeed = ids_cleaningspeed;
if ( ids_cleaningstartspraypresegmenttime )
{
InterSegmentStartSprayCleaner = ids_cleaningstartspraypresegmenttime;
InterSegmentStartRocking = ids_cleaningstartspraypresegmenttime + 1000;
}
if ( ids_cleaningstopbeforesegmenttime)
InterSegmentCenterRockers = ids_cleaningstopbeforesegmenttime;
if ( ids_leftcleaningmotorspeed)
LeftRockerSpeed = ids_leftcleaningmotorspeed;
if ( ids_rightcleaningmotorspeed)
RighttRockerSpeed = ids_rightcleaningmotorspeed;
}
uint32_t DispenserPreSegmentControlId = 0xFF;
uint32_t BrushStopControlId = 0xFF;
uint32_t PreSegmentControlId = 0xFF;
uint32_t IDS_DispenserControlInit()
{
DispensersControl = (void *)(GENHWCFG_MAP_IN_FLASH + 0x4000);
EraseFlashSection(DispensersControl,sizeof(HardwarePidControl)*MAX_SYSTEM_DISPENSERS);
return OK;
}
uint32_t IDS_DispenserPidRequestMessage(HardwarePidControl* request)
{
int Dispenser_i,i;
//int temp;
for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
{
if (ThreadDispenserIdToControlId[i] == request->hardwarepidcontroltype)
{
Dispenser_i = i;
break;
}
}
if (request->pvinputfilterfactormode > MAX_CONTROL_SAMPLES)
request->pvinputfilterfactormode = MAX_CONTROL_SAMPLES;
ReadAppAndProgram(&DispensersControl[Dispenser_i], sizeof(HardwarePidControl), request);
for (i = 0;i < DispensersControl[Dispenser_i].pvinputfilterfactormode; i++)
DispenserSamples[Dispenser_i][i] = 0; //reset the samples value for control beginning
/*DispenserNormalizedErrorCoEfficient[Dispenser_i] = (2*PI*DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].armlength);
temp = 1<<(DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].resolutionbits);
temp=(100*(temp-1)*DancersCfg[ThreadDispenserIdToDancerId[Dispenser_i]].maximalmovementmm);
DispenserNormalizedErrorCoEfficient[Dispenser_i] = DispenserNormalizedErrorCoEfficient[Dispenser_i] / temp;*/
return OK;
}
/*
* IDS Printing support
* Prepare: build pressure in all participating dispensers
* Print - dispense ink to the printing head
* stop - stop dispensing
*
* control processes:
* on prepare stage - each 10msec against the pressure sensors
* on print stage - every 10/100 msec against the speed sensor
*
* */
//Dispenser Pressure control
//callback - calls printing stm with the result
// registration - 10 msec, dispenser pressure sensor
// AddControlCallback(DeviceId2Dispenser[DispenserId], DispenserControlCBFunction, eHundredMillisecond);
// start the dispenser pressure building - move up in a TBD speed, valve closed
//Dispenser Speed control
//callback - handles speed
// registration - 10msec, dispenser speed senseo
// start the dispensing - move up according to the segment defined speed and microstepping, valve opened
//
void DispenserPrepareReady(void)
{
int i;
for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
{
if (DispenserReady[i] == false)
{
return; //not all configured Dispensers are ready
}
}
REPORT_MSG(Module_IDS,"All Dispensers Prepare Ready");
PrepareReady(Module_IDS,ModuleDone);
}
//********************************************************************************************************************
uint32_t IDS_PrepareReady(uint32_t deviceID, uint32_t ReadValue)
{
if (IDS_Active == false)
{
REPORT_MSG(deviceID,"IDS_Active false");
return ERROR;
}
DispenserReady[deviceID] = true;
REPORT_MSG(deviceID,"Dispenser prepare ready");
DispenserPrepareReady();
return OK; // all configured heaters are ready
}
/*
void OpenJobFile();
void CloseJobFile();
JobDescriptionFileSegment *GetNextSegmentFromJobFile();
void FreeSegmentFileData(JobDescriptionFileSegment *Segment);
JobDescriptionFileBrushStop *GetNextBrushStopFromJobFile();
void FreeBrushStopFileData(JobDescriptionFileBrushStop *BrushStop);
*/
/************************************************************************************************************************************
uint32_t IDS_MapDispenserUsedinFileJobshort(void *JobDetails)
{
JobTicket* JobTicket = JobDetails;
JobDescriptionFileBrushStop *BrushStop;
JobDescriptionFileSegment *Segment;
int Dispenser_i, Brush_i,DispenserId;
FRESULT Fresult = FR_OK;
uint32_t status = OK;
bool lookForLubrication = false;
for (Dispenser_i = 0;Dispenser_i<MAX_SYSTEM_DISPENSERS;Dispenser_i++)
{
DispenserUsedInJob[Dispenser_i] = false;
}
if (EnableCleaning == true)
DispenserUsedInJob[CLEANER_DISPENSER] = true;
if (JobTicket->enablelubrication == true)
{
DispenserUsedInJob[LUBRICANT_DISPENSER] = true;
lookForLubrication = true;
}
Fresult = OpenJobFile();
if (Fresult == FR_OK)
{
Segment = GetNextSegmentFromJobFile();
while(Segment)
{
if ((Segment->has_brushstopscount)&&(Segment->brushstopscount))
{
for (Brush_i=0;Brush_i<Segment->brushstopscount;Brush_i++)
{
BrushStop = GetNextBrushStopFromJobFile();
if (BrushStop)
{
if (BrushStop->n_dispensers)
{
for (Dispenser_i = 0;Dispenser_i < BrushStop->n_dispensers;Dispenser_i++)
{
//prepare the SW structures
DispenserId = BrushStop->dispensers[Dispenser_i]->index;
if (BrushStop->dispensers[Dispenser_i]->nanolitterpersecond>0.0)
{
DispenserUsedInJob[DispenserId] = true;
if ((lookForLubrication == true)&&(DispenserId == LUBRICANT_DISPENSER))
{
lookForLubrication = false;
lubricant_speed = BrushStop->dispensers[Dispenser_i]->nanolitterpersecond/BrushStop->dispensers[Dispenser_i]->nanoliterperpulse;
if (BrushStop->dispensers[Dispenser_i]->dispenserstepdivision
!= DISPENSER_STEP_DIVISION__Auto)
{
//MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
lubricant_speed /=
BrushStop->dispensers[Dispenser_i]->dispenserstepdivision; //the dye supply is calculated based on a 1/8 microstep
}
else
{
lubricant_speed/=8;//MotorsCfg[HW_Motor_Id].microstep; //the dye supply is calculated based on a 1/8 microstep
}
REPORT_MSG (lubricant_speed*100, "LUBRICANT_SPEED*100");
}
}
}//for dispenser
}//if dispensers
else
{
LOG_ERROR (BrushStop->index, "no dispensers in brushstop");
}
FreeBrushStopFileData(BrushStop);
BrushStop = NULL;
}
else
{
LOG_ERROR (BrushStop, "malloc error");
status = ERROR;
}
}//for brushstops
}// if brush stop count
FreeSegmentFileData(Segment);
Segment = GetNextSegmentFromJobFile();
}
FreeSegmentFileData(Segment);
CloseJobFile();
}
return status;
}
*************************************************************************************************************************************/
/************************************************************************************************************************************/
uint32_t IDS_MapDispenserUsedinFileJob(void *JobDetails)
{
JobTicket* JobTicket = JobDetails;
uint8_t *SegmentPtr = 0, *BrushStopPtr = 0;
JobDescriptionFileBrushStop *BrushStop;
JobDescriptionFileSegment *Segment;
int Dispenser_i, Brush_i,DispenserId;
uint32_t Bytes = 0,readBytes = 0,ImmediateRead = 0,SegmentSize = 0,BrushStopSize = 0;
uint32_t status = OK;
FRESULT Fresult = FR_OK;
FIL *FileHandle = 0; //the system supports a single active file
bool lookForLubrication = false;
int brushCounter = 0;
/*
Parsing the job description file.
The job description file simply contains an array of segments and their brush stops.
The job description file is meant to be read brush stop by brush stop while the job is in progress.
The following diagram represents a single job description file segment structure.
The process of reading the whole file is simply repeating that reading order.
Each JobDescriptionFileSegment contains a �BrushStopsCount� field that should be used to determine how many brush stops are associated
with the current segment and how many times the process of reading brush stops should be repeated.
1. 32bit integer containing the next JobFileDescriptionSegment message byte count
2. JobDescriptionFileSegment message
3. 32bit integer containing the next JobDescriptionFileBrushStop message byte count
4. JobDescriptionFileBrushStop message
1. Read segment message length.
2. Read segment message.
a. Read brush stop message length.
b. Read brush stop message.
c. Go to step 2.a x Segment.BrushStopsCount.
3. Go to step 1 until end of file.
*/
GeneralHwReady = false;
for (Dispenser_i = 0;Dispenser_i<MAX_SYSTEM_DISPENSERS;Dispenser_i++)
{
DispenserUsedInJob[Dispenser_i] = false;
}
n_segments = 0;
if (EnableCleaning == true)
DispenserUsedInJob[CLEANER_DISPENSER] = true;
if (JobTicket->enablelubrication == true)
{
DispenserUsedInJob[LUBRICANT_DISPENSER] = true;
lookForLubrication = true;
}
if (JobTicket->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile)
{
FileHandle = my_malloc(sizeof(FIL));
Fresult = FileOpen(JobTicket->jobdescriptionfile, &Bytes, FileHandle);
if (Fresult == FR_OK)
{
while((readBytes < Bytes)&&(status == OK))
{
Fresult = f_read(FileHandle,&SegmentSize,4,&ImmediateRead );
if (Fresult == FR_OK)
{
readBytes += ImmediateRead;
SegmentPtr = my_malloc (SegmentSize);
if (SegmentPtr)
{
Fresult = f_read(FileHandle,SegmentPtr,SegmentSize,&ImmediateRead );
if (Fresult == FR_OK)
{
readBytes += ImmediateRead;
n_segments++;
Segment = job_description_file_segment__unpack(NULL, SegmentSize, SegmentPtr);
if ((Segment->has_brushstopscount)&&(Segment->brushstopscount))
{
//REPORT_MSG (Segment->brushstopscount, "Segment->brushstopscount");
for (Brush_i=0;Brush_i<Segment->brushstopscount;Brush_i++)
{
if (status == ERROR)
break;
Fresult = f_read(FileHandle,&BrushStopSize,4,&ImmediateRead );
if (Fresult == FR_OK)
{
readBytes += ImmediateRead;
BrushStopPtr = my_malloc (BrushStopSize);
if (BrushStopPtr)
{
Fresult = f_read(FileHandle,BrushStopPtr,BrushStopSize,&ImmediateRead );
if (Fresult == FR_OK)
{
readBytes += ImmediateRead;
BrushStop = job_description_file_brush_stop__unpack(NULL, BrushStopSize, BrushStopPtr);
//REPORT_MSG (BrushStopSize, "BrushStop");
if ((brushCounter % 100)==0)
{
SendJobProgress(0.0,0,false, "Processing file");
Control_WD(ENABLE,55); //activate heaters/dispenser watchdog, 0.5 seconds
}
brushCounter++;
if (BrushStop->n_dispensers)
{
for (Dispenser_i = 0;Dispenser_i < BrushStop->n_dispensers;Dispenser_i++)
{
//prepare the SW structures
DispenserId = BrushStop->dispensers[Dispenser_i]->index;
if (BrushStop->dispensers[Dispenser_i]->nanolitterpersecond>0.0)
{
DispenserUsedInJob[DispenserId] = true;
}
if ((lookForLubrication == true)&&(DispenserId == LUBRICANT_DISPENSER))
{
lookForLubrication = false;
lubricant_speed = BrushStop->dispensers[Dispenser_i]->nanolitterpersecond/BrushStop->dispensers[Dispenser_i]->nanoliterperpulse;
if (BrushStop->dispensers[Dispenser_i]->dispenserstepdivision
!= DISPENSER_STEP_DIVISION__Auto)
{
//MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
lubricant_speed /=
BrushStop->dispensers[Dispenser_i]->dispenserstepdivision; //the dye supply is calculated based on a 1/8 microstep
}
else
{
lubricant_speed/=8;//MotorsCfg[HW_Motor_Id].microstep; //the dye supply is calculated based on a 1/8 microstep
}
REPORT_MSG (lubricant_speed*100, "LUBRICANT_SPEED*100");
}
}//for dispenser
}//if dispensers
else
{
LOG_ERROR (BrushStop->index, "no dispensers in brushstop");
}
job_description_file_brush_stop__free_unpacked (BrushStop,NULL);
BrushStop = NULL;
} //read brush stop data
else
{
LOG_ERROR (Fresult, "f_read error");
status = ERROR;
}
my_free(BrushStopPtr);
BrushStopPtr = NULL;
}//brushstop malloc ok
else
{
LOG_ERROR (BrushStopPtr, "malloc error");
status = ERROR;
}
}//brushstop size read ok
else
{
LOG_ERROR (Fresult, "f_read error");
status = ERROR;
}
}//for brushstops
}// if brush stop count
else
{
LOG_ERROR (0, "no brushstops error");
status = ERROR;
}
job_description_file_segment__free_unpacked(Segment,NULL);
Segment = NULL;
}// read segment data
my_free(SegmentPtr);
SegmentPtr = NULL;
Task_sleep(10);
}//segment malloc
else
{
LOG_ERROR (SegmentPtr, "malloc error");
status = ERROR;
}
}//segment read size
else
{
LOG_ERROR (Fresult, "f_read error");
status = ERROR;
}
}//while(readBytes < Bytes)
}
else
{
LOG_ERROR (Fresult, "FileOpen error");
status = ERROR;
}
}//file job
if (SegmentPtr)
my_free(SegmentPtr);
if (BrushStopPtr)
my_free(BrushStopPtr);
if (Segment != NULL)
job_description_file_segment__free_unpacked(Segment,NULL);
if (BrushStop != NULL)
job_description_file_brush_stop__free_unpacked (BrushStop,NULL);
Fresult = f_close(FileHandle);
GeneralHwReady = true;
REPORT_MSG (n_segments, "Finished checking the file");
return status;
}
/************************************************************************************************************************************/
bool IDS_MapDispenserUsedinJob(void *JobDetails)
{
JobTicket* JobTicket = JobDetails;
int Dispenser_i, Segment_i,Brush_i,DispenserId;
if (JobTicket->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile)
{
return (IDS_MapDispenserUsedinFileJob(JobDetails));
//return (IDS_MapDispenserUsedinFileJobshort(JobDetails));
}
else
{
for (Dispenser_i = 0;Dispenser_i<MAX_SYSTEM_DISPENSERS;Dispenser_i++)
{
DispenserUsedInJob[Dispenser_i] = false;
}
if (n_segments == 0)
return false;
for (Segment_i=0;Segment_i<n_segments;Segment_i++)
{
for (Brush_i=0;Brush_i<JobTicket->segments[Segment_i]->n_brushstops;Brush_i++)
{
if (JobTicket->segments[Segment_i]->brushstops[Brush_i]->n_dispensers)
{
for (Dispenser_i = 0;Dispenser_i < JobTicket->segments[Segment_i]->brushstops[Brush_i]->n_dispensers;Dispenser_i++)
{
//prepare the SW structures
DispenserId = JobTicket->segments[Segment_i]->brushstops[Brush_i]->dispensers[Dispenser_i]->index;
if (JobTicket->segments[Segment_i]->brushstops[Brush_i]->dispensers[Dispenser_i]->nanolitterpersecond>0.0)
{
DispenserUsedInJob[DispenserId] = true;
if(DispenserId == LUBRICANT_DISPENSER)
{
lubricant_speed = JobTicket->segments[0]->brushstops[0]->dispensers[Dispenser_i]->nanolitterpersecond/
JobTicket->segments[0]->brushstops[0]->dispensers[Dispenser_i]->nanoliterperpulse;
if (JobTicket->segments[0]->brushstops[0]->dispensers[Dispenser_i]->dispenserstepdivision
!= DISPENSER_STEP_DIVISION__Auto)
{
//MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
lubricant_speed /=
JobTicket->segments[0]->brushstops[0]->dispensers[Dispenser_i]->dispenserstepdivision; //the dye supply is calculated based on a 1/8 microstep
}
else
{
lubricant_speed/=8;//MotorsCfg[HW_Motor_Id].microstep; //the dye supply is calculated based on a 1/8 microstep
}
REPORT_MSG (lubricant_speed*100, "LUBRICANT_SPEED*100");
}
}
}//for dispenser
}//if dispensers
}//for brush
}//for segments
}
return true;
}
//********************************************************************************************************************
uint32_t IDSPrepareState(void *JobDetails)
{
int Motor_i, HW_Motor_Id, Pid_Id,i;
//start IDS control for all motors
IDS_Active = true;
Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste);
for (Motor_i = 0;Motor_i < MAX_SYSTEM_DISPENSERS;Motor_i++)
{
HW_Motor_Id = DispenserIdToMotorId[Motor_i];
Pid_Id = Motor_i;/*IDSMotorIdToControlId[Motor_i];*/
DispenserControlConfig[Motor_i].m_params.MAX = 1;
DispenserControlConfig[Motor_i].m_params.MIN = DispensersControl[Pid_Id].outputproportionalpowerlimit*-1;
DispenserControlConfig[Motor_i].m_params.Kd = DispensersControl[Pid_Id].derivativetime;
DispenserControlConfig[Motor_i].m_params.Kp = DispensersControl[Pid_Id].proportionalgain;
DispenserControlConfig[Motor_i].m_params.Ki = DispensersControl[Pid_Id].integraltime;
DispenserControlConfig[Motor_i].m_params.epsilon = 0.01;
DispenserControlConfig[Motor_i].m_params.dt = eHundredMillisecond;
DispenserControlConfig[Motor_i].m_calculatedError = 0;
DispenserControlConfig[Motor_i].m_integral = 0;
DispenserControlConfig[Motor_i].m_isEnabled = true;
DispenserControlConfig[Motor_i].m_isReady = true;
DispenserControlConfig[Motor_i].m_mesuredParam = 0;
DispenserControlConfig[Motor_i].m_preError = 0;
DispenserControlConfig[Motor_i].m_SetParam = 0;//need to update SetParams on presegment stage
MotorSetDirection((TimerMotors_t)HW_Motor_Id,MotorsCfg[HW_Motor_Id].directionthreadwize); //set the dispenser to the
/*Start the dispensers to build initial pressure
* check different handling for dispensers that participate in the first segment and idle dispensers
* start control for initial pressure
*
*/
//ValveCommand (Enable,MixerDirection);
}
//set 3 dancers to the profile positions
//IDS_MapDispenserUsedinJob(JobDetails);
for (i = 0; i < MAX_SYSTEM_DISPENSERS; i++)
{
//IDS_StopHomeDispenser(i);
if (DispenserUsedInJob[i] == true) //we actually should check for all dispensers
{
DispenserReady[i] = false;
IDS_Dispenser_Build_Pressure(i, IDS_PrepareReady);
REPORT_MSG(i,"Dispenser prepare called");
}
else
{
DispenserReady[i] = true;
//IDS_HomeDispenser (i, 1000 , NULL);
}
}
DispenserPrepareReady();
return OK;
}
//********************************************************************************************************************
uint32_t IDS_Valve_PresegmentValveReady(uint32_t deviceID, uint32_t ReadValue)
{
//TimerMotors_t HW_Motor_Id = DispenserIdToMotorId[deviceID];
//MotorStop(HW_Motor_Id,Hard_Hiz);
//REPORT_MSG(deviceID,"Dispenser PreSegment called");
IDS_Valve_PresegmentReady( deviceID, ReadValue);
return OK;
}
//********************************************************************************************************************
uint32_t IDS_Valve_PresegmentReady(uint32_t deviceID, uint32_t ReadValue)
{
int i;
if (IDS_Active == false)
return ERROR;
DispenserPreSegmentReady[deviceID] = true;
//REPORT_MSG(deviceID,"IDS_Valve_Presegment Ready");
for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
{
if (DispenserPreSegmentReady[i] == false)
{
//REPORT_MSG(i,"IDS_Valve_Presegment Not Ready");
return OK; //not all configured heaters are ready
}
}
REPORT_MSG(deviceID,"IDS Presegment Ready!!");
PreSegmentReady(Module_IDS,ModuleDone);
return OK; // all configured heaters are ready
}
//********************************************************************************************************************
JobDescriptionFileBrushStop * FileBrushStop;
char IdsMessage[100];
uint32_t IDSPreSegmentStateCallbackRunner(uint32_t IfIndex, uint32_t ReadValue)
{
JobDispenser **Dispensers;
//set the speed only before the first segment, speed is constant accros job
int Dispenser_i,n_dispensers,DispenserId;
TimerMotors_t HW_Motor_Id;
double segmentfirst_speed;
/*
IDS Pre-Segment (Inter-Segment) activity
1. Cleaning
2. Build pressure toward the waste valve
The IDS pre-segment process will be performed before all segments, including the first one.
The dye dispensers will be in one of two states:
1. After being idle � with a high pressure, idle motor and closed valve (will be performed in job prepare or during the previous segment. For Ty time until pressure Pa is achieved)
2. At work � pushing dye to the mixer.
At pre-segment, TW seconds before its end, the active dispensers will start working in the next segment's speed: Ssegment* WFCF.
After TU milliseconds the valve will open.
At segment start, the waste valve will be redirected to the head and the dispensers' speed will be reduced to the next segment's speed
Cleaning: the cleaning process involves: starting the cleaning dispenser in speed Sclean, starting the head rockers motor(s) in speed S1 and S2,
and stopping the dispenser, centering the rockers Tending milliseconds before segment start.
Segment state:
1. Active dispensers are working.
2. Idle dispensers are filling, until TX+TY seconds before segment end. (TX=backlash time, TY=pressure prepare time). Then they reverse direction and start building pressure until segment end or until pressure PA (= prepare pressure) is achieved.
This means that for each Pre-segment we must calculate: TW,TU,Tending,
This means that for each segment we must calculate: Tx,Ty.
*/
/*uint32_t InterSegmentStartSprayCleaner = 500;
uint32_t InterSegmentStartRocking = 1000;
uint32_t InterSegmentCenterRockers = 3000;
uint32_t InterSegmentStartWFCFDispensers = lInterSegmentLength-1500;
uint32_t IDS_Cleaning_Move_Rockers (int LeftRockerSpeed,int RightRockerSpeed);
uint32_t IDS_Cleaning_Center_And_Stop_Rockers (int timeout,callback_fptr callback);
uint32_t IDS_Cleaning_Spray_Cleaning_Solution (int dispenserSpeed,callback_fptr callback);
uint32_t IDS_Cleaning_Stop_Cleaning_Solution (callback_fptr callback);
*/
//InterSegmentStepsLimit = lInterSegmentLength*10;//100 millisec steps
InterSegmentStepsCount+=100;
if (InterSegmentStepsCount == lInterSegmentLength)
{
//IDS_Valve_PresegmentReady(1,0);
Report("End of Pre-segment Handling",__FILE__,__LINE__,InterSegmentStepsCount,RpWarning,(int)lInterSegmentLength,0);
SafeRemoveControlCallback(DispenserPreSegmentControlId,IDSPreSegmentStateCallbackRunner);
}
if (EnableCleaning == true)
{
if (InterSegmentStartSprayCleaner == InterSegmentStepsCount)
{
Report("Start Spray Cleaner",__FILE__,__LINE__,InterSegmentStepsCount,RpWarning,(int)lInterSegmentLength,0);
//IDS_Cleaning_Spray_Cleaning_Solution (int dispenserSpeed,callback_fptr callback);
}
if (InterSegmentStartRocking == InterSegmentStepsCount)
{
Report("Start cleaning rockers",__FILE__,__LINE__,InterSegmentStepsCount,RpWarning,(int)lInterSegmentLength,0);
//IDS_Cleaning_Move_Rockers (int LeftRockerSpeed,int RightRockerSpeed);
}
if (InterSegmentCenterRockers == InterSegmentStepsCount)
{
Report("Stop spray and center rockers",__FILE__,__LINE__,InterSegmentStepsCount,RpWarning,(int)lInterSegmentLength,0);
//IDS_Cleaning_Stop_Cleaning_Solution (callback_fptr callback);
//IDS_Cleaning_Center_And_Stop_Rockers (int timeout,callback_fptr callback);
}
}
if (InterSegmentStartWFCFDispensers == InterSegmentStepsCount)
{
Report("start dispensers at rate * WFCF",__FILE__,__LINE__,InterSegmentStepsCount,RpWarning,(int)lInterSegmentLength,0);
if (FileBrushStop)
{
REPORT_MSG(FileBrushStop->index,"WFCFBrushStopRead Index");
Dispensers = FileBrushStop->dispensers;
n_dispensers = FileBrushStop->n_dispensers;
if (n_dispensers)
{
for (Dispenser_i = 0; Dispenser_i < n_dispensers; Dispenser_i++)
{
DispenserId = Dispensers[Dispenser_i]->index;
HW_Motor_Id = DispenserIdToMotorId[DispenserId];
if (MotorsCfg[HW_Motor_Id].hardwaremotortype
!= DispenserIdToMotorId[DispenserId])
continue;
if ((DispenserId == CLEANER_DISPENSER)||(DispenserId == LUBRICANT_DISPENSER))
{
continue;
}
//(Speed*uStep*PPR)/((2*PI*Dispenser_Radius)
segmentfirst_speed = Dispensers[Dispenser_i]->nanolitterpersecond
/ Dispensers[Dispenser_i]->nanoliterperpulse;
if (Dispensers[Dispenser_i]->dispenserstepdivision
!= DISPENSER_STEP_DIVISION__Auto)
{
//MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
segmentfirst_speed /=
Dispensers[Dispenser_i]->dispenserstepdivision; //the dye supply is calculated based on a 1/8 microstep
IDS_Dispenser_Set_Flow_Params(
DispenserId, Dispensers[Dispenser_i]->nanoliterperpulse,
Dispensers[Dispenser_i]->dispenserstepdivision);
}
else
{
segmentfirst_speed/=8;//MotorsCfg[HW_Motor_Id].microstep; //the dye supply is calculated based on a 1/8 microstep
IDS_Dispenser_Set_Flow_Params(
DispenserId, Dispensers[Dispenser_i]->nanoliterperpulse,
MotorsCfg[HW_Motor_Id].microstep);
}
if ((int) segmentfirst_speed > 0)
{
segmentfirst_speed *= (100+WFCF);
segmentfirst_speed /= 100;
DispenserSegmentReady[DispenserId] = false;
//Control3WayValvesWithCallback (DispenserId, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer
IDS_Dispenser_Start_Motor_and_Open_Valve(DispenserId,
segmentfirst_speed,
NULL); usnprintf(IdsMessage, 80,
"WFCF Dispenser %d nl/sec %d nl/pulse %d speed %d",
DispenserId,
(int) Dispensers[Dispenser_i]->nanolitterpersecond,
(int) Dispensers[Dispenser_i]->nanoliterperpulse,
(int) segmentfirst_speed);
//REPORT_MSG(segmentfirst_speed,IdsMessage);
Report(IdsMessage, __FILE__, __LINE__, Dispenser_i, RpWarning, segmentfirst_speed, 0);
SendJobProgress(0.0, 0, false, IdsMessage);
}
}
}
}
//startDispensersAtSegmentSpeed*1=WFCFClenerSpray(speed);
}
return OK;
}
uint32_t IDSPreSegmentState(void *SegmentDetails, int SegmentId)
{
JobSegment* Segment = SegmentDetails;
JobDispenser **Dispensers;
//set the speed only before the first segment, speed is constant accros job
int Dispenser_i,n_dispensers,DispenserId;
TimerMotors_t HW_Motor_Id;
JobBrushStopId = 0;
// activate control fr all motors
/* wait for all dispensers to get to the required pressure
* move the presegment ready when all dispensers are ready.
*/
REPORT_MSG(SegmentId,"IDSPreSegmentState");
if (JobBrushStopId>=Segment->n_brushstops)
{
LOG_ERROR(Segment->n_brushstops,"Error JobBrushStopId");
JobEndReason = JOB_OUT_OF_DYE;
PreSegmentReady(Module_IDS,ModuleFail);
return ERROR;
}
if ((EnableIntersegment == true)&&(IntersegmentLength>0))
{
Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste); //if intersegment is defined throw the ink away
if (SegmentId>0)
{
lInterSegmentLength = ((IntersegmentLength*100)*1000/dyeingspeed);
lInterSegmentLength-=(lInterSegmentLength%100); //round to a 100 multiplication
InterSegmentStepsCount = 0;
DispenserPreSegmentControlId = AddControlCallback( IDSPreSegmentStateCallbackRunner, 100,TemplateDataReadCBFunction ,0, 0, 0 );
if (DispenserPreSegmentControlId == 0xFF)
{
Report("Add control callback failed",__FILE__,__LINE__,(int)100,RpWarning,(int)0,0);
return ERROR;
}
Report("Add control callback ",__FILE__,__LINE__,(int)100,RpWarning,(int)IntersegmentLength,0);
if (EnableCleaning == true)
{
InterSegmentStartSprayCleaner = 500;
InterSegmentStartRocking = 1000;
InterSegmentCenterRockers = 3000;
}
InterSegmentStartWFCFDispensers = lInterSegmentLength-5000;
}
}
if (uploadstrategy == JOB_UPLOAD_STRATEGY__Default)
{
Dispensers = Segment->brushstops[JobBrushStopId]->dispensers;
n_dispensers = Segment->brushstops[JobBrushStopId]->n_dispensers;
}
else
{
if (BrushStopControlId != 0xFF)
{
RemoveControlCallback(BrushStopControlId,IDSBrushStopRestartCallback);
BrushStopControlId = 0xFF;
}
FileBrushStop = GetNextBrushStopFromJobFile();
if (FileBrushStop)
{
REPORT_MSG(FileBrushStop->index,"BrushStopRead Index");
Dispensers = FileBrushStop->dispensers;
n_dispensers = FileBrushStop->n_dispensers;
}
else
{
LOG_ERROR(FileBrushStop,"BrushStopReadError");
JobEndReason = JOB_OUT_OF_DYE;
PreSegmentReady(Module_IDS,ModuleFail);
}
}
if (n_dispensers)
{
for (Dispenser_i = 0;Dispenser_i < n_dispensers;Dispenser_i++)
{
DispenserId = Dispensers[Dispenser_i]->index;
DispenserPreSegmentReady[DispenserId] = false;
}
for (Dispenser_i = 0;Dispenser_i < n_dispensers;Dispenser_i++)
{
DispenserId = Dispensers[Dispenser_i]->index;
HW_Motor_Id = DispenserIdToMotorId[DispenserId];
if (MotorsCfg[HW_Motor_Id].hardwaremotortype != DispenserIdToMotorId[DispenserId])//unconfigured dispenser
{
REPORT_MSG(DispenserId,"Dispenser PreSegment not configured");
DispenserPreSegmentReady[DispenserId] = true; //27/03/19 check if job should be stopped
IDS_Valve_PresegmentReady(DispenserId,0); //27/03/19 to be removed when the presegment handler will be added
continue;
}
if ((DispenserId == CLEANER_DISPENSER)||(DispenserId == LUBRICANT_DISPENSER))
{
REPORT_MSG(DispenserId,"Dispenser PreSegment cleaner or lubricant");
DispenserPreSegmentReady[DispenserId] = true; //27/03/19 check if job should be stopped
IDS_Valve_PresegmentReady(DispenserId,0); //27/03/19 to be removed when the presegment handler will be added
continue;
}
//REPORT_MSG(DispenserId,"IDS_Valve_Presegment start");
IDS_Dispenser_Set_Flow_Params(DispenserId,0,0);
if (Dispensers[Dispenser_i]->dispenserstepdivision != DISPENSER_STEP_DIVISION__Auto)
{
MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
}
else
{
MotorSetMicroStep(HW_Motor_Id, MotorsCfg[HW_Motor_Id].microstep);
}
if ((EnableIntersegment == true)&&(IntersegmentLength>0))
{
MotorStop(HW_Motor_Id,Hard_Hiz); //26/03/19 test without valves
CurrentDispenserSpeed[DispenserId] = 0;
DispenserPreSegmentReady[DispenserId] = true; //27/03/19 check if job should be stopped
REPORT_MSG(DispenserId,"Dispenser stopped pre Segment");
}
IDS_Valve_PresegmentReady(DispenserId,0); //27/03/19 to be removed when the presegment handler will be added
}
}
//Task_sleep(5);
return OK;
}
//********************************************************************************************************************
uint32_t SegmentNumOfBrushStops = 0;
double BrushStopTime = 0;
void IDS_StartBrushStop(int n_dispensers, JobDispenser** Dispensers)
{
int Dispenser_i,DispenserId;
TimerMotors_t HW_Motor_Id;
double segmentfirst_speed;
Report("IDS_StartBrushStop",__FILE__,__LINE__,(int)JobBrushStopId,RpWarning,(int)0,0);
if (n_dispensers)
{
for (Dispenser_i = 0; Dispenser_i < n_dispensers; Dispenser_i++)
{
DispenserId = Dispensers[Dispenser_i]->index;
HW_Motor_Id = DispenserIdToMotorId[DispenserId];
if (MotorsCfg[HW_Motor_Id].hardwaremotortype
!= DispenserIdToMotorId[DispenserId])
continue;
if ((DispenserId == CLEANER_DISPENSER)||(DispenserId == LUBRICANT_DISPENSER))
{
continue;
}
//(Speed*uStep*PPR)/((2*PI*Dispenser_Radius)
segmentfirst_speed = Dispensers[Dispenser_i]->nanolitterpersecond
/ Dispensers[Dispenser_i]->nanoliterperpulse;
if (Dispensers[Dispenser_i]->dispenserstepdivision
!= DISPENSER_STEP_DIVISION__Auto)
{
//MotorSetMicroStep(HW_Motor_Id, Dispensers[Dispenser_i]->dispenserstepdivision);
segmentfirst_speed /=
Dispensers[Dispenser_i]->dispenserstepdivision; //the dye supply is calculated based on a 1/8 microstep
IDS_Dispenser_Set_Flow_Params(
DispenserId, Dispensers[Dispenser_i]->nanoliterperpulse,
Dispensers[Dispenser_i]->dispenserstepdivision);
}
else
{
segmentfirst_speed/=8;//MotorsCfg[HW_Motor_Id].microstep; //the dye supply is calculated based on a 1/8 microstep
IDS_Dispenser_Set_Flow_Params(
DispenserId, Dispensers[Dispenser_i]->nanoliterperpulse,
MotorsCfg[HW_Motor_Id].microstep);
}
if ((int) segmentfirst_speed > 0)
{
DispenserSegmentReady[DispenserId] = false;
//Control3WayValvesWithCallback (DispenserId, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer
/*IDS_Dispenser_Start_Motor_and_Open_Valve(DispenserId,
segmentfirst_speed,
NULL);*/
Control3WayValvesWithCallback (DispenserId, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer
MotorSetSpeed(HW_Motor_Id, segmentfirst_speed);
CurrentDispenserSpeed[DispenserId] = segmentfirst_speed;
usnprintf(IdsMessage, 80,
"Dispenser %d nl/sec %d nl/pulse %d speed %d",
DispenserId,
(int) Dispensers[Dispenser_i]->nanolitterpersecond,
(int) Dispensers[Dispenser_i]->nanoliterperpulse,
(int) segmentfirst_speed);
//REPORT_MSG(segmentfirst_speed,IdsMessage);
Report(IdsMessage, __FILE__, __LINE__, Dispenser_i, RpWarning, segmentfirst_speed, 0);
SendJobProgress(0.0, 0, false, IdsMessage);
}
else
{
DispenserSegmentReady[DispenserId] = true;
//IDS_Dispenser_Close_Valve_And_Stop_Motor(DispenserId,NULL);*/
MotorStop(HW_Motor_Id, Hard_Hiz);
CurrentDispenserSpeed[DispenserId] = 0;
Report("inActive dispenser stopped", __FILE__, __LINE__, DispenserId, RpWarning, segmentfirst_speed, 0);
}
}
}
}
uint32_t IDSBrushStopRestartCallback(uint32_t IfIndex, uint32_t readValue)
{
JobDispenser **Dispensers = NULL;
int n_dispensers = 0;
JobSegment* Segment = (void *)IfIndex;
if (uploadstrategy == JOB_UPLOAD_STRATEGY__Default)
{
Dispensers = Segment->brushstops[JobBrushStopId]->dispensers;
n_dispensers = Segment->brushstops[JobBrushStopId]->n_dispensers;
}
else
{
if (FileBrushStop)
FreeBrushStopFileData(FileBrushStop);
FileBrushStop = GetNextBrushStopFromJobFile();
if (FileBrushStop)
{
REPORT_MSG(FileBrushStop->index,"BrushStopRead Index");
Dispensers = FileBrushStop->dispensers;
n_dispensers = FileBrushStop->n_dispensers;
}
else
{
LOG_ERROR(FileBrushStop,"BrushStopReadError");
JobEndReason = JOB_OUT_OF_DYE;
SegmentReady(Module_IDS,ModuleFail);
}
}
if (n_dispensers)
{
IDS_StartBrushStop(n_dispensers, Dispensers);
}
JobBrushStopId++;
Report("brushstop",__FILE__,__LINE__,(int)JobBrushStopId,RpWarning,(int)SegmentNumOfBrushStops,0);
if (JobBrushStopId >= SegmentNumOfBrushStops)
{
Report("last brushstop",__FILE__,__LINE__,(int)JobBrushStopId,RpWarning,(int)SegmentNumOfBrushStops,0);
SafeRemoveControlCallback(BrushStopControlId,IDSBrushStopRestartCallback);
BrushStopControlId = 0Xff;
}
return OK;
}
//********************************************************************************************************************
uint32_t IDSSegmentState(void *SegmentDetails, int SegmentId)
{
JobSegment* Segment = SegmentDetails;
JobDispenser **Dispensers;
int n_dispensers;
Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Head);
SegmentNumOfBrushStops = Segment->n_brushstops;
BrushStopTime = Segment->length/SegmentNumOfBrushStops; //brushstop in meters
BrushStopTime = ((BrushStopTime*100)/dyeingspeed);//brushstop in seconds
BrushStopTime *= 1000; //brushstop in millisecond
Report("IDSSegmentState",__FILE__,__LINE__,(int)BrushStopTime,RpWarning,(int)SegmentNumOfBrushStops,0);
if (uploadstrategy == JOB_UPLOAD_STRATEGY__Default)
{
Dispensers = Segment->brushstops[JobBrushStopId]->dispensers;
n_dispensers = Segment->brushstops[JobBrushStopId]->n_dispensers;
}
else
{
if (FileBrushStop)
{
Dispensers = FileBrushStop->dispensers;
n_dispensers = FileBrushStop->n_dispensers;
}
else
{
LOG_ERROR(FileBrushStop,"BrushStopReadError");
}
}
IDS_StartBrushStop(n_dispensers, Dispensers);
JobBrushStopId++;
if ((BrushStopTime)&&(SegmentNumOfBrushStops > 1))
{
BrushStopControlId = AddControlCallback( IDSBrushStopRestartCallback, BrushStopTime,TemplateDataReadCBFunction ,SegmentDetails, 0, 0 );
if (BrushStopControlId == 0xFF)
{
Report("Add control callback failed",__FILE__,__LINE__,(int)BrushStopTime,RpWarning,(int)0,0);
return ERROR;
}
Report("Add control callback ",__FILE__,__LINE__,(int)BrushStopTime,RpWarning,(int)n_dispensers,0);
}
else
{
if (FileBrushStop)
FreeBrushStopFileData(FileBrushStop);
FileBrushStop = NULL;
}
return OK;
}
//********************************************************************************************************************
uint32_t IDS_Valve_DistanceToSpoolValveReady(uint32_t deviceID, uint32_t ReadValue)
{
//TimerMotors_t HW_Motor_Id = DispenserIdToMotorId[deviceID];
//MotorStop(HW_Motor_Id,Hard_Hiz);
//REPORT_MSG(deviceID,"Dispenser DTS called");
IDS_Valve_DistanceToSpoolReady( deviceID, ReadValue);
return OK;
}
//********************************************************************************************************************
uint32_t IDS_Valve_DistanceToSpoolReady(uint32_t deviceID, uint32_t ReadValue)
{
int i;
DispenserDistanceToSpoolReady[deviceID] = true;
for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
{
if (DispenserDistanceToSpoolReady[i] == false)
{
return OK; //not all configured heaters are ready
}
}
REPORT_MSG(deviceID,"IDS_Valve_DistanceToSpoolReady End called");
DistanceToSpoolReady(Module_IDS,ModuleDone);
return OK; // all configured heaters are ready
}
//********************************************************************************************************************
uint32_t IDSDistanceToSpoolState(void)
{
int Dispenser_i;
REPORT_MSG(100,"Dispenser DTS");
Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste); //#bug 323
for (Dispenser_i = 0;Dispenser_i < MAX_SYSTEM_DISPENSERS;Dispenser_i++)
{
if (DispenserUsedInJob[Dispenser_i]==false)//unconfigured dispenser
continue;
DispenserDistanceToSpoolReady[Dispenser_i] = false;
IDS_Dispenser_Set_Flow_Params(Dispenser_i,0,0);
//MotorStop(HW_Motor_Id,Hard_Hiz);
//Control3WayValvesWithCallback ((Valves_t)Dispenser_i, MidTank_Dispenser, IDS_Valve_DistanceToSpoolValveReady); //direction: MidTank_Dispenser or Dispenser_Mixer
IDS_Dispenser_Close_Valve_And_Stop_Motor(Dispenser_i,IDS_Valve_DistanceToSpoolValveReady);
}
return OK;
}
//********************************************************************************************************************
uint32_t IDS_Valve_EndValveReady(uint32_t deviceID, uint32_t ReadValue)
{
//TimerMotors_t HW_Motor_Id = DispenserIdToMotorId[deviceID];
//REPORT_MSG(deviceID,"Dispenser End called");
//MotorStop(HW_Motor_Id,Hard_Hiz);
//IDS_HomeDispenser (deviceID, 800 , NULL);
return OK;
}
//********************************************************************************************************************
uint32_t IDSEndState(void )
{
int Dispenser_i;
IDS_Active = false;
Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste);
REPORT_MSG(0,"Dispenser End Start");
if (BrushStopControlId != 0xFF)
{
RemoveControlCallback(BrushStopControlId,IDSBrushStopRestartCallback);
BrushStopControlId = 0xFF;
}
if (FileBrushStop)
FreeBrushStopFileData(FileBrushStop);
FileBrushStop = NULL;
for ( Dispenser_i = 0;Dispenser_i < MAX_SYSTEM_DISPENSERS;Dispenser_i++)
{
if (DispenserUsedInJob[Dispenser_i] == true)
{
//MotorStop(DispenserIdToMotorId[Dispenser_i],Hard_Hiz);
//Control3WayValvesWithCallback (Dispenser_i, MidTank_Dispenser, IDS_Valve_EndValveReady); //direction: MidTank_Dispenser or Dispenser_Mixer
IDS_Dispenser_Close_Valve_And_Stop_Motor(Dispenser_i,IDS_Valve_EndValveReady);
IDS_Dispenser_Set_Flow_Params(Dispenser_i,0,0);
}
else
{
IDS_Valve_EndValveReady(Dispenser_i,false);
}
}
IDS_StopLubrication();
return OK;
}
uint32_t IDS_StartLubrication(void)
{
IDS_Dispenser_Start_Motor_and_Open_Valve(LUBRICANT_DISPENSER,lubricant_speed,NULL);
CurrentDispenserSpeed[LUBRICANT_DISPENSER] = lubricant_speed;
REPORT_MSG (lubricant_speed, "IDS_StartLubrication");
Lubricant_2Way_Valve (START);
return OK;
}
uint32_t IDS_StopLubrication(void)
{
IDS_Dispenser_Close_Valve_And_Stop_Motor(LUBRICANT_DISPENSER,IDS_Valve_EndValveReady);
CurrentDispenserSpeed[LUBRICANT_DISPENSER] = 0;
REPORT_MSG (lubricant_speed, "IDS_StopLubrication");
Lubricant_2Way_Valve (STOP);
return OK;
}
|