odrive.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "Arduino.h"
  3. #define READ_TIMEOUT 1000
  4. class ODrive {
  5. public:
  6. ODrive(Stream& serial_in);
  7. enum AxisState_t {
  8. AXIS_STATE_UNDEFINED = 0, //<! will fall through to idle
  9. AXIS_STATE_IDLE = 1, //<! disable PWM and do nothing
  10. AXIS_STATE_STARTUP_SEQUENCE = 2, //<! the actual sequence is defined by
  11. // the config.startup_... flags
  12. AXIS_STATE_FULL_CALIBRATION_SEQUENCE =
  13. 3, //<! run all calibration procedures, then idle
  14. AXIS_STATE_MOTOR_CALIBRATION = 4, //<! run motor calibration
  15. AXIS_STATE_SENSORLESS_CONTROL = 5, //<! run sensorless control
  16. AXIS_STATE_ENCODER_INDEX_SEARCH = 6, //<! run encoder index search
  17. AXIS_STATE_ENCODER_OFFSET_CALIBRATION =
  18. 7, //<! run encoder offset calibration
  19. AXIS_STATE_CLOSED_LOOP_CONTROL = 8 //<! run closed loop control
  20. };
  21. enum ControlMode_t {
  22. CONTROL_MODE_VOLTAGE_CONTROL = 0,
  23. CONTROL_MODE_TORQUE_CONTROL = 1,
  24. CONTROL_MODE_VELOCITY_CONTROL = 2,
  25. CONTROL_MODE_POSITION_CONTROL = 3,
  26. };
  27. // Commands
  28. void setPosition(float position);
  29. void setPosition(float position, float velocity_feedforward);
  30. void setPosition(float position, float velocity_feedforward,
  31. float current_feedforward);
  32. void setVelocity(float velocity);
  33. void setVelocity(float velocity, float current_feedforward);
  34. void setCurrent(float current);
  35. void setGain(float pos, float vel, float vel_integrator);
  36. void setControlMode(int32_t mode);
  37. void setControlInputPos(float pos);
  38. void trapezoidalMove(float position);
  39. // Getters
  40. float getVelocity();
  41. float getVbusVoltage();
  42. int32_t getEncoderShadowCount();
  43. float getEncoderPosEstimate();
  44. float getMotorTemp();
  45. float getPhaseCurrent();
  46. float getBusCurrent();
  47. bool checkError(int32_t* axis = NULL, int32_t* motor_thermistor = NULL,
  48. int32_t* encoder = NULL, int32_t* controller = NULL);
  49. // General params
  50. // State helper
  51. bool runState(int32_t requested_state, uint32_t timeout);
  52. // device will reboot
  53. void eraseConfig();
  54. void reboot();
  55. void saveConfig();
  56. void setDefaultConfig();
  57. float readFloat();
  58. int32_t readInt();
  59. void writeToDeive(const char* data);
  60. void writeConfig(const char* config, float_t value);
  61. void writeConfig(const char* config, int32_t value);
  62. int32_t readConfigInt(const char* config);
  63. float readConfigFloat(const char* config);
  64. private:
  65. String readString();
  66. void readFlush();
  67. Stream& serial;
  68. };