Commits

Christophe Combelles committed c043bb7

further dev on shooting

Comments (0)

Files changed (2)

reliefcnc/main.py

     parser.add_option('-d', '--debug', nargs=0, help='set debug mode')
     parser.add_option('-m', '--music', nargs=0, help='play music')
     parser.add_option('-t', '--test', nargs=0, help='test')
+    parser.add_option('-b', '--moveby', nargs=0, help='move by N steps')
     (options, args) = parser.parse_args()
     if options.debug is not None:
         debug = True
         debug = False
 
     if options.music is not None:
-        import pdb; pdb.set_trace()
         MusicPlayer().test()
         sys.exit()
+
+    if options.moveby.isdigit():
+        shooter = ReliefShooter(debug=debug)
+        shooter.move_by(options.moveby)
+        sys.exit()
+        
     
     if options.test is not None:
-        ReliefShooter(debug=debug).test()
+        shooter = ReliefShooter(debug=debug)
+        shooter.base = 1600
+        shooter.camdelay = 1
+        shooter.zero()
+        shooter.test()
+        #shooter.shoot()
         sys.exit()
 
     print u'doing nothing is boring'

reliefcnc/shoot.py

 
 class ReliefShooter(object):
 
+    base = 10 # distance between 2 images in mm
+    nb_points = 8 # nb of stereoscopic images (8 for Alioscopy panel)
+    camdelay = 0.5 # delay (s) between the burst command and the 1st image
+    burst_period = 1.515/7 # delay between 2 images
+    # The Nikon D200 took 8 images (7 intervals) in 1.515s
+    position = 0 # current position in mm
+
     def __init__(self, debug=False):
         self.tiny = TinyCN(debug=debug)
 
         # motor resolution
         self.tiny.motor.res_x = 30
-        self.tiny.motor.res_y = 200
-        self.tiny.motor.res_z = 200
 
+        # speed
+        self.tiny.tool.speed = 800
+        self.tiny.set_speed(self.tiny.tool.speed, self.tiny.motor.res_x)
+    
+        # set maximum acceleration
+        self.tiny.set_speed_acca(3)
+        self.tiny.set_speed_accb(1)
 
-    def test(self):
-        # calibrate zero
+        self.cam_command = ('gphoto2',
+                            '--auto-detect',
+                            '--set-config',
+                            '/main/settings/capturetarget=1',
+                            '--set-config',
+                            '/main/capturesettings/capturemode=1',
+                            '--set-config',
+                            '/main/capturesettings/burstnumber=8',
+                            '--capture-image')
 
-        # move to the left
+    def zero(self):    
+        self.tiny.zero_x()
+        self.position = 0
+
+    def move_to(self, position):
+        """Move to specified position in mm using a ramp
+        """
+        self.position = position
+        self.step = self.position 
+        self.move_ramp(position)
+        
+    def move_by(self, distance):
+        """Move the camera by the specified distance in mm
+        """
+        current_position = self.tiny.get_x()
+        steps_to_move = distance*10
+        self.tiny.move_ramp_x(current_position + steps_to_move)
+
+    def shoot(self):
+        """shoot according to the parameters
+        """
+        # calculate the speed according to the burst rate
+        speed = int(self.nb_points * self.base / self.burst_period)
+
+        # calculate the acceleration length (D = Vmax^2 / a)
+        acc_length = self.tiny.get_speed_max**2 / acceleration
+
+        # move to the left point + acceleration length + a 1cm margin
+        self.move_ramp(-int(self.base/2) + acc_length + 10)
 
         # launch the burst
+        p = subprocess.Popen(self.cam_command)
+        
+        # launch the ramp
+        self.tiny.set_speed_max(3000, self.tiny.motor.res_x)
 
-        # launch the cnc commands
+        # return to zero    
+        self.tiny.move_ramp_x(0)
+    
+        # wait for the buffer to be empty
+        while self.tiny.get_fifo_count() > 0:
+            time.sleep(0.1)
 
-        # return to the left
-
-
-        # speed
-        self.tiny.tool.speed = 700
-        self.tiny.set_speed(self.tiny.tool.speed, self.tiny.motor.res_x)
-    
-        # acceleration
-        self.tiny.set_speed_acca(4)
-        #self.tiny.set_speed_accb(2)
-    
-        # launch the burst shoot
-        # D200 took 1.515sec for 8 images
-    
-        self.tiny.move_var_x(4400, 0, 105, 'up')
-        self.tiny.move_var_x(5000, 105, 0, 'down')
-    
-        self.tiny.move_var_x(600, 0, 300, 'up')
-        self.tiny.move_var_x(0, 300, 0, 'down')
-    
-        time.sleep(0.5)
-    
-        command = ('gphoto2',
-                   '--auto-detect',
-                   '--set-config',
-                   '/main/settings/capturetarget=1',
-                   '--set-config',
-                   '/main/capturesettings/capturemode=1',
-                   '--set-config',
-                   '/main/capturesettings/burstnumber=8',
-                   '--capture-image')
-    
-        p = subprocess.Popen(command)
-    
-        #ramp self.tiny.write('\x14\x08\x10\x00' + 3*'\x00\x00\x01\x10')
-        #self.tiny.get_buffer_state()
+        print u'finished!'
         #while self.tiny.get_buffer_state() != '\x00\x80':
         #    pass
-        #while self.tiny.get_fifo_count() > 0:
-        #    time.sleep(0.1)
     
-    #    usb.release_interface(self.tiny.handle, 0)
-    #    usb.detach_kernel_driver_np(self.tiny.handle,0)
-    #    usb.reset(self.tiny.handle)
-    #    usb.close(self.tiny.handle)
-        #del self.tiny
-
-
-
-
-    
-
-