

class MotorControl
{
public:
  void begin();
  void clear()
  {
    numCmds_ = 0;
    currentCmd_ = 0;
  }
  void addCmd(float signedSpeed, unsigned long duration);
  void iteration();

  int numCommands() const { return numCmds_; }
  float speed(int cmdIdx) const;
  unsigned long duration(int cmdIdx) const;

private:
  static constexpr int MAX_MOTOR_COMMANDS = 1024;
  struct MotorCmd
  {
    int directionAndSpeed; // fraction of PWM_RESO
    unsigned long delayToNextCmdInMs;
  };

  int currentCmd_ = 0;
  int numCmds_ = 0;
  MotorCmd motorCommands_[MAX_MOTOR_COMMANDS];
  unsigned long startTime_ = 0;
};
