-
Final
01/09/2018 at 13:00 • 0 commentsFinal
Here is the arduino code:
/* Little Monster Scanner ====================== Written by Alan Cooper (agp.cooper@gmail.com) This work is licensed under the Creative Commons Attribution - Non Commercial 2.5 License. This means you are free to copy and share the code (but not to sell it). Also it is good karma to attribute the source of the code. */ #define DirX 2 // Reserved for Head 1 #define DirY 3 // Reserved for Head 2 #define DirZ 4 // Scanner #define StepX 5 // Reserved for Head 1 #define StepY 6 // Reserved for Head 2 #define StepZ 7 // Scanner #define Enable 8 // Enable all stepper motors (active LOW) #define Sensor1 A4 // SE-10 PIR Scanner (active LOW) #define Sensor2 A5 // Reserved for RCWL-0516 (active LOW) #define N 19 // Sample array size volatile bool scanDone=false; volatile byte forwardScan[N]; volatile byte reverseScan[N]; volatile unsigned int magic=0; volatile int dirFlag=0; volatile int stepCount=1200+80; // Offset for sensor zero (+4.5 degrees) volatile int stepTrip=2400; // +/-60 degrees (400 step motor and 1/16 mircosteps) volatile int index=0; // Used to save data to an array ISR(TIMER2_OVF_vect) { static unsigned int phase=0; if (phase<0x8000) { phase+=magic; if (phase>=0x8000) { digitalWrite(StepZ,LOW); } } else { phase+=magic; if (phase<0x8000) { digitalWrite(StepZ,HIGH); stepCount++; index=(stepCount>>7); // 0 to N-1 if (dirFlag==0) { if (digitalRead(Sensor1)==LOW) { forwardScan[index]=1; } else { forwardScan[index]=0; } } else { if (digitalRead(Sensor1)==LOW) { reverseScan[N-1-index]=1; } else { reverseScan[N-1-index]=0; } } if (stepCount>stepTrip) { stepCount=0; dirFlag=1-dirFlag; if (dirFlag==1) { digitalWrite(DirZ,HIGH); } else { digitalWrite(DirZ,LOW); } scanDone=true; } } } } void setup() { // LED pinMode(LED_BUILTIN,OUTPUT); pinMode(DirZ,OUTPUT); pinMode(StepZ,OUTPUT); pinMode(Enable,OUTPUT); pinMode(Sensor1,INPUT_PULLUP); // Sensor1 is open collector digitalWrite(LED_BUILTIN,HIGH); // Off digitalWrite(DirZ,LOW); digitalWrite(StepZ,LOW); digitalWrite(Enable,LOW); // On // Use Timer 2 for ISR // Good for ATmega48A/PA/88A/PA/168A/PA/328/P cli(); TIMSK2=0; // Clear timer interrupts TCCR2A=(0<<COM2A0)|(0<<COM2B0)|(3<<WGM20); // Fast PWM TCCR2B=(1<<WGM22)|(2<<CS20); // 2 MHz clock and (Mode 7) OCR2A=243; // Set for 8197 Hz OCR2B=121; // PWM 50% - Not used TIMSK2=(1<<TOIE2)|(0<<OCIE2A)|(0<<OCIE2B); // Set interrupts sei(); Serial.begin(9600); delay(200); // Pause to align scanner Serial.println("Little Monster Scanner V1.0"); Serial.flush(); Serial.println("Waiting 10s for alignment of scanner"); Serial.flush(); delay(10000); // Update frequency without interrupt (Note frequency should be between 1 and 4095) unsigned int freq=400; // Using 400 step motor and 1/16 microsteps cli(); magic=(freq<<3); sei(); } void loop() { int i,tmp,cnt,mean; if (scanDone) { scanDone=false; mean=0; cnt=0; for(i=0;i<N;i++) { tmp=reverseScan[i]+forwardScan[i]; mean+=i*tmp; cnt=cnt+tmp; } if (cnt>0) { mean=mean/cnt; } else { mean=N/2; } for(i=0;i<mean;i++) Serial.print('.'); if (cnt>0) { Serial.print('*'); } else { Serial.print(':'); } for(i=mean+1;i<N;i++) Serial.print('.'); Serial.println(); } }
An ISR runs the stepper motor and the mean uses forward and reverse scans.
Here is me sitting in my partners chair:
Little Monster Scanner V1.0 Waiting 10s for alignment of scanner .........:......... .........:......... .........:......... .........:......... Behind scanner (no signal) ...........*....... Walking to seat (crossing scanner path) .........*......... Seated (scanner centred on seat) .........*......... Seated (scanner centred on seat) .........*......... Seated (scanner centred on seat) ........*.......... Walking left of scanner ........*.......... Wakling left of scanner .........:......... Behind scanner (no signal) .........:......... .........:.........
So it is now ready (except for the controller box) to drive some spooky head(s).
AlanX
-
First Set of Results
01/09/2018 at 07:36 • 0 commentsResults
Set the scanner for 90 degree scan, 2 seconds per pass and 13 samples per pass.
Little Monster Scanner V1.0 Waiting 10s for alignment of scanner R Scan: L Scan: .....*.**.**. R Scan:.......*.**.. L Scan: ...*.*.**.**. R Scan:.......*.**.. L Scan: ...*.*.**.**. R Scan:.......*.**.. L Scan: .....****.**. R Scan:.......*.**.. L Scan: ....*****.**. R Scan:.......*.**.. L Scan: ...*.****.**. R Scan:.......*.**.. L Scan: ....*****.**. R Scan:.......*.**.. L Scan: ...*.****.**. R Scan:.......*.**.. L Scan: ...*.****.**. R Scan:.......*.**.. L Scan: ....*****.**. R Scan:.......*.**.. L Scan: ....*****.**. R Scan:.......*.**.. L Scan: ....*****.**. R Scan:.......*.**.. L Scan: ........**.*. R Scan:.......*..**. L Scan: .....**.**.*. R Scan:.......*..**. L Scan: ....*****..*. R Scan:.......*..*.. L Scan: ....*****..*. R Scan:.......*..*.. L Scan: ....*****..*. R Scan:.......*..*.. L Scan: ....*****..*. R Scan:.......*.**.. L Scan: ....*****..*. R Scan:.......*..*.. L Scan: ....*****..*. R Scan:.......*..*..
The stars (*) are me sitting about 0.8 m away to the right of centre of the scanner. There is a distinct lag in the data but what is remarkable is how regular the scan pattern is.
Here I am 3 m away from the scanner:
L Scan: ............. R Scan: ............. L Scan: ..***.*...... Me R Scan: ..*...**..*** Me and dog L Scan: .*.*.*....*.. Me and dog R Scan: ..**...*..*.* Me and dog L Scan: ...*.*.*.**.. Me and dog R Scan: ..**...*..*** Me and dog L Scan: .*****...*... Me and dog R Scan: ..**.***..*** Me and dog L Scan: .*****...**.. Me and dog R Scan: ..**..*...... Me L Scan: .*****....... Me R Scan: ..**..*...... Me L Scan: .*****....... Me R Scan: ..**.***..*** Me and dog L Scan: .*****...**.. Me and dog R Scan: ..**.***..*** Me and dog L Scan: .*****...**.. Me and dog R Scan: ..**.***..... Me L Scan: **.****...... Me R Scan: ..**.***..... Me L Scan: **.****...... Me R Scan: ..**.***..... Me L Scan: .****.*...... Me R Scan: ..**.***..*** Me and dog L Scan: .*****...*... Me and dog R Scan: ..**..*...... Me L Scan: .*****....... Me R Scan: ..**......... Me L Scan: ............. R Scan: .............
On the right hand side (the last four samples) is the response from my dog moving in and out of the scene! So a pretty good result.
Improvements
As I present a response of about 6 samples at 3 m (~40 degrees), clearly the scan is too wide (i.e. too fast?). I should be presenting about 3 samples at this distance.
Second Pass
Made three modifications:
- Increased the scan to +/-60 degrees (19 samples)
- Reduced the speed to 3.75 RPM (6 seconds per span pass)
- Offset the results 1 sample
Little Monster Scanner V1.0 Waiting 10s for alignment of scanner >> << ..........**....... >> ..........*........ << ........*.**....... >> ..........*........ << ........*.**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*.*...... << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> ..........*........ << ..........**....... >> .........**........ << ..........**....... >> ..........*........ << ..........**....... >> .........**........ << ..........**....... >> .........**........ << ..........**....... >> ..........*........ << ..........**.......
This my partner sitting in a chair about 3 m away. No signal if she is not in the chair. Well that seems to work fine.
AlanX
-
Scanner Base
01/09/2018 at 01:53 • 0 commentsMounting the Motor and Electronics
Here is the motor mount and electronics box:
The sensor cable needs to be replaced with something longer and more flexible and my box-bolts are not long enough.
Here is the inside:
I have used an off the self CNC board and I need to "bend" the stepper plug to fit inside the box. The CNC board is over-kill but it was sitting around unused.
One fault with these boards is that the shunts to control the micro stepping does not work. I added these 10k pull-ups to fix the problem:
I have ordered longer bolts for the box but some strong rubber-bands may suffice in the mean time. I have a new idea for holding these boxed together that I might try.
Scanning
At the moment the idea for the scanner is to do a left and right pass (~2 seconds) and then to point at the LM for say 10 to 15 seconds, then repeat. This will require some optimisation for the best effect. Now the "head" that looks at the LM need not be the scanner! As there are two free stepper drivers I could have two heads looking at the LM. Extra spooky!
AlanX
-
The Scanner Box
01/09/2018 at 01:27 • 0 commentsA Narrow Scan PIR
The PIR datasheet (and bandpass of the electronics) indicate that the sensor will respond to signals up to about 10 Hz but at reduced sensitivity. Therefore scanning for "Little Monsters" (LMs) is feasible.
The next step is to consider a suitable narrow beam "lens". After much research the lens became a vertical slot. The slot is designed for an apperture of 10 to 15 degrees horizontally and 30 to 40 degrees vertically:
Here is the SE-10 mounted inside the box:
The initial testing worked great:
- The sensor appertured appeared to be about right.
- The sensor did not react to very slow LM movements (i.e. tippy-toe) across the apperture.
- Responded with a dual pulses for slow LM movements entering and leaving the apperture.
- Responded with a single pulse when leaving the apperture for fast movements.
Without a suitable motor base, the sensor moves too much when scanning but it was clear that "fast" scanning works.
AlanX