Dear DAVID Community,

As you are probably aware, the entire DAVID company, team and product range has been integrated into HP Inc.
This forum is now read-only. Relevant content has been migrated to HP and merged into HP's Support Forums on November 1, 2016.

To start new discussions for 3D Scanning, please register and post your new topic at the HP Support Forums

Automated 360° Turntable Code

Problems, solutions and discussion about scanning with a video projector and stripe patterns.

Automated 360° Turntable Code

Postby MagWeb » Thu Feb 06, 2014 9:52 pm

Hi,

here's a possible code snippet for an Arduino controlled turntable. In this case the Arduino uses an AdafruitMotorShield to drive the stepper.
Should be easy to port this to any driver library of your hardware.

The trick is to enable DAVIDs AddScanToList functionality. DAVID sends a "T" to show its state of being ready with scanning and after passing the scan to Shapefusion (with or without aligning) DAVID sends a fresh "S" message which can be used to trigger the next scan....

This means you can get the full round with a single click without loosing some time!

Code: Select all
// Simple Code to do a 360° turntable SL-scan with DAVIDs COM dialog enabled
// Written by MagWeb for DAVID3.10 - 06.02.2014
// This snippet is based on the Adafruit Motor shield library but should be portable to any stepper driver library
//
// The trick is to use DAVID'S automatic "AddToList" funktionality which makes DAVID send a "ready to scan" message after a previous scan:

#include <AFMotor.h> // This is needed for my Adafruit MotorShield on the Arduino

AF_Stepper motor(200, 2); // This is needed for my Adafruit MotorShield on the Arduino
int val; //Variable to store the content of the COM port
int count = 0; // Variable to count the scans
int limit = 10; // Means the number of scans/round
int StepsPerRound = 20000;  // Depends on the stepper's + gear's resolution


void setup() {
  Serial.begin(9600);   // set up Serial library at 9600 bps
  motor.setSpeed(200);  //  This is needed for my Adafruit MotorShield on the Arduino
}

void loop() {
  if (Serial.available() > 0) {
    val = Serial.read();  // read if theres a message in the port and store it in the communication variable             
  } 
  if (val == 'T' && count < limit){
    motor.step(StepsPerRound/limit, FORWARD, SINGLE); //Performs a turntable motion - This is needed for my Adafruit MotorShield on the Arduino
    motor.release(); // Releases the stepper - This is needed for my Adafruit MotorShield on the Arduino
    count +=1; //
  }
  if (val == '2' && count > 0 && count < limit){
    Serial.println("S"); // Triggers the next scan when DAVID has sent its "ready" message
  }
  if (val == '2' && count == limit){
    count = 0; //Just to reset things when you finished a whole round
  }
  if (val == '1'){
    count = 0; //To reset the counter after a faulty try switch to DAVID#s Calibration mode and return to ScanningMode
  }
  val = 0; // To refresh the COM port input
}


Hope you'll find this usefull
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby MagWeb » Thu Feb 06, 2014 10:51 pm

Just to give an idea of needed time:

This was done grabbing 10 scans per round.
Scanning and aligning these 10 scans lasted 3:00,14 min (18sec/scan) without any interaction after clicking the first start.
Fusion needed another click and some time (depending on the res). This is at 1000.
Attachments
AutoScan.jpg
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby Sven » Fri Feb 07, 2014 6:41 pm

Beautiful code! Short, clear, effective :D
Thanks Gunter!
User avatar
Sven
DAVID Developer
 
Posts: 1541
Joined: Mon Jan 22, 2007 8:59 am
Location: Braunschweig, Germany

Re: Automated 360° Turntable Code

Postby MagWeb » Fri Feb 07, 2014 9:08 pm

Not that complicated - you made the interface.
Some credits go to: mexscan - he asked how to do this...
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby loddie » Mon Feb 10, 2014 6:47 am

Gunter,

Thanks for sharing! I just ordered an Arduino Mega today to create a 2 axis rig similar to your Gate: http://forum.david-3d.com/viewtopic.php?f=6&t=1674

However, I plan to use with the SLS-1 instead of laser.

Were you able to get the Gate to complete 2 axis scans with one click? In other words, can the software scan 360 degrees in set increments, fuse, rotate the other axis, scan again, fuse with just one click? I'm guessing the software will only allow scanning in one plane and fusing, but not two planes with a single click. Hope this makes sense. :D

I'm hoping to build a rig where the scanner rides on a track like a bicycle rim, scanning in 60 degree increments around the object. Then the bicycle rim would rotate on its own axis 90 degrees, and the scan is repeated. Hopefully the process can be automated to scan in two planes with just one click.
loddie
 
Posts: 5
Joined: Thu Oct 17, 2013 4:11 pm

Re: Automated 360° Turntable Code

Postby MagWeb » Mon Feb 10, 2014 2:59 pm

Hi,

as long as there's enough overlap between the new and the previous scan, this will work with any position of a rig.

Yes with my Gate I could manage a one click result also on these two axis. At that time we still had the CommandFileInterpreter were you could script a alignment process freely. (means free, fine, global-alignment as well as fusion). Now this way allows only free alignment and you've to start the fusion manually.
Maybe the future DAVID SDK will give us more possibilities to plan and automize a scan...
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby loddie » Mon Feb 10, 2014 6:51 pm

That's too bad the CommandFileInterpreter is no longer an option. :( Let's hope the future SDK restores this functionality. :D
loddie
 
Posts: 5
Joined: Thu Oct 17, 2013 4:11 pm

Re: Automated 360° Turntable Code

Postby hunkatibor2 » Sun Mar 23, 2014 5:04 pm

Hi Magweb
Aurdino built the control system and stepping up with my boyfriend. The letter T to rotate the object. I do not understand yet what comes to automatic work. One should install some software?
Tibor
Intel Xeon E5410 2.33GHZ 16GB RAM Windows 7 64bit David 4.5.0
2 Basler A622F camera 2 Tamron Asfirical AF 28-80mm lense
LG DLP Projector PF1500G Canon D40 Tokina 17-70mm 1:2.8-4,5
Humanti Calibration panel system and Alignmed&Two camera
hunkatibor2
 
Posts: 1408
Joined: Tue Mar 16, 2010 4:26 pm
Location: Hungary

Re: Automated 360° Turntable Code

Postby MagWeb » Mon Mar 24, 2014 12:25 pm

No other software than DAVID and the code on the Arduino needed.
This uses the default command/message settings in DAVID.
Enable "add to list" checkbox in SL menue

The workflow is:

User does a first scan
This is the loop performed X times:
DAVID passes the scan over to ShapeFusion automatically AND sends a 'T' to Arduino
Arduino turns the turntable and waits
When DAVID falls back to SL it sends a '2' to the Arduino
If the Arduino reads a '2', it sends a 'S' to DAVID which triggers the second scan
The loop is performed again
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby gkrywusha » Wed Apr 16, 2014 9:56 pm

Hi Magweb,

I'm going to work on making my first turntable using the Arduino Uno R3 coupled with an Adafuit Motor Shield V2.

The motor I purchased was this one...

http://www.amazon.com/gp/product/B004G5 ... UTF8&psc=1

It states the features as:
Step Angle (degrees) :1.8
2 Phase
Rated Voltage : 12V
Rated Current : 0.33A
Holding Torque : 2.3kg*cm
5mm Diameter Drive Shaft

As I'm not a coder, what augment would I need to run this with your code and have it scan every 18 degrees?
Any advice is most appreciated. Thanks!
gkrywusha
 
Posts: 69
Joined: Sun Oct 27, 2013 8:41 pm

Re: Automated 360° Turntable Code

Postby MagWeb » Fri Apr 18, 2014 5:29 pm

Seems Adafruit changed some things to call the stepper for the V2 MotorShield. The code above was written for the V1 shield.

You may have to adopt the lines commented with "// This is needed for my Adafruit MotorShield on the Arduino "

Concerning your stepper:
It does 200 steps per round ( 360/1.8 )
So you've to set the line:
int StepsPerRound = 20000; // Depends on the stepper's + gear's resolution
to
int StepsPerRound = 200; // Depends on the stepper's + gear's resolution
(I would consider a gear to get a higher resolution which will give a smoother movement)

Concerning your number of scans:
If you do a scan each 18° it will give 20 scans /round. (This is a pretty high number - for most objects a number of 8-10 scans/round should be enough.)
You've to set the line
int limit = 10; // Means the number of scans/round
to
int limit = 20; // Means the number of scans/round

This should be all.. as said there maybe some issues concerning the new V2 library...
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Re: Automated 360° Turntable Code

Postby gkrywusha » Fri Apr 18, 2014 6:01 pm

Thanks for the reply!

Just found the last pieces will be delivered today so I'll be building over the weekend. I'll let you know how things are progressing. Thanks again.

Greg K.
gkrywusha
 
Posts: 69
Joined: Sun Oct 27, 2013 8:41 pm

Re: Automated 360° Turntable Code

Postby gkrywusha » Fri Apr 18, 2014 9:51 pm

Also, I agree on the number of scans, but with my camera and projector trying to scan 32mm miniatures, I have lots of holes and it seems I have to increase the scan number to get full coverage. Will have to figure out the gear variable and how that is worked into construction. I'm very wet behind the ears, but love the idea. I got burned with a Kickstarter dual laser scanner and and amazed at the quality I can get with even 2nd hand electronics. Believe me, I'd love to have the money for a David system, but disability makes that more a pipedream.

Greg
gkrywusha
 
Posts: 69
Joined: Sun Oct 27, 2013 8:41 pm

Re: Automated 360° Turntable Code

Postby gkrywusha » Fri Apr 25, 2014 8:47 am

Thanks for all the help.

I got the turntable working and can now scan easily in 10 scans. I'm wondering about one thing. My turntable looks to be finalizing its first move when the 2nd scan starts. This scan is near automatic as there's no waiting for auto-alignment from a previous scan. Is there a way to add a delay or speed up the movement to compensate? Other than that, this is great. Still working on meshing some top scans with the 360 at this point.

Thanks,

Greg K.
gkrywusha
 
Posts: 69
Joined: Sun Oct 27, 2013 8:41 pm

Re: Automated 360° Turntable Code

Postby MagWeb » Fri Apr 25, 2014 9:43 am

A line

delay(1000);

makes the code wait 1 sec (the value is in microseconds)

I'd add it here:

if (val == '2' && count > 0 && count < limit){
delay(1000); // replace 1000 with the needed delay in ms
Serial.println("S"); // Triggers the next scan when DAVID has sent its "ready" message
}
MagWeb
Moderator
 
Posts: 2499
Joined: Wed Jul 18, 2007 8:48 pm

Next

Return to Structured Light Scanning

Who is online

Users browsing this forum: No registered users and 2 guests

cron