Pages: 1 [2]   Go Down
Author Topic: 3D Scanner with 2 RC Servos and a distance Sensor  (Read 5328 times)
0 Members and 1 Guest are viewing this topic.
The Big Smoke
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
Hacking and Slashing
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey designer.

I wonder if you could help me, I'm thinking of extending your work with the scanner. I've been reading up on polar coordinates and I just wanted to understand how produce a 3d image.


From my understanding the scanner is at point 0, everything else is relative to the servos and distance.

When you convert to cartesian coordinates, again, they are relative. so you may have a -10, -10 (for example) where 0,0 is your scanner.

I dont know [anything] much about Mesh (or any other 3d rendering software), but from the tech specs, you just feed it a collection of cartesian readings in the right format and it'll render the result - leaving you to "clean up" the image.

Any guidance would be highly appreciated!
Logged

Atascadero, CA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 468
Arduino addict
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if for example you always move the scanner exactly 2m forward you can take that into account as an offset during the polar/cartesian conversion.
You could use a wheel with a 1m (or any known) circumference and a rotation sensor so that the code calculates the distance for you.  In fact, you could even make the scanner head rotate 360 degrees one rotation and then back and have it log a zig-zag helical scan of sorts.  As long as you know the traveled distance in relation to the scan head angular movement, you can calculate the 3D space.

This would give you a straight-but-bumpy map of the cave.  You would need to measure ahead and behind some distance so you could detect and calculate turns and other directional changes.
Logged

What about elevensies? Luncheon? Afternoon tea? Dinner? Supper?

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thats my way of getting a image:

lets just look it up for 1 point (Code is VB.net)

1.) Origin.

the rotationpoint from the pan-servo is 0,0,0 (X,Y,Z) or 0,0(R,Angle)

2.) Where´s your scanned point.

for example the pan servo is at 50° and the tilt servo at 30°. your reading a analog value of lets say 100.

so first convert the analog value to distance:

Code:
   Public Function ADWtoDist(ByVal ADW As Integer) As String

        'If the Value is smaller as 38, the result would be biger as 300cm, what makes no sense.
        If ADW < 38 Then ADW = 38

        ADWtoDist = 10565 * ADW ^ -0.982

        'Debug.Print("Dist: " & ADWtoDist & " cm")
    End Function

3.) then we convert the polar coordinates into cartesian:

Basics: http://www.euclideanspace.com/maths/geometry/space/coordinates/polar/index.htm

in Code it looks like this:

Code:
Public Function PolarToCartesian(ByVal TiltAngle As Double, ByVal PanAngle As Double, ByVal R As Double) As Array

        'This will be 1=X,2=Y,3=Z
        Dim Result(3) As Double

        'Basic: http://www.euclideanspace.com/maths/geometry/space/coordinates/polar/index.htm
        ' x = r sin(a1) cos(a2)
        ' y = r sin(a1) sin(a2)
        ' z = r cos(a1)
        '
        'Where a1 = TiltAngle, a2 = PanAngle, r = R

        'All Angles must be Radians, and they must be 0-180, not 0-155

        TiltAngle = TiltAngle * 180 / 155
        PanAngle = PanAngle * 180 / 155

        TiltAngle = Math.PI * TiltAngle / 180.0
        PanAngle = Math.PI * PanAngle / 180.0

        'Now they can be calculatet:

        Result(1) = (R * Sin(TiltAngle) * Cos(PanAngle)) + TextBox1.Text
        Result(2) = (R * Sin(TiltAngle) * Sin(PanAngle)) + TextBox2.Text
        Result(3) = R * Cos(TiltAngle)

        Return Result

    End Function

the 0-155 to 1-180 conversion comes from my servos, if you move them from 0-155 they make already 0-180 degrees...  :smiley

4.) And know this must be saved into a file!

Easiest format is obj: http://en.wikipedia.org/wiki/Obj

example file from my scan:
Code:
v 31.9121705541201 33.5715843563032 17.1546264824741
v 33.984405250283 35.7515740185642 17.1399861761586
v 36.1267443214351 38.0053134414284 17.037524539716
v 32.3026021291672 33.9823181399808 14.1901570731361
v 32.4941081567727 34.1837823666023 13.2370150128776
v 32.8076369704424 34.5136144912581 12.3293085742347
v 32.8370021129878 34.544506603671 11.3148117078009
v 32.4527234486948 34.1402456784305 10.1785760817876

to do that in Code:

Code:
 
            Dim Cartesian(3) As Double

            Cartesian = PolarToCartesian(Tilt, Pan, Dist)

            Dim OutStr, OutStr2, X, Y, Z, As String

            OutStr = Nothing

            X = Replace(Cartesian(1).ToString, ",", ".")
            Y = Replace(Cartesian(2).ToString, ",", ".")
            Z = Replace(Cartesian(3).ToString, ",", ".")

            'This is the obj String:

            OutStr2 = "v " & X & " " & Y & " " & Z & vbCrLf

            RichTextBox2.AppendText(OutStr2)

5.) and at the end of a scan save it to a .obj file:


Code:
RichTextBox2.SaveFile("N:\Programme\Meshlab\ArduinoScan.obj", RichTextBoxStreamType.PlainText)

now just open this .obj file in Meshlab, and your ready to run  smiley

6.) Meshlab

look here: http://philohome.com/scan3d/scan3d.htm

under "3D reconstruction" theres a perfect description on how to use Meshlab!

designer2k2
« Last Edit: April 18, 2009, 06:03:49 am by designer2k2 » Logged


The Big Smoke
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
Hacking and Slashing
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah thats fantastic, I'll give that a go as soon as I recieve my measurer.

Thanks a lot, I'll let you know my results smiley
Logged

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

somebody has taken this to the extreme: http://pruned.blogspot.com/2010/02/mapping-abysses.html



very cool stuff  8-)
Logged


The Big Smoke
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
Hacking and Slashing
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's amazing, I'd love to the see the environmental re-mapping process
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, what a coinsidence it is, I'v just had the same idea sience last night, when I told my friend I want to build a thing for scanning in a dark room and realizing a 3D map of that.

I never thought there would be a trailblazer on the other side of world:). Anyway, I think it is very insteresting, and I sincerely wish u acquiring a perfect success!!
Logged

Pages: 1 [2]   Go Up
Jump to: