Files
walker_control/include/motor.h
devdesk c8d990b1cd Remove pingpong mode completely
- Remove pingpong method declarations and member variables from motor.h
- Remove pingpong implementation (startPingpong, stopPingpong, updatePingpong, etc.) from motor.cpp
- Remove pingpong UI section, handlers, and routes from webserver.cpp
- Remove stopPingpong call from stall callback in main.cpp
2026-02-05 22:01:50 +02:00

54 lines
1.4 KiB
C++

#ifndef MOTOR_H
#define MOTOR_H
#include <Arduino.h>
#include "config.h"
// Stall callback function type
typedef void (*StallCallback)();
class MotorController {
public:
void begin();
void setSpeed(int speed); // 0-100 percentage
void setDirection(int dir); // -1=reverse, 0=stop, 1=forward
void stop();
void update(); // Call in loop() for current monitoring
int getSpeed();
int getDirection();
float getCurrentRight(); // Current in amps (forward direction)
float getCurrentLeft(); // Current in amps (reverse direction)
float getCurrentActive(); // Current from active direction
// Stall detection
bool isStalled();
void setStallCallback(StallCallback callback);
void resetStallDetection();
private:
int _speed = 0;
int _direction = 0;
float _currentRight = 0;
float _currentLeft = 0;
// ADC zero-current offset (calibrated at startup)
int _adcOffsetRight = 0;
int _adcOffsetLeft = 0;
// Stall detection state
bool _stalled = false;
int _stallConfirmCount = 0;
StallCallback _stallCallback = nullptr;
unsigned long _lastDirectionChangeTime = 0;
void applyMotorState();
float readCurrentSense(int pin);
void calibrateCurrentOffset();
void checkStall();
};
extern MotorController motor;
#endif