Move all ramp variables to class members. To move the ramp behavior to the Loop() method there will need to be a global timer.
This commit is contained in:
parent
344e1e8d1d
commit
1c1978107d
|
@ -31,15 +31,15 @@ void ContactPrinter::Setup () {
|
||||||
void ContactPrinter::Start () {
|
void ContactPrinter::Start () {
|
||||||
RampTakeup(0, takeup_pwm_duty_cycle, takeup_ramp_time);
|
RampTakeup(0, takeup_pwm_duty_cycle, takeup_ramp_time);
|
||||||
delay(100);
|
delay(100);
|
||||||
//drive_motor.Start();
|
drive_motor.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactPrinter::Stop () {
|
void ContactPrinter::Stop () {
|
||||||
//drive_motor.Start();
|
drive_motor.Start();
|
||||||
delay(100);
|
delay(100);
|
||||||
RampTakeup( takeup_pwm_duty_cycle, 0, takeup_ramp_time);
|
RampTakeup( takeup_pwm_duty_cycle, 0, takeup_ramp_time);
|
||||||
digitalWrite(takeup_picture_pin_cw, LOW);
|
digitalWrite(takeup_picture_pin_cw, LOW);
|
||||||
digitalWrite(takeup_picture_pin_ccw, LOW)
|
digitalWrite(takeup_picture_pin_ccw, LOW);
|
||||||
digitalWrite(takeup_stock_pin_cw, LOW);
|
digitalWrite(takeup_stock_pin_cw, LOW);
|
||||||
digitalWrite(takeup_stock_pin_ccw, LOW);
|
digitalWrite(takeup_stock_pin_ccw, LOW);
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@ void ContactPrinter::SetDirectionPicture(bool clockwise) {
|
||||||
|
|
||||||
//linear
|
//linear
|
||||||
void ContactPrinter::RampTakeup(uint16_t start, uint16_t end, uint16_t time) {
|
void ContactPrinter::RampTakeup(uint16_t start, uint16_t end, uint16_t time) {
|
||||||
uint16_t steps = abs(start - end);
|
takeup_ramp_steps = abs(start - end);
|
||||||
uint16_t step = round(time / steps);
|
takeup_ramp_step = round(time / takeup_ramp_steps);
|
||||||
uint16_t pwm = start;
|
takeup_pwm_duty_cycle = start;
|
||||||
bool dir = end < start;
|
takeup_ramp_dir = end < start;
|
||||||
|
|
||||||
if (takeup_picture_cw) {
|
if (takeup_picture_cw) {
|
||||||
digitalWrite(takeup_picture_pin_cw, HIGH);
|
digitalWrite(takeup_picture_pin_cw, HIGH);
|
||||||
|
@ -82,20 +82,23 @@ void ContactPrinter::RampTakeup(uint16_t start, uint16_t end, uint16_t time) {
|
||||||
digitalWrite(takeup_stock_pin_cw, LOW);
|
digitalWrite(takeup_stock_pin_cw, LOW);
|
||||||
digitalWrite(takeup_stock_pin_ccw, HIGH);
|
digitalWrite(takeup_stock_pin_ccw, HIGH);
|
||||||
}
|
}
|
||||||
|
takeup_ramping = true;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < steps; i++) {
|
for (uint16_t i = 0; i < takeup_ramp_steps; i++) {
|
||||||
if (pwm <= 0 || pwm >= 256) {
|
if (takeup_pwm_duty_cycle <= 0 || takeup_pwm_duty_cycle >= 255) {
|
||||||
|
takeup_ramping = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ledcWrite(takeup_picture_pwm_channel, pwm);
|
ledcWrite(takeup_picture_pwm_channel, takeup_pwm_duty_cycle);
|
||||||
ledcWrite(takeup_stock_pwm_channel, pwm);
|
ledcWrite(takeup_stock_pwm_channel, takeup_pwm_duty_cycle);
|
||||||
delay(step);
|
delay(takeup_ramp_step);
|
||||||
if (dir) {
|
if (takeup_ramp_dir) {
|
||||||
pwm++;
|
takeup_pwm_duty_cycle++;
|
||||||
} else {
|
} else {
|
||||||
pwm--;
|
takeup_pwm_duty_cycle--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
takeup_ramping = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContactPrinter::IsRunning () {
|
bool ContactPrinter::IsRunning () {
|
||||||
|
|
|
@ -30,6 +30,10 @@ class ContactPrinter {
|
||||||
volatile float takeup_speed = 1.0; //estimated rpm
|
volatile float takeup_speed = 1.0; //estimated rpm
|
||||||
|
|
||||||
volatile uint16_t takeup_pwm_duty_cycle = 0;
|
volatile uint16_t takeup_pwm_duty_cycle = 0;
|
||||||
|
volatile uint16_t takeup_ramp_steps = 0; //# of steps
|
||||||
|
volatile uint16_t takeup_ramp_step = 0; //length of step (ms)
|
||||||
|
volatile boolean takeup_ramp_dir = true; //true = up, false = down
|
||||||
|
volatile boolean takeup_ramping = false;
|
||||||
|
|
||||||
volatile bool takeup_picture_cw = false;
|
volatile bool takeup_picture_cw = false;
|
||||||
volatile bool takeup_picture_ccw = true;
|
volatile bool takeup_picture_ccw = true;
|
||||||
|
|
Loading…
Reference in New Issue