Project compiles now with scripts/compile.sh and in the IDE

This commit is contained in:
Matt McWilliams 2024-02-01 11:40:38 -05:00
parent 03e8df9617
commit eb3c920d2d
4 changed files with 45 additions and 12 deletions

View File

@ -13,6 +13,15 @@ void ContactPrinter::Setup () {
drive_motor.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_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);
@ -20,7 +29,7 @@ void ContactPrinter::Setup () {
} }
void ContactPrinter::Start () { void ContactPrinter::Start () {
RampTakeup(0, takeup_pwm, takeup_ramp_time); RampTakeup(0, takeup_pwm_duty_cycle, takeup_ramp_time);
delay(100); delay(100);
//drive_motor.Start(); //drive_motor.Start();
} }
@ -28,13 +37,13 @@ void ContactPrinter::Start () {
void ContactPrinter::Stop () { void ContactPrinter::Stop () {
//drive_motor.Start(); //drive_motor.Start();
delay(100); delay(100);
RampTakeup(takeup_pwm, 0, takeup_ramp_time); RampTakeup( takeup_pwm_duty_cycle, 0, takeup_ramp_time);
} }
void ContactPrinter::SetSpeedTakeup(float speed) { void ContactPrinter::SetSpeedTakeup(float speed) {
takeup_speed = speed; takeup_speed = speed;
takeup_pwm = round(speed * 255); takeup_pwm_duty_cycle = floor(speed * 255);
} }
void ContactPrinter::SetSpeedDrive(float speed) { 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) { if (takeup_picture_cw) {
takeup_picture_pin = takeup_picture_pin_cw; takeup_picture_pin = takeup_picture_pin_cw;
analogWrite(takeup_picture_pin_ccw, 0); //analogWrite(takeup_picture_pin_ccw, 0);
} else { } else {
takeup_picture_pin = takeup_picture_pin_ccw; takeup_picture_pin = takeup_picture_pin_ccw;
analogWrite(takeup_picture_pin_cw, 0); //analogWrite(takeup_picture_pin_cw, 0);
} }
if (takeup_stock_cw) { if (takeup_stock_cw) {
takeup_stock_pin = takeup_stock_pin_cw; takeup_stock_pin = takeup_stock_pin_cw;
analogWrite(takeup_stock_pin_ccw, 0); //analogWrite(takeup_stock_pin_ccw, 0);
} else { } else {
takeup_stock_pin = takeup_stock_pin_cw; 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++) { for (uint16_t i = 0; i < steps; i++) {
if (pwm <= 0 || pwm >= 256) { if (pwm <= 0 || pwm >= 256) {
break; break;
} }
analogWrite(takeup_picture_pin, pwm); //analogWrite(takeup_picture_pin, pwm);
analogWrite(takeup_stock_pin, pwm); //analogWrite(takeup_stock_pin, pwm);
delay(step); delay(step);
if (dir) { if (dir) {
pwm++; pwm++;

View File

@ -11,18 +11,25 @@ class ContactPrinter {
EncoderMotor drive_motor; EncoderMotor drive_motor;
const uint16_t serial_delay = 5; 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_cw = 8;
const uint8_t takeup_picture_pin_ccw = 9; 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_cw = 10;
const uint8_t takeup_stock_pin_ccw = 11; 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 drive_speed = 1.0; //calculated rpm
volatile float takeup_speed = 1.0; //estimated rpm volatile float takeup_speed = 1.0; //estimated rpm
volatile uint16_t drive_pwm; volatile uint16_t takeup_pwm_duty_cycle = 255;
volatile uint16_t takeup_pwm;
volatile bool takeup_picture_cw = false; volatile bool takeup_picture_cw = false;
volatile bool takeup_picture_ccw = true; volatile bool takeup_picture_ccw = true;

View File

@ -20,4 +20,7 @@ void EncoderMotor::Setup () {
ledcSetup(pwm_channel, pwm_frequency, pwm_resolution); ledcSetup(pwm_channel, pwm_frequency, pwm_resolution);
ledcAttachPin(enable_pin, pwm_channel); ledcAttachPin(enable_pin, pwm_channel);
ledcWrite(pwm_channel, pwm_duty_cycle); ledcWrite(pwm_channel, pwm_duty_cycle);
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
} }

14
scripts/compile.sh Normal file
View File

@ -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