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:
parent
1c1978107d
commit
1056e81b82
|
@ -106,5 +106,6 @@ bool ContactPrinter::IsRunning () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactPrinter::Loop () {
|
void ContactPrinter::Loop () {
|
||||||
|
timer = millis();
|
||||||
drive_motor.Loop();
|
drive_motor.Loop();
|
||||||
}
|
}
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue