Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import odrive
- from odrive.enums import *
- import numpy as np
- import time
- import pickle as pkl
- odrv = odrive.find_any()
- BUF_SIZE = 10_000
- t_buf = np.zeros(BUF_SIZE)
- effective_torque_setpoint_buf = np.zeros(BUF_SIZE)
- vbus_buf = np.zeros(BUF_SIZE)
- modq_buf = np.zeros(BUF_SIZE)
- modd_buf = np.zeros(BUF_SIZE)
- vq_buf = np.zeros(BUF_SIZE)
- vd_buf = np.zeros(BUF_SIZE)
- va_buf = np.zeros(BUF_SIZE)
- vb_buf = np.zeros(BUF_SIZE)
- n = 0
- input("************ Press enter to start test. Warning - motor will activate!")
- try:
- odrv.axis0.controller.config.input_mode = InputMode.PASSTHROUGH
- odrv.axis0.controller.config.control_mode = ControlMode.TORQUE_CONTROL
- odrv.axis0.requested_state = AxisState.CLOSED_LOOP_CONTROL
- odrv.axis0.controller.input_torque = 0.4
- t0 = time.monotonic()
- while ((odrv._obj_handle is not None) and (odrv.axis0.current_state == AxisState.CLOSED_LOOP_CONTROL) and (n < BUF_SIZE)):
- t_now = time.monotonic() - t0
- effective_torque_setpoint = odrv.axis0.controller.effective_torque_setpoint
- vbus = odrv.vbus_voltage
- mod_q = odrv.axis0.motor.foc.mod_q
- mod_d = odrv.axis0.motor.foc.mod_d
- v_q = odrv.axis0.motor.foc.Vq_setpoint
- v_d = odrv.axis0.motor.foc.Vd_setpoint
- v_a = odrv.axis0.motor.foc.final_v_alpha
- v_b = odrv.axis0.motor.foc.final_v_beta
- t_buf[n] = t_now
- effective_torque_setpoint_buf[n] = effective_torque_setpoint
- vbus_buf[n] = vbus
- modq_buf[n] = mod_q
- modd_buf[n] = mod_d
- vq_buf[n] = v_q
- vd_buf[n] = v_d
- va_buf[n] = v_a
- vb_buf[n] = v_b
- n += 1
- except (AttributeError, KeyboardInterrupt) as e:
- pass
- results_buf = [None]*n
- for i in range(n):
- results_buf[i] = {
- 't': t_buf[i],
- 'tau': effective_torque_setpoint_buf[i],
- 'vbus': vbus_buf[i],
- 'modq': modq_buf[i],
- 'modd': modd_buf[i],
- 'vq': vq_buf[i],
- 'vd': vd_buf[i],
- 'va': va_buf[i],
- 'vb': vbus_buf[i]
- }
- with open('data_outfile.pkl', 'wb') as f:
- pkl.dump(results_buf, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement