Compare commits

...

2 Commits

8 changed files with 106 additions and 103 deletions

View File

@ -1 +1 @@
0.2.0
0.2.1

View File

@ -7,65 +7,77 @@ ContactPrinter::ContactPrinter () {
void ContactPrinter::Setup () {
pinMode(takeup_picture_pin_cw, OUTPUT);
pinMode(takeup_picture_pin_ccw, OUTPUT);
pinMode(takeup_stock_pin_cw, OUTPUT);
pinMode(takeup_stock_pin_ccw, OUTPUT);
pinMode(takeup_pin_dir_a, OUTPUT);
pinMode(takeup_pin_dir_b, OUTPUT);
pinMode(start_button_pin, INPUT_PULLUP);
drive_motor.Setup();
ledcSetup(takeup_picture_pwm_channel, pwm_frequency, pwm_resolution);
ledcSetup(takeup_stock_pwm_channel, pwm_frequency, pwm_resolution);
ledcSetup(takeup_pwm_channel, pwm_frequency, pwm_resolution);
Serial.print("Attaching pin ");
Serial.print(takeup_pin_enable);
Serial.print(" to ledc channel ");
Serial.print(takeup_pwm_channel);
Serial.println(" for takeup");
ledcAttachPin(takeup_pin_enable, takeup_pwm_channel);
ledcWrite(takeup_pwm_channel, takeup_pwm_duty_cycle);
ledcAttachPin(takeup_picture_pin_enable, takeup_picture_pwm_channel);
ledcAttachPin(takeup_stock_pin_enable, takeup_stock_pwm_channel);
digitalWrite(takeup_pin_dir_a, LOW);
digitalWrite(takeup_pin_dir_b, LOW);
ledcWrite(takeup_picture_pwm_channel, takeup_pwm_duty_cycle);
ledcWrite(takeup_stock_pwm_channel, takeup_pwm_duty_cycle);
digitalWrite(takeup_picture_pin_cw, LOW);
digitalWrite(takeup_picture_pin_ccw, LOW);
digitalWrite(takeup_stock_pin_cw, LOW);
digitalWrite(takeup_stock_pin_ccw, LOW);
SetSpeedTakeup(0.4);
SetSpeedDrive(1.0);
SetDirectionTakeup(true);
SetSpeedTakeup(0.9);
SetSpeedDrive(0.8);
start_time = millis();
}
void ContactPrinter::Start () {
Serial.println("Start()");
drive_motor.Start();
//RampTakeup(0, takeup_pwm_duty_cycle, takeup_ramp_time);
StartTakeup();
run_time = timer;
running = true;
}
void ContactPrinter::Stop () {
Serial.println("Stop()");
drive_motor.Stop();
RampTakeup(takeup_pwm_duty_cycle, 0, takeup_ramp_time);
digitalWrite(takeup_picture_pin_cw, LOW);
digitalWrite(takeup_picture_pin_ccw, LOW);
digitalWrite(takeup_stock_pin_cw, LOW);
digitalWrite(takeup_stock_pin_ccw, LOW);
StopTakeup();
run_time = timer;
running = false;
}
void ContactPrinter::SetSpeedTakeup(float speed) {
takeup_speed = speed;
takeup_pwm_duty_cycle = floor(speed * 255);
takeup_pwm_duty_cycle = floor(speed * pwm_maximum);
Serial.print("Set takeup motors PWM = ");
Serial.println(takeup_pwm_duty_cycle);
}
void ContactPrinter::StartTakeup () {
ledcWrite(takeup_pwm_channel, takeup_pwm_duty_cycle);
if (takeup_dir) {
digitalWrite(takeup_pin_dir_a, LOW);
digitalWrite(takeup_pin_dir_b, HIGH);
} else {
digitalWrite(takeup_pin_dir_a, HIGH);
digitalWrite(takeup_pin_dir_b, LOW);
}
}
void ContactPrinter::StopTakeup() {
digitalWrite(takeup_pin_dir_a, LOW);
digitalWrite(takeup_pin_dir_b, LOW);
ledcWrite(takeup_pwm_channel, 0);
}
void ContactPrinter::SetSpeedDrive(float speed) {
drive_motor.SetSpeed(speed);
}
void ContactPrinter::SetDirectionStock(bool clockwise) {
takeup_stock_cw = clockwise;
}
void ContactPrinter::SetDirectionPicture(bool clockwise) {
takeup_picture_cw = clockwise;
void ContactPrinter::SetDirectionTakeup(bool dir) {
takeup_dir = dir;
}
//linear
@ -77,28 +89,11 @@ void ContactPrinter::RampTakeup(uint16_t start_pwm, uint16_t end_pwm, uint16_t t
takeup_ramp_current_step = 0;
takeup_ramping = true;
if (takeup_picture_cw) {
digitalWrite(takeup_picture_pin_cw, HIGH);
digitalWrite(takeup_picture_pin_ccw, LOW);
} else {
digitalWrite(takeup_picture_pin_cw, LOW);
digitalWrite(takeup_picture_pin_ccw, HIGH);
}
if (takeup_stock_cw) {
digitalWrite(takeup_stock_pin_cw, HIGH);
digitalWrite(takeup_stock_pin_ccw, LOW);
} else {
digitalWrite(takeup_stock_pin_cw, LOW);
digitalWrite(takeup_stock_pin_ccw, HIGH);
}
for (uint16_t i = 0; i < takeup_ramp_steps; i++) {
if (takeup_pwm_duty_cycle <= 0 || takeup_pwm_duty_cycle >= 255) {
takeup_ramping = false;
if (takeup_pwm_duty_cycle <= 0 || takeup_pwm_duty_cycle >= pwm_maximum) {
break;
}
ledcWrite(takeup_picture_pwm_channel, takeup_pwm_duty_cycle);
ledcWrite(takeup_stock_pwm_channel, takeup_pwm_duty_cycle);
ledcWrite(takeup_pwm_channel, takeup_pwm_duty_cycle);
delay(takeup_ramp_step);
if (takeup_ramp_dir) {
takeup_pwm_duty_cycle++;
@ -109,13 +104,12 @@ void ContactPrinter::RampTakeup(uint16_t start_pwm, uint16_t end_pwm, uint16_t t
takeup_ramping = false;
}
void ContactPrinter::RampTakeupLoop () {
}
void ContactPrinter::ButtonLoop () {
if (!running && digitalRead(start_button_pin) == LOW) {
if (!running && timer >= run_time + button_delay && digitalRead(start_button_pin) == LOW) {
Start();
} else if (running && timer >= run_time + button_delay && digitalRead(start_button_pin) == LOW) {
Stop();
}
}
@ -125,11 +119,13 @@ bool ContactPrinter::IsRunning () {
void ContactPrinter::Loop () {
timer = millis();
ButtonLoop();
if (running) {
drive_motor.Loop();
if (takeup_ramping) {
RampTakeupLoop();
if (initialized) {
ButtonLoop();
if (running) {
drive_motor.Loop();
}
} else if (timer >= start_time + 100) {
initialized = true;
}
}
}

View File

@ -17,25 +17,26 @@ class ContactPrinter {
const uint16_t baud = 115200;
/* PINS */
const uint8_t takeup_picture_pin_enable = 23;
const uint8_t takeup_picture_pin_cw = 22;
const uint8_t takeup_picture_pin_ccw = 21;
const uint8_t takeup_stock_pin_enable = 19;
const uint8_t takeup_stock_pin_cw = 18;
const uint8_t takeup_stock_pin_ccw = 5;
const uint8_t takeup_pin_enable = 21;
const uint8_t takeup_pin_dir_a = 22;
const uint8_t takeup_pin_dir_b = 23;
const uint8_t start_button_pin = 15;
/* MOTOR PWM */
const uint32_t pwm_frequency = 30000;
const uint8_t takeup_picture_pwm_channel = 1;
const uint8_t takeup_stock_pwm_channel = 2;
const uint32_t pwm_frequency = 5000;
const uint8_t takeup_pwm_channel = 1;
const uint8_t pwm_resolution = 8;
const uint16_t pwm_maximum = 255; //8 = 255, 16 = 65535
/* BUTTONS */
const uint16_t button_delay = 500;
/* MEMORY */
volatile long timer = 0;
volatile long start_time = 0;
volatile long run_time = 0;
volatile float drive_speed = 1.0; //calculated rpm
volatile float takeup_speed = 1.0; //estimated rpm
@ -52,12 +53,9 @@ class ContactPrinter {
volatile boolean takeup_ramping = false;
volatile bool takeup_picture_cw = false;
volatile bool takeup_picture_ccw = true;
volatile bool takeup_stock_cw = true;
volatile bool takeup_stock_ccw = true;
volatile bool takeup_dir = true;
volatile bool initialized = false;
volatile bool running = false;
public:
@ -70,8 +68,11 @@ class ContactPrinter {
void Stop();
void SetSpeedTakeup(float speed);
void SetSpeedDrive(float speed);
void SetDirectionStock(bool clockwise);
void SetDirectionPicture(bool clockwise);
void SetDirectionTakeup(bool dir);
void StartTakeup();
void StopTakeup();
void EnableTakeup();
void RampTakeup(uint16_t start, uint16_t end, uint16_t time);
void RampTakeupLoop();

View File

@ -21,6 +21,11 @@ void DriveMotor::Setup () {
pinMode(encoder_b_pin, INPUT);
ledcSetup(pwm_channel, pwm_frequency, pwm_resolution);
Serial.print("Attaching pin ");
Serial.print(enable_pin);
Serial.print(" to ledc channel ");
Serial.print(pwm_channel);
Serial.println(" for drive");
ledcAttachPin(enable_pin, pwm_channel);
ledcWrite(pwm_channel, pwm_duty_cycle);
@ -34,15 +39,14 @@ void DriveMotor::Start() {
digitalWrite(backward_pin, LOW);
}
void DriveMotor::Stop() {
pwm_duty_cycle = 0;
void DriveMotor::Stop() {;
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
ledcWrite(pwm_channel, pwm_duty_cycle);
ledcWrite(pwm_channel, 0);
}
void DriveMotor::SetSpeed(float speed) {
pwm_duty_cycle = floor(255 * speed);
pwm_duty_cycle = floor(pwm_maximum * speed);
Serial.print("Set drive motor PWM = ");
Serial.println(pwm_duty_cycle);
}

View File

@ -16,9 +16,10 @@ class DriveMotor {
volatile uint8_t pwm_duty_cycle = 0;
const uint32_t pwm_frequency = 30000;
const uint32_t pwm_frequency = 5000;
const uint8_t pwm_channel = 0;
const uint8_t pwm_resolution = 8;
const uint16_t pwm_maximum = 255; //8 = 255, 16 = 65535
const uint8_t ppr = 11;
const float ratio = 187.0 / 3.0;

View File

@ -1,6 +1,6 @@
#include "ContactPrinter.h";
#define VERSION "0.2.0"
#define VERSION "0"
/**
*
@ -9,23 +9,19 @@
*
* Pins
*
* 23 Takeup Picture Enable - set duty rate
* 22 Takeup Picture Clockwise
* 21 Takeup Picture Counter Clockwise
* 21 Takeup Picture Enable - set duty rate
* 22 Takeup Direction A - Stock Clockwise, Picture Counter Clockwise
* 23 Takeup Direction B - Stock Counter Clockwise, Picture Clockwise
*
* 19 Takeup Stock Enable - set duty rate
* 18 Takeup Stock Clockwise
* 5 Takeup Stock Counter Clockwise
*
* 13 Drive Enable
* 12 Drive Forward (Clockwise)
* 26 Drive Enable
* 27 Drive Forward (Clockwise)
* 14 Drive Backward (Counter Clockwise)
* 27 Drive Encoder A
* 26 Drive Encoder B
* 33 Drive Encoder A
* 25 Drive Encoder B
*
* 15 Start Button
*
* 33 Lamp
* 32 Lamp
*
**/
@ -33,10 +29,10 @@ ContactPrinter contact_printer;
void setup () {
Serial.begin(115200);
contact_printer.Setup();
Serial.print("contact_printer v");
Serial.println(VERSION);
contact_printer.Setup();
}
void loop () {
contact_printer.Loop();
}
}

View File

@ -6,9 +6,14 @@
*********/
// Motor A
int motor1Pin1 = 14;
int motor1Pin2 = 27;
int enable1Pin = 26;
//int motor1Pin1 = 14;
//int motor1Pin2 = 27;
//int enable1Pin = 26;
// Motor B
int motor1Pin1 = 5;
int motor1Pin2 = 18;
int enable1Pin = 19;
// Setting PWM properties
const int freq = 30000;

View File

@ -15,7 +15,7 @@ if [[ "${1}" == "major" ]]; then
elif [[ "${1}" == "minor" ]]; then
let "VERSION[1]=${VERSION[1]}+1"
let "VERSION[2]=0"
else; then
else
let "VERSION[2]=${VERSION[2]}+1"
fi