Ultrasonic 3D Scanner – Informatie en onderdelen
Ultrasonic 3D Scanner
Informatie (ENG):
A small XY-moveable Scanner to create a (low detailed) 3D Picture of your environment.
Movement is done with 2x “Servo 9g”.
The sensor is an “HC-SR04”.
Next step will be to create the electronics and the display…
Edit: Added a very first picture of a scan. The scan is of course (like expected) low detailed, but you can see the shape of the bottle. I have some ideas to improve the quality, but for now I have to go on and do some other stuff. Maybe I will work again on it in some weeks.
Edit 2: Added the SourceCode for the ATMega8, which is sending the data to its UART with 250kbit/s, 8bit Data, no partity.
Additionally there is a “PHP” file which converts the LOG-Files to PNG.
PLEASE NOTE: This is only a quick and dirty hack, just to see if it the idea, that I had is realizable.
Scripts
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 |
/* * _3D_Scanner_Mega8.c * * Created: 23.06.2015 18:38:27 * Author: pyromaniac */ #define F_CPU 8000000UL #include <stdio.h> #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> char stop = 1; // start/stop => sending 's' in terminal (250kbit, 8bit, no parity) /* PORT C.5 => Ultrasonic Trigger PORT C.4 => Ultrasonic Echo PORT B.0 => ServoMotor Vertikal PORT B.1 => ServoMotor Horizontal */ void USART_Transmit( unsigned char data ); ISR(USART_RXC_vect) { char c = UDR; if (c == 's') stop = (stop + 1) & 0x01; USART_Transmit (c); } void warte(int x) { x = x / 1.9; while (x--) _delay_us(1); } int US_Messen() { unsigned int max_us_time = 3000; unsigned int time = max_us_time; PORTC = 0x20; _delay_ms(10); PORTC = 0x00; while (!(PINC & 0x10)); while ((PINC & 0x10) && time) { time--; //_delay_us(0.1); } return max_us_time-time; } void USART_Transmit( unsigned char data ) { while (!(UCSRA & (1<<UDRE))); UDR = data; } void serial_send_str( const char *s ) { while (*s != 0) { while (!(UCSRA & (1<<UDRE))); UDR = *s++; } } void init_serial( void ) { UBRRL = 1; // 250kbit @ 8Mhz CPU_CLK UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE); UCSRC = (1 << URSEL) | (3 << UCSZ0); } void set_position ( int x, int y ) { int xdelay = 1500; int ydelay = 1500; PORTB = 0x01; warte(ydelay + y); PORTB = 0x00; warte(3000 - ydelay + y); PORTB = 0x02; warte(xdelay + x); PORTB = 0x00; warte(3000 - xdelay + x); } void init_adc() { ADMUX = (1 << REFS0) | (3 << MUX0); // Ref = AVCC; ADC3; ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADFR) | (3 << ADPS0); } int IR_messen() { return ADC; } int main( void ) { const char mode = 0; // mode 0 => Ultraschall; 1 => Infrarot; int dist = 0; char buf[64]; DDRC = 0b00100000; // Ultraschall + LED DDRB = 0b00000011; // Servo-Motoren init_serial(); init_adc(); sei(); sprintf(buf, "Starting...\n\r"); serial_send_str(buf); while(1) { for (int y = 300; y <= 1100; y += 10) { for (int x = -1000; x <= 1000; x += 20) { while (stop) set_position(x, y); set_position(x, y); if (mode == 0) dist = US_Messen(); if (mode == 1) dist = IR_messen(); //sprintf(buf, "X: %d; Y: %d; D: %u;\n\r", x, y, dist); sprintf(buf, "0X%04X,", dist); serial_send_str(buf); } for (int z = 0; z < 100; z++) set_position(-1000, y); } stop = 1; } } |
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 |
<?php $width = 100; $height = 80; $name = "putty1_01.log"; $ascii_content = file_get_contents($name); for ($y = 0; $y < $height; $y++) for ($x = 0; $x < $width; $x++) { $content[$x][$y] = hexdec(substr($ascii_content, $x * 7 + 2 + ($y * ($width + 1) * 7), 4)) / 2; //echo substr($ascii_content, $x * 7 + 2, 4)." "; //echo $content[$x][$y]." "; } //exit; header ('Content-Type: image/png'); $im = @imagecreatetruecolor($width, $height) or die('Cannot Initialize new GD image stream'); for ($y = 0; $y < $height; $y++) for ($x = 0; $x < $width; $x++) { $col = imagecolorallocate ($im, $content[$x][$y], 0, 0); imagesetpixel ($im, $x, $y, $col); } imagepng($im); imagedestroy($im); ?> |
Download Ultrasonic 3D scanner @ Thingiverse
[#/3dscanner/ultrasonic3dscanner/onderdelen/ultrasonic3dscanner” ]