Hi, i am fairly new til Kuka and i am trying to write a function in the robot that will take "samples" of a sensor input and avg it out afterwords.
I have marked the Input i would like to get updated in every "loop cycle" of the FOR loop with RED
The Controller is KRC5
Robot: KR70
WorkVisual: 6.0.29
the Codes is this:
DEF Measure_Sampling (Samples:IN , rSampleTime:IN , rInput :IN , rCalValue:IN , rOutput:OUT )
;-----------------------;
; Declarations ;
;-----------------------;
DECL INT Samples ;Amount of desired samples
DECL INT N1 ;For Loop Interpretor
DECL REAL SamplesReal ;Amount of desired samples as REAL for Math
DECL REAL rInput ;Input signal in REAL
DECL REAL rSampleBuffer ;Temp buffer for calculation
DECL REAL rSampleTime ;Sample time pr sample SEC
DECL REAL rCalValue ;Calibration Value Input
DECL REAL rOutput ;Result
;-----------------------;
; Function ;
;-----------------------;
rSampleBuffer = 0 ;Reset Sample Buffer
SamplesReal = Samples
WAIT FOR $ROB_STOPPED
WAIT SEC 0.1
FOR N1 = 1 TO Samples
rSampleBuffer = rSampleBuffer + rInput
WAIT SEC rSampleTime
ENDFOR
WAIT SEC 0.1
rOutput = ((rSampleBuffer / SamplesReal) + rCalValue ) ;Output
WAIT FOR TRUE
END
Thanks in Advance