From eb3c920d2d6b916ef91d30892861e1c2450a368e Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 1 Feb 2024 11:40:38 -0500 Subject: [PATCH] Project compiles now with scripts/compile.sh and in the IDE --- ino/contact_printer/ContactPrinter.cpp | 27 +++++++++++++++++--------- ino/contact_printer/ContactPrinter.h | 13 ++++++++++--- ino/contact_printer/EncoderMotor.cpp | 3 +++ scripts/compile.sh | 14 +++++++++++++ 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 scripts/compile.sh diff --git a/ino/contact_printer/ContactPrinter.cpp b/ino/contact_printer/ContactPrinter.cpp index 4e882b6..bfee312 100644 --- a/ino/contact_printer/ContactPrinter.cpp +++ b/ino/contact_printer/ContactPrinter.cpp @@ -13,6 +13,15 @@ void ContactPrinter::Setup () { drive_motor.Setup(); + ledcSetup(takeup_picture_pwm_channel, pwm_frequency, pwm_resolution); + ledcSetup(takeup_stock_pwm_channel, pwm_frequency, pwm_resolution); + + ledcAttachPin(takeup_picture_pin_enable, takeup_picture_pwm_channel); + ledcAttachPin(takeup_stock_pin_enable, takeup_stock_pwm_channel); + + 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); @@ -20,7 +29,7 @@ void ContactPrinter::Setup () { } void ContactPrinter::Start () { - RampTakeup(0, takeup_pwm, takeup_ramp_time); + RampTakeup(0, takeup_pwm_duty_cycle, takeup_ramp_time); delay(100); //drive_motor.Start(); } @@ -28,13 +37,13 @@ void ContactPrinter::Start () { void ContactPrinter::Stop () { //drive_motor.Start(); delay(100); - RampTakeup(takeup_pwm, 0, takeup_ramp_time); + RampTakeup( takeup_pwm_duty_cycle, 0, takeup_ramp_time); } void ContactPrinter::SetSpeedTakeup(float speed) { takeup_speed = speed; - takeup_pwm = round(speed * 255); + takeup_pwm_duty_cycle = floor(speed * 255); } void ContactPrinter::SetSpeedDrive(float speed) { @@ -60,25 +69,25 @@ void ContactPrinter::RampTakeup(uint16_t start, uint16_t end, uint16_t time) { if (takeup_picture_cw) { takeup_picture_pin = takeup_picture_pin_cw; - analogWrite(takeup_picture_pin_ccw, 0); + //analogWrite(takeup_picture_pin_ccw, 0); } else { takeup_picture_pin = takeup_picture_pin_ccw; - analogWrite(takeup_picture_pin_cw, 0); + //analogWrite(takeup_picture_pin_cw, 0); } if (takeup_stock_cw) { takeup_stock_pin = takeup_stock_pin_cw; - analogWrite(takeup_stock_pin_ccw, 0); + //analogWrite(takeup_stock_pin_ccw, 0); } else { takeup_stock_pin = takeup_stock_pin_cw; - analogWrite(takeup_stock_pin_cw, 0); + //analogWrite(takeup_stock_pin_cw, 0); } for (uint16_t i = 0; i < steps; i++) { if (pwm <= 0 || pwm >= 256) { break; } - analogWrite(takeup_picture_pin, pwm); - analogWrite(takeup_stock_pin, pwm); + //analogWrite(takeup_picture_pin, pwm); + //analogWrite(takeup_stock_pin, pwm); delay(step); if (dir) { pwm++; diff --git a/ino/contact_printer/ContactPrinter.h b/ino/contact_printer/ContactPrinter.h index 929f1e8..b970ee5 100644 --- a/ino/contact_printer/ContactPrinter.h +++ b/ino/contact_printer/ContactPrinter.h @@ -11,18 +11,25 @@ class ContactPrinter { EncoderMotor drive_motor; const uint16_t serial_delay = 5; - const uint16_t baud = 57600; + const uint16_t baud = 115200; + const uint8_t takeup_picture_pin_enable = 7; const uint8_t takeup_picture_pin_cw = 8; const uint8_t takeup_picture_pin_ccw = 9; + + const uint8_t takeup_stock_pin_enable = 12; const uint8_t takeup_stock_pin_cw = 10; const uint8_t takeup_stock_pin_ccw = 11; + const uint32_t pwm_frequency = 30000; + const uint8_t takeup_picture_pwm_channel = 1; + const uint8_t takeup_stock_pwm_channel = 2; + const uint8_t pwm_resolution = 8; + volatile float drive_speed = 1.0; //calculated rpm volatile float takeup_speed = 1.0; //estimated rpm - volatile uint16_t drive_pwm; - volatile uint16_t takeup_pwm; + volatile uint16_t takeup_pwm_duty_cycle = 255; volatile bool takeup_picture_cw = false; volatile bool takeup_picture_ccw = true; diff --git a/ino/contact_printer/EncoderMotor.cpp b/ino/contact_printer/EncoderMotor.cpp index 13e4def..3d7dda3 100644 --- a/ino/contact_printer/EncoderMotor.cpp +++ b/ino/contact_printer/EncoderMotor.cpp @@ -20,4 +20,7 @@ void EncoderMotor::Setup () { ledcSetup(pwm_channel, pwm_frequency, pwm_resolution); ledcAttachPin(enable_pin, pwm_channel); ledcWrite(pwm_channel, pwm_duty_cycle); + + digitalWrite(forward_pin, LOW); + digitalWrite(backward_pin, LOW); } diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100644 index 0000000..386002b --- /dev/null +++ b/scripts/compile.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +FQBN=esp32:esp32:esp32 #ESP32 + +INO="./ino/contact_printer" +INOFILE="${INO}/contact_printer.ino" +OUTPUT="./bin" + +mkdir -p "${OUTPUT}" + +#esp32 +arduino-cli compile --fqbn ${FQBN} --output-dir "${OUTPUT}" "${INO}" || echo 'Compile failed' && exit 1