Advertisement
Guest User

ODrive test script

a guest
Nov 2nd, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. import odrive
  2. from odrive.enums import *
  3. import numpy as np
  4. import time
  5. import pickle as pkl
  6.  
  7. odrv = odrive.find_any()
  8.  
  9. BUF_SIZE = 10_000
  10. t_buf = np.zeros(BUF_SIZE)
  11. effective_torque_setpoint_buf = np.zeros(BUF_SIZE)
  12. vbus_buf = np.zeros(BUF_SIZE)
  13. modq_buf = np.zeros(BUF_SIZE)
  14. modd_buf = np.zeros(BUF_SIZE)
  15. vq_buf = np.zeros(BUF_SIZE)
  16. vd_buf = np.zeros(BUF_SIZE)
  17. va_buf = np.zeros(BUF_SIZE)
  18. vb_buf = np.zeros(BUF_SIZE)
  19.  
  20. n = 0
  21.  
  22. input("************ Press enter to start test. Warning - motor will activate!")
  23.  
  24. try:
  25.     odrv.axis0.controller.config.input_mode = InputMode.PASSTHROUGH
  26.     odrv.axis0.controller.config.control_mode = ControlMode.TORQUE_CONTROL
  27.     odrv.axis0.requested_state = AxisState.CLOSED_LOOP_CONTROL
  28.  
  29.     odrv.axis0.controller.input_torque = 0.4
  30.  
  31.     t0 = time.monotonic()
  32.     while ((odrv._obj_handle is not None) and (odrv.axis0.current_state == AxisState.CLOSED_LOOP_CONTROL) and (n < BUF_SIZE)):
  33.         t_now = time.monotonic() - t0
  34.         effective_torque_setpoint = odrv.axis0.controller.effective_torque_setpoint
  35.         vbus = odrv.vbus_voltage
  36.         mod_q = odrv.axis0.motor.foc.mod_q
  37.         mod_d = odrv.axis0.motor.foc.mod_d
  38.         v_q = odrv.axis0.motor.foc.Vq_setpoint
  39.         v_d = odrv.axis0.motor.foc.Vd_setpoint
  40.         v_a = odrv.axis0.motor.foc.final_v_alpha
  41.         v_b = odrv.axis0.motor.foc.final_v_beta
  42.    
  43.         t_buf[n] = t_now
  44.         effective_torque_setpoint_buf[n] = effective_torque_setpoint
  45.         vbus_buf[n] = vbus
  46.         modq_buf[n] = mod_q
  47.         modd_buf[n] = mod_d
  48.         vq_buf[n] = v_q
  49.         vd_buf[n] = v_d
  50.         va_buf[n] = v_a
  51.         vb_buf[n] = v_b
  52.    
  53.         n += 1
  54. except (AttributeError, KeyboardInterrupt) as e:
  55.     pass
  56.  
  57. results_buf = [None]*n
  58. for i in range(n):
  59.     results_buf[i] = {
  60.             't': t_buf[i],
  61.             'tau': effective_torque_setpoint_buf[i],
  62.             'vbus': vbus_buf[i],
  63.             'modq': modq_buf[i],
  64.             'modd': modd_buf[i],
  65.             'vq': vq_buf[i],
  66.             'vd': vd_buf[i],
  67.             'va': va_buf[i],
  68.             'vb': vbus_buf[i]
  69.             }
  70.  
  71. with open('data_outfile.pkl', 'wb') as f:
  72.     pkl.dump(results_buf, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement