Skip to content

Instantly share code, notes, and snippets.

@samuelsadok
Created September 7, 2019 10:02
Show Gist options
  • Save samuelsadok/41045b129878085ecc8d8a09d42b8e67 to your computer and use it in GitHub Desktop.
Save samuelsadok/41045b129878085ecc8d8a09d42b8e67 to your computer and use it in GitHub Desktop.
def generic_test(test_name, axis, vf_tuples, duration = 2.0, savefile = None):
axis.motor.config.motor_type = 2 # force voltage control
axis.motor.config.pole_pairs = 1 # ensure vel_setpoint is in [Hz]
axis.controller.current_setpoint = 0
axis.requested_state = 11 # open loop
axis.controller.vel_setpoint = 0
time.sleep(0.01)
if axis.current_state != 11:
raise Exception("not controlling, error code 0x{:02X}".format(axis.error))
runs = []
for voltage, frequency in vf_tuples:
print("{} with {}V @ {}Hz...".format(test_name, voltage, frequency))
axis.controller.current_setpoint = 0
time.sleep(3)
print("go!")
axis.controller.vel_setpoint = frequency
axis.controller.current_setpoint = voltage
start = time.monotonic()
run = {
"omega_stator": 2 * pi * frequency,
"omega_rotor": 0, # TODO: record encoder feedback
"timestamps": [],
"Vq": [],
"Vd": [],
"Iq": [],
"Id": []
}
while time.monotonic() - start < duration:
run["timestamps"].append(time.monotonic() - start)
run["Vq"].append(axis.motor.current_control.final_v_q)
run["Vd"].append(axis.motor.current_control.final_v_d)
run["Iq"].append(axis.motor.current_control.Iq_measured)
run["Id"].append(axis.motor.current_control.Id_measured)
time.sleep(0.001)
runs.append(run)
axis.controller.current_setpoint = 0
axis.requested_state = 1 # idle
if savefile:
import json
with open(savefile, "w") as fp:
json.dump(runs, fp, indent=4)
return runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment