Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by Dunning-Kruger!

Moving Average Array Error

Hello,

I'm getting this error "Error on line 19: Variable is an array: $MvAvgTouch".

I'm trying to smooth out all the noise coming in from my ADC0 from my graphite sensor I have going to the digital and vcc pin of the ADC0 port. It fluctuates +-100 units.

I'm making a biped lift it's feet above an object when it kicks into something unmovable.

My line 19 is:

Code:


$AvgTouch=($MvAvgTouch[1]+$MvAvgTouch[2]+$MvAvgTouch[3]+$MvAvgTouch[4]+$MvAvgTouch[5]+$MvAvgTouch[6]+$MvAvgTouch[7]+$MvAvgTouch[8]+$MvAvgTouch[9]+$MvAvgTouch[10])/10


Code:

 
$S1Back=85
$S2Back=85
DefineArray( $MvAvgTouch, 15, 1 )
#$MvAvgTouch[0]=0
$AvgTouch=0
$n=0
Servo(D0, $S1Back)
sleep(1000)
Servo(D1, $S2Back)
$Touch=0
:Top
$Touch=GetADC(adc0)
$n=$n+1
$MvAvgTouch[$n]=$Touch
if ($n>10)
$n=0
EndIf

$AvgTouch=($MvAvgTouch[1]+$MvAvgTouch[2]+$MvAvgTouch[3]+$MvAvgTouch[4]+$MvAvgTouch[5]+$MvAvgTouch[6]+$MvAvgTouch[7]+$MvAvgTouch[8]+$MvAvgTouch[9]+$MvAvgTouch[10])/10

sleep(100)

if ($Touch>220)
$S1Back=$S1Back+5
$S2Back=$S2Back+5
print($Touch)
Servo(D0, $S1Back)
sleep(500)
Servo(D1, $S2Back)
EndIf

if ($Touch95)
$S1Back=$S1Back-5
$S2Back=$S2Back+5
#print($Touch)
Servo(D0, $S1Back)
sleep(500)
Servo(D1, $S2Back)
if ($S2Back>35)
goto(Over)
EndIf
EndIf
goto(Top)

:Over

$Touch=GetADC(adc0)
sleep(100)

if ($Touch<220)
$S1Back=$S1Back+5
$S2Back=$S2Back-5
print($Touch)
Servo(D0, $S1Back)
sleep(500)
Servo(D1, $S2Back)
EndIf

goto(Over)



Thanks much,

Bill

#2  
Thanks Richard,

Sorry I waited so long to mark this as resolved but I thought there would have been another solution.

I will make a feature request to do array addition and division so I'll be able to do DSP for things like vibration signature analysis to test faulty metal parts.

I suspect it's probably a little late in the game now, but here's a very well developed open source programming language we could be customized for robotics:
http://ahkscript.org/

All the best,

Bill
#3  
Hi DJ,

Thanks for your efforts but I replicated your code and the error persists with the 04.04.2015 update. I've attached a screen shot with the code and the error which might be helpful in solving this one.

User-inserted image



Cheers,

Bill
PRO
Synthiam
#4  
I do not believe you have updated... this works as expected....

Code:


definearray($array, 10, 1)

$array[1] = 3

$answer = ($array[0] + $array[1] + $array[2]) / 2

print($answer)


And I also tried it with this..

Code:


definearray($MvAvgTouch, 11, 1)

$MvAvgTouch[1] = 3

$AvgTouch = ($MvAvgTouch[1] + $MvAvgTouch[2] + $MvAvgTouch[3] + $MvAvgTouch[4] + $MvAvgTouch[5] + $MvAvgTouch[6] + $MvAvgTouch[7] +$MvAvgTouch[8] + $MvAvgTouch[9] + $MvAvgTouch[10])/10

print($AvgTouch)
#5  
Excellent DJ!

Thanks so much for the quick fix. It's working perfectly now.

BTW that's a very powerful feature for the com port readers also. I've been reeling with ideas.:)

Best,

Bill