Commits

Christophe Combelles committed 280e6d7

improve shooting

  • Participants
  • Parent commits c043bb7

Comments (0)

Files changed (2)

File reliefcnc/main.py

 def main():
     parser = OptionParser()
     parser.add_option('-d', '--debug', nargs=0, help='set debug mode')
-    parser.add_option('-m', '--music', nargs=0, help='play music')
+    parser.add_option('', '--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')
+    parser.add_option('-m', '--moveby', nargs=1, help='move by N steps')
+    parser.add_option('-s', '--shoot', nargs=0, help='shoot sequence')
+    parser.add_option('-b', '--base', nargs=1, help='define the base in mm')
     (options, args) = parser.parse_args()
     if options.debug is not None:
         debug = True
         MusicPlayer().test()
         sys.exit()
 
-    if options.moveby.isdigit():
+    if (options.moveby is not None
+          and (options.moveby.isdigit()
+          or (options.moveby[0] == '-'
+            and options.moveby[1:].isdigit()))):
         shooter = ReliefShooter(debug=debug)
-        shooter.move_by(options.moveby)
+        shooter.move_by(int(options.moveby))
         sys.exit()
         
     
-    if options.test is not None:
+    if options.shoot is not None:
         shooter = ReliefShooter(debug=debug)
-        shooter.base = 1600
+        shooter.base = 5
+        if options.base.isdigit():
+            shooter.base = int(options.base)
         shooter.camdelay = 1
-        shooter.zero()
-        shooter.test()
+        shooter.shoot()
         #shooter.shoot()
         sys.exit()
 

File reliefcnc/shoot.py

         self.tiny.set_speed_acca(3)
         self.tiny.set_speed_accb(1)
 
-        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')
+        self.cam_command = (
+            'gphoto2',
+            '--auto-detect',
+            '--set-config',
+            '/main/settings/capturetarget=1',
+            '--set-config',
+            '/main/capturesettings/capturemode=1',
+            '--set-config',
+            '/main/capturesettings/burstnumber=%s' % self.nb_points,
+            '--capture-image')
 
     def zero(self):    
         self.tiny.zero_x()
     def shoot(self):
         """shoot according to the parameters
         """
+
+        # reset to zero
+        self.tiny.zero_x()
+
+        assert(self.nb_points > 0)
         # calculate the speed according to the burst rate
-        speed = int(self.nb_points * self.base / self.burst_period)
+        speed = int((self.nb_points-1) * self.base / self.burst_period) # mm/s
+        print 'speed %s' % speed
+
+        # get the acceleration
+        acceleration = 10.0 / self.tiny.get_speed_acca()
 
         # calculate the acceleration length (D = Vmax^2 / a)
-        acc_length = self.tiny.get_speed_max**2 / acceleration
+        reso = 20.0 # factor for acc
+        acc_length = speed**2 / acceleration / reso
+        print 'acc_length %s' % acc_length
 
         # move to the left point + acceleration length + a 1cm margin
-        self.move_ramp(-int(self.base/2) + acc_length + 10)
+        half_range = int(self.base/2 + acc_length + 10)
+        print 'move to %s' % half_range
+        self.tiny.set_speed_max(2500, self.tiny.motor.res_x)
+        self.tiny.move_ramp_x(half_range)
+
+        # wait for the first ramp to finish
+        while self.tiny.get_fifo_count() > 0:
+            time.sleep(0.5)
+
+        # set the max speed of the ramp
+        self.tiny.set_speed_max(speed, self.tiny.motor.res_x)
+        # launch the main ramp
+        print 'move to -%s' % half_range
+        self.tiny.move_ramp_x(-half_range)
 
         # launch the burst
         p = subprocess.Popen(self.cam_command)
         
-        # launch the ramp
-        self.tiny.set_speed_max(3000, self.tiny.motor.res_x)
-
         # return to zero    
+        self.tiny.set_speed_max(2500, self.tiny.motor.res_x)
         self.tiny.move_ramp_x(0)
     
         # wait for the buffer to be empty
-        while self.tiny.get_fifo_count() > 0:
-            time.sleep(0.1)
+        #while self.tiny.get_fifo_count() > 0:
+        #    time.sleep(0.5)
 
         print u'finished!'
         #while self.tiny.get_buffer_state() != '\x00\x80':