Define IO behavior
This commit is contained in:
parent
7dc33b5dc1
commit
abc2054600
|
@ -7,12 +7,16 @@ ContactPrinter::ContactPrinter () {
|
|||
|
||||
void ContactPrinter::Setup () {
|
||||
pinMode(drive_pin, OUTPUT);
|
||||
pinMode(takeup_picture_pin, OUTPUT);
|
||||
pinMode(takeup_stock_pin, OUTPUT);
|
||||
pinMode(takeup_picture_pin_cw, OUTPUT);
|
||||
pinMode(takeup_picture_pin_ccw, OUTPUT);
|
||||
pinMode(takeup_stock_pin_cw, OUTPUT);
|
||||
pinMode(takeup_stock_pin_ccw, OUTPUT);
|
||||
|
||||
digitalWrite(drive_pin, LOW);
|
||||
digitalWrite(takeup_picture_pin, LOW);
|
||||
digitalWrite(takeup_stock_pin, LOW);
|
||||
digitalWrite(takeup_picture_pin_cw, LOW);
|
||||
digitalWrite(takeup_picture_pin_ccw, LOW);
|
||||
digitalWrite(takeup_stock_pin_cw, LOW);
|
||||
digitalWrite(takeup_stock_pin_ccw, LOW);
|
||||
}
|
||||
|
||||
void ContactPrinter::Start () {
|
||||
|
@ -23,8 +27,9 @@ void ContactPrinter::Start () {
|
|||
|
||||
void ContactPrinter::Stop () {
|
||||
analogWrite(drive_pin, 0);
|
||||
analogWrite(takeup_stock_pin, 0);
|
||||
analogWrite(takeup_picture_pin, 0);
|
||||
delay(100);
|
||||
RampTakeup(takeup_pwm, 0, takeup_ramp_time);
|
||||
|
||||
}
|
||||
|
||||
void ContactPrinter::SetSpeedTakeup(float speed) {
|
||||
|
@ -38,24 +43,43 @@ void ContactPrinter::SetSpeedDrive(float speed) {
|
|||
}
|
||||
|
||||
void ContactPrinter::SetDirectionStock(bool clockwise) {
|
||||
|
||||
takeup_stock_cw = clockwise;
|
||||
}
|
||||
|
||||
void ContactPrinter::SetDirectionPicture(bool clockwise) {
|
||||
|
||||
takeup_picture_cw = clockwise;
|
||||
}
|
||||
|
||||
//linear
|
||||
void ContactPrinter::RampTakeup(uint16_t start, uint16_t end, uint16_t time) {
|
||||
uint16_t steps = abs(start - end);
|
||||
uint16_t step = round(time / steps);
|
||||
uint16_t pwm = start;
|
||||
uint8_t takeup_picture_pin;
|
||||
uint8_t takeup_stock_pin;
|
||||
bool dir = end < start;
|
||||
|
||||
if (takeup_picture_cw) {
|
||||
takeup_picture_pin = takeup_picture_pin_cw;
|
||||
analogWrite(takeup_picture_pin_ccw, 0);
|
||||
} else {
|
||||
takeup_picture_pin = takeup_picture_pin_ccw;
|
||||
analogWrite(takeup_picture_pin_cw, 0);
|
||||
}
|
||||
if (takeup_stock_cw) {
|
||||
takeup_stock_pin = takeup_stock_pin_cw;
|
||||
analogWrite(takeup_stock_pin_ccw, 0);
|
||||
} else {
|
||||
takeup_stock_pin = takeup_stock_pin_cw;
|
||||
analogWrite(takeup_stock_pin_cw, 0);
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < steps; i++) {
|
||||
if (pwm <= 0 || pwm >= 256) {
|
||||
break;
|
||||
}
|
||||
analogWrite(takeup_stock_pin, pwm);
|
||||
analogWrite(takeup_picture_pin, pwm);
|
||||
analogWrite(takeup_stock_pin, pwm);
|
||||
delay(step);
|
||||
if (dir) {
|
||||
pwm++;
|
||||
|
|
|
@ -10,8 +10,10 @@ class ContactPrinter {
|
|||
const uint16_t serial_delay = 5;
|
||||
const uint16_t baud = 57600;
|
||||
const uint8_t drive_pin = 7;
|
||||
const uint8_t takeup_picture_pin = 8;
|
||||
const uint8_t takeup_stock_pin = 9;
|
||||
const uint8_t takeup_picture_pin_cw = 8;
|
||||
const uint8_t takeup_picture_pin_ccw = 9;
|
||||
const uint8_t takeup_stock_pin_cw = 10;
|
||||
const uint8_t takeup_stock_pin_ccw = 11;
|
||||
|
||||
volatile float drive_speed = 1f;
|
||||
volatile float takeup_speed = 1f;
|
||||
|
@ -19,6 +21,11 @@ class ContactPrinter {
|
|||
volatile uint16_t drive_pwm;
|
||||
volatile uint16_t takeup_pwm;
|
||||
|
||||
volatile bool takeup_picture_cw = false;
|
||||
volatile bool takeup_picture_ccw = true;
|
||||
|
||||
volatile uint16_t takeup_ramp_time = 500;
|
||||
|
||||
volatile bool running = false;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue