Fill out EncoderMotor methods and add variables to be used to calculate position + speed and used for PID. TODO: rename class because it is not a generic EncoderMotor class, should instead be DriveMotor.

This commit is contained in:
Matt McWilliams 2024-02-17 13:05:43 +00:00
parent 1c1978107d
commit 1056e81b82
4 changed files with 27 additions and 3 deletions

View File

@ -106,5 +106,6 @@ bool ContactPrinter::IsRunning () {
} }
void ContactPrinter::Loop () { void ContactPrinter::Loop () {
timer = millis();
drive_motor.Loop(); drive_motor.Loop();
} }

View File

@ -26,6 +26,8 @@ class ContactPrinter {
const uint8_t takeup_stock_pwm_channel = 2; const uint8_t takeup_stock_pwm_channel = 2;
const uint8_t pwm_resolution = 8; const uint8_t pwm_resolution = 8;
volatile long timer = 0;
volatile float drive_speed = 1.0; //calculated rpm volatile float drive_speed = 1.0; //calculated rpm
volatile float takeup_speed = 1.0; //estimated rpm volatile float takeup_speed = 1.0; //estimated rpm

View File

@ -25,6 +25,21 @@ void EncoderMotor::Setup () {
digitalWrite(backward_pin, LOW); digitalWrite(backward_pin, LOW);
} }
void EncoderMotor::Loop () { void EncoderMotor::Start() {
ledcWrite(pwm_channel, pwm_duty_cycle);
digitalWrite(forward_pin, HIGH);
digitalWrite(backward_pin, LOW);
}
void EncoderMotor::Stop() {
pwm_duty_cycle = 0;
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
ledcWrite(pwm_channel, pwm_duty_cycle);
}
void EncoderMotor::SetSpeed() {
pwm_duty_cycle = 255;
}
void EncoderMotor::Loop () {
//monitor speed
} }

View File

@ -14,12 +14,18 @@ class EncoderMotor {
volatile uint8_t encoder_a_pin = 27; volatile uint8_t encoder_a_pin = 27;
volatile uint8_t encoder_b_pin = 26; volatile uint8_t encoder_b_pin = 26;
volatile uint8_t pwm_duty_cycle = 255; volatile uint8_t pwm_duty_cycle = 0;
const uint32_t pwm_frequency = 30000; const uint32_t pwm_frequency = 30000;
const uint8_t pwm_channel = 0; const uint8_t pwm_channel = 0;
const uint8_t pwm_resolution = 8; const uint8_t pwm_resolution = 8;
const uint8_t ppr = 11;
const float ratio = 187.0 / 3.0;
const uint32_t maxPulses = (int) round((float) ppr * ratio);
const uint8_t speed = 255;
const uint8_t framesPerRotation = 18;
public: public:
EncoderMotor(); EncoderMotor();