Files
walker_control/include/motor.h
devdesk fcfee5fa66 Remove all stall detection logic, add 100ms current logging
- Removed all STALL_* configuration parameters from config.h
- Simplified motor.h: removed stall-related methods and member variables
- Simplified motor.cpp: deleted checkStall(), resetStallDetection()
- Added frequent current logging (100ms) for data collection
- Removed stall callback system from main.cpp
- Simplified pingpong mode: time-based only, removed stall-return option
- Updated webserver: removed stall warning UI, removed stallReturn checkbox
- Updated status JSON: removed stalled and ppStallReturn fields

This version is for testing with new beefy PSU to collect current data
before designing new stall detection algorithm.
2026-02-05 20:59:38 +02:00

61 lines
1.7 KiB
C++

#ifndef MOTOR_H
#define MOTOR_H
#include <Arduino.h>
#include "config.h"
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
// Pingpong mode (time-based only)
void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent);
void stopPingpong();
bool isPingpongActive();
int getPingpongSpeed();
int getPingpongTime();
int getPingpongSpeedRandom();
int getPingpongTimeRandom();
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;
// Pingpong state
bool _pingpongActive = false;
int _pingpongBaseSpeed = 50;
int _pingpongBaseTime = 2000;
int _pingpongSpeedRandomPercent = 0;
int _pingpongTimeRandomPercent = 0;
int _pingpongCurrentSpeed = 50;
int _pingpongCurrentTime = 2000;
unsigned long _pingpongLastSwitch = 0;
int _pingpongDirection = 1;
void applyMotorState();
float readCurrentSense(int pin);
void calibrateCurrentOffset();
void updatePingpong();
int applyRandomness(int baseValue, int randomPercent);
};
extern MotorController motor;
#endif