def calculate_and_move_trap(self):
     global phi, angle, haptic_toggle
     t1 = time.time()
     phi_focus = phase_algorithms.phase_find(rt,x,y,z)
     t2 = time.time()
     # Making it so if haptic is on it will only focus and if its off it will add the pattern
     if haptic_toggle == False:
         phi = phase_algorithms.add_twin_signature(rt,phi_focus, angle)
     else:
         phi = phi_focus
     t3 = time.time()
     #print("T1 = :", t2-t1)
     #print("T2 = :", t3-t2)
     t4 = time.time()
     for i in range(88):
         # Send offset commands
         command = Functions.create_board_command_offset(board, i, phi[i])
         reply = self.com.send_json(command)
         if reply["Status"] != "Success":
             raise Exception("Failed to start conversion", reply)
     t5 = time.time()  
     #print("T3 = :", t5-t4)
     # Send load offset command
     command = Functions.create_board_command_load_offsets(board)
     reply = self.com.send_json(command)
     if reply["Status"] != "Success":
         raise Exception("Failed to start conversion 1", reply)
Esempio n. 2
0
        def calculate_and_move_trap(self):
            import math
            import phase_algorithms
            import numpy as np
            import transducer_placment
            global phase_index

            phi_focus = phase_algorithms.phase_find(rt, x, y, z)
            phi = phase_algorithms.add_twin_signature(rt, phi_focus, 90)
            for transducer in range(0, ntrans):
                phase_index[transducer] = int(2500 - phi[transducer] /
                                              ((2 * math.pi) / 1250))
            print(" ")
            print("Moved!")
            print("Phase index is ", phase_index)
            print("New Position: ", "x = "
                  "%.3f" % x, "y = "
                  "%.3f" % y, "z = "
                  "%.3f" % z)  #tester

            from connect import Controller
            with Controller() as ctl:
                ctl.setOutputDACPower(256)
                ctl.setOutputDACDivisor(100)
                for i in range(ctl.outputs):
                    ctl.setOffset(i, phase_index[i])
                ctl.loadOffsets()
"""

# ----------------------Setup for potential calculation------------------------

#rt = transducer_placment.array_grid(0.01,10,10) # spcing , x nummber, y number of transducers
rt = transducer_placment.big_daddy()
#rt = transducer_placment.random(88,0.05,0.01)
ntrans = len(rt)  # Total number of transducers in grid

nt = transducer_placment.direction_vectors(
    ntrans, [0, 0, 1])  # nt is the direction vector of each transducer

focus_point = [0, 0, 0]

phi_focus = phase_algorithms.phase_find(
    rt, focus_point[0], focus_point[1], focus_point[2]
)  # phi is the initial phase of each transducer to focus on a point
phi_signature = phase_algorithms.add_twin_signature(rt, np.copy(phi_focus), 90)
#phi_signature = phase_algorithms.add_vortex_signature(rt, np.copy(phi_focus))
#phi_signature = phase_algorithms.add_bottle_signature(rt, np.copy(phi_focus),0.03)
#phi_noise = phase_algorithms.phase_random_noise(2, np.copy(phi_signature)) # number is randomness multiplier (0-1)*multiplier scaled between 0 and 2pi

phi = phi_signature

potential_calculated = algorithms.force_calc(
    focus_point, rt, nt, phi, vti=False
)  ## Outputs = pabs, fx, fy, fz, u_with_gravity, u_with_gravity_nano, laplace_u

u_with_gravity_nano = potential_calculated[5]

potential_array = u_with_gravity_nano
Esempio n. 4
0
rt = transducer_placment.delete_transducers(rt,trans_to_delete)
ntrans = len(rt);
global phase_index

# -------------------------------------------------------------------------- #p


choose = input("Please choose haptic as (h) or pattern as (p) or moving as (m) or GUI controled movment as (GUI): ")


## --------------------------- Haptic feedback --------------------------- ##
    
if choose == ("h"):
    print ("Haptic mode selected")
    phase_index = np.zeros((ntrans),dtype=int)
    phi_focus = phase_algorithms.phase_find( rt, 0, 0, 0.08 ) #  (x , y , z) (z = up)
    for transducer in range(0,ntrans):
        phase_index[transducer] = int(2500-phi_focus[transducer]/((2*math.pi)/1250))
        
    from connect import Controller 
    with Controller() as ctl:
        
        while True:          # Turns the pattern off and on as fast as possible
            
            for i in range(ctl.outputs):
                ctl.setOffset(i,phase_index[i])
            ctl.loadOffsets()
    
            for i in range(ctl.outputs):
                ctl.disableOutput(i)
# -------------------------------------------------------------------------- #
    with Controller() as com:        
        command_power = Functions.create_board_command_power(board, 256)
        reply_power = com.send_json(command_power)
        if reply_power["Status"] != "Success":
            raise Exception("Failed to start conversion 2", reply_power)
            

                   
## --------------------------- Haptic feedback --------------------------- ##
    


elif choose == ("h"):
    print ("Haptic mode selected")
       
    phi_focus = phase_algorithms.phase_find(rt,0,0,0.10)

    from Controller import Controller
    with Controller() as com:        
        for i in range(88):
            # Send offset commands
            command = Functions.create_board_command_offset(board, i, phi_focus[i], True)
            reply = com.send_json(command)
            if reply["Status"] != "Success":
                raise Exception("Failed to start conversion 1", reply)
                
        # Send load offset command
        command = Functions.create_board_command_load_offsets(board)
        reply = com.send_json(command)
        if reply["Status"] != "Success":
            raise Exception("Failed to start conversion 1", reply)