/** * Claude's Eyes - Motor Control Header * * Controls the 4WD drive system (2 motors per side) */ #ifndef MOTOR_CONTROL_H #define MOTOR_CONTROL_H #include // Movement directions enum MotorDirection { DIR_STOP, DIR_FORWARD, DIR_BACKWARD, DIR_LEFT, // Turn left (pivot) DIR_RIGHT, // Turn right (pivot) DIR_SOFT_LEFT, // Soft turn left (one side slower) DIR_SOFT_RIGHT // Soft turn right (one side slower) }; class MotorControl { public: MotorControl(); /** * Initialize motor pins and PWM * @return true if successful */ bool begin(); /** * Move in a direction for a specified duration * @param direction Movement direction * @param speed Speed (0-100 percent) * @param duration_ms Duration in milliseconds (0 = continuous) */ void move(MotorDirection direction, int speed = 50, unsigned long duration_ms = 0); /** * Stop all motors immediately */ void stop(); /** * Check if motors are currently active */ bool isMoving() { return _isMoving; } /** * Get current direction */ MotorDirection getCurrentDirection() { return _currentDirection; } /** * Get current speed (0-100) */ int getCurrentSpeed() { return _currentSpeed; } /** * Get direction as string */ const char* getDirectionString(); /** * Update motor state (call from loop for timed movements) */ void update(); /** * Enable/disable motors (safety feature) */ void setEnabled(bool enabled) { _enabled = enabled; if (!enabled) stop(); } bool isEnabled() { return _enabled; } private: bool _initialized; bool _enabled; bool _isMoving; MotorDirection _currentDirection; int _currentSpeed; unsigned long _moveStartTime; unsigned long _moveDuration; // Internal motor control void setMotorA(int speed); // -255 to 255 void setMotorB(int speed); // -255 to 255 int percentToSpeed(int percent); }; // Global instance extern MotorControl Motors; #endif // MOTOR_CONTROL_H