from magum import Magum from array import * DT = 0.02 # 20ms axisOffset = array('i', []) i = 0 magum = Magum(250, 1, 2, 1) # first of all calibrate the sensor axisOffset = magum.calibrateSens(1000) while True: try: cFAngleAxis = magum.compFilter( DT, axisOffset ) # Note: it might need a small time amount to get up to speed except IOError: # avoid timeout errors pass if i % 20 == 0: print str(int(round(cFAngleAxis[0], 0))) + ',' + str( int(round(cFAngleAxis[1], 0))) + ',' + str( int(round(cFAngleAxis[2], 0))) i += 1 # it's better to use % operator for printing out data, # time.sleep may cause uncorrect data do to sampling operation
# G_scaleRange = 250, FsDouble = 1 (enabled) # A_scaleRange = 2, lnoise = 1 (on) magum = Magum(250, 1, 2, 1) axisOffset = magum.calibrateSens(1000) DT = 0.1 Kp = 1.0 Ki = 0.0 Kd = 0.0 setpoint = 90.0 pid = PID(Kp, Ki, Kd, setpoint) value = setpoint pid.tunnings = (Kp, Ki, Kd) while True: time.sleep(DT) #readPID(Kp, Ki, Kd) #pid.tunnings = (Kp, Ki, Kd) try: cFAngleAxis = magum.compFilter(DT, axisOffset) except IOError: pass output = pid(int(cFAngleAxis[2] + cFAngleAxis[0])) output = constrain(output) ser.write((str(output) + '\r\n').encode()) print str(int(round(cFAngleAxis[0], 0))) + ',' + str( int(round(cFAngleAxis[1], 0))) + ',' + str( int(round(cFAngleAxis[2], 0))) print output
from magum import Magum from array import * DT = 0.02 # 20ms axisOffset = array('i',[]) i = 0 magum = Magum(250,1,2,1) # first of all calibrate the sensor axisOffset = magum.calibrateSens(1000) while True: try: cFAngleAxis = magum.compFilter(DT,axisOffset) # Note: it might need a small time amount to get up to speed except IOError: # avoid timeout errors pass if i%20 == 0: print str(int(round(cFAngleAxis[0],0))) + ',' + str(int(round(cFAngleAxis[1],0))) + ',' + str(int(round(cFAngleAxis[2],0))) i += 1 # it's better to use % operator for printing out data, # time.sleep may cause uncorrect data do to sampling operation
from magum import Magum from array import * DT = 0.02 # 20ms axisOffset = array('i',[]) i = 0 magum = Magum(250,1,2,1) # first of all calibrate the sensor axisOffset = magum.calibrateSens(1000) while True: try: cFAngleAxis = magum.compFilter(DT,axisOffset) except IOError: # avoid timeout errors pass if i%20 == 0: print str(int(round(cFAngleAxis[0],0))) + ',' + str(int(round(cFAngleAxis[1],0))) + ',' + str(int(round(cFAngleAxis[2],0))) i += 1 # it's better to use % operator for printing out data, # time.sleep may cause uncorrect data do to sampling operation