-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmagnetic_field_current_relation.py
36 lines (27 loc) · 1.43 KB
/
magnetic_field_current_relation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
from math import pi
mu = 4 * pi * 10**(-7) # magnetic field constant Tm/A
halfofsidelength = 0.3302 # meters, physical parameter, check this
distbetweensides = 0.49 #0.4572 # meters, physical parameter, check this
wireturns = 56 #58 # physical parameter, doc says 56, not sure what actual
constmultiplier = wireturns * mu / pi # pulling constants into a single variable
def distFromOriginSquared(d):
return (distbetweensides/2 + d)**2 # meter^2
def dropOffFromSide(d):
A = halfofsidelength ** 2
offset = distFromOriginSquared(d)
return (2 * A) / ((A + offset) * (2 * A + offset)**0.5) # meter^-1
def paramMultiplier(d): # parameter is distance from origin, we usually only care about d=0
return (dropOffFromSide(d) + dropOffFromSide(-d)) * constmultiplier * 10**(6) # microT/A
def getNeededCurrent(desiredfield): #get microteslas return amps
return (desiredfield / paramMultiplier(0)) * 2
def axialMagField(current, d): #get amps return microteslas
#need to get actual current for axis from program or PSU somehow
return current * paramMultiplier(d)
# given the environmental and desired fields, what currents must we pull?
def automatic(env_field, ideal_field):
#compensation
diff = [ideal_field[i] - env_field[i] for i in range(3)]
#negative amps just means amps with a 180 degree polarity
needed_current = [getNeededCurrent(diff[i]) for i in range(3)]
return needed_current