Create EncoderMotor.cpp. Compiler error on analogWrite using ESP32 build target. Without it the ledc* functions are unavailable. Will pull ESP32 build process over from meterlite.
This commit is contained in:
parent
20d37eb1e6
commit
6321367c97
|
@ -1,18 +1,18 @@
|
|||
#include "ContactPrinter.h"
|
||||
|
||||
ContactPrinter::ContactPrinter () {
|
||||
SetDriveSpeed(drive_speed);
|
||||
SetSpeedDrive(drive_speed);
|
||||
SetSpeedTakeup(takeup_speed);
|
||||
}
|
||||
|
||||
void ContactPrinter::Setup () {
|
||||
pinMode(drive_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);
|
||||
drive_motor.Setup();
|
||||
|
||||
digitalWrite(takeup_picture_pin_cw, LOW);
|
||||
digitalWrite(takeup_picture_pin_ccw, LOW);
|
||||
digitalWrite(takeup_stock_pin_cw, LOW);
|
||||
|
@ -22,11 +22,11 @@ void ContactPrinter::Setup () {
|
|||
void ContactPrinter::Start () {
|
||||
RampTakeup(0, takeup_pwm, takeup_ramp_time);
|
||||
delay(100);
|
||||
analogWrite(drive_pin, drive_pwm);
|
||||
//drive_motor.Start();
|
||||
}
|
||||
|
||||
void ContactPrinter::Stop () {
|
||||
analogWrite(drive_pin, 0);
|
||||
//drive_motor.Start();
|
||||
delay(100);
|
||||
RampTakeup(takeup_pwm, 0, takeup_ramp_time);
|
||||
|
||||
|
@ -38,8 +38,7 @@ void ContactPrinter::SetSpeedTakeup(float speed) {
|
|||
}
|
||||
|
||||
void ContactPrinter::SetSpeedDrive(float speed) {
|
||||
drive_speed = speed;
|
||||
drive_pwm = round(speed * 255);
|
||||
//drive_motor.SetSpeed();
|
||||
}
|
||||
|
||||
void ContactPrinter::SetDirectionStock(bool clockwise) {
|
||||
|
|
|
@ -2,21 +2,24 @@
|
|||
#define CONTACT_PRINTER
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "EncoderMotor.h"
|
||||
|
||||
class ContactPrinter {
|
||||
|
||||
private:
|
||||
|
||||
EncoderMotor drive_motor;
|
||||
|
||||
const uint16_t serial_delay = 5;
|
||||
const uint16_t baud = 57600;
|
||||
const uint8_t drive_pin = 7;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
@ -24,6 +27,9 @@ class ContactPrinter {
|
|||
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 uint16_t takeup_ramp_time = 500;
|
||||
|
||||
volatile bool running = false;
|
||||
|
@ -33,6 +39,7 @@ class ContactPrinter {
|
|||
ContactPrinter();
|
||||
|
||||
void Setup();
|
||||
void Loop();
|
||||
void Start();
|
||||
void Stop();
|
||||
void SetSpeedTakeup(float speed);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#include "EncoderMotor.h"
|
||||
|
||||
EncoderMotor::EncoderMotor () {
|
||||
|
||||
};
|
||||
|
||||
EncoderMotor::EncoderMotor (uint8_t e_pin, uint8_t f_pin, uint8_t b_pin, uint8_t ea_pin, uint8_t eb_pin) {
|
||||
enable_pin = e_pin;
|
||||
forward_pin = f_pin;
|
||||
backward_pin = b_pin;
|
||||
encoder_a_pin = ea_pin;
|
||||
encoder_b_pin = eb_pin;
|
||||
};
|
||||
|
||||
void EncoderMotor::Setup () {
|
||||
pinMode(enable_pin, OUTPUT);
|
||||
pinMode(forward_pin, OUTPUT);
|
||||
pinMode(backward_pin, OUTPUT);
|
||||
|
||||
ledcSetup(pwm_channel, pwm_frequency, pwm_resolution);
|
||||
ledcAttachPin(enable_pin, pwm_channel);
|
||||
ledcWrite(pwm_channel, pwm_duty_cycle);
|
||||
}
|
|
@ -6,15 +6,29 @@
|
|||
class EncoderMotor {
|
||||
|
||||
private:
|
||||
uint8_t enable_pin;
|
||||
uint8_t forward_pin;
|
||||
uint8_t backward_pin;
|
||||
uint8_t pwm_duty_speed = 255;
|
||||
uint32_t pwm_frequency = 30000;
|
||||
|
||||
//defaults are for EPS32 dev board
|
||||
volatile uint8_t enable_pin = 13;
|
||||
volatile uint8_t forward_pin = 12;
|
||||
volatile uint8_t backward_pin = 14;
|
||||
volatile uint8_t encoder_a_pin = 27;
|
||||
volatile uint8_t encoder_b_pin = 26;
|
||||
|
||||
volatile uint8_t pwm_duty_cycle = 255;
|
||||
|
||||
const uint32_t pwm_frequency = 30000;
|
||||
const uint8_t pwm_channel = 0;
|
||||
const uint8_t pwm_resolution = 8;
|
||||
|
||||
public:
|
||||
|
||||
EncoderMotor();
|
||||
EncoderMotor(uint8_t e_pin, uint8_t f_pin, uint8_t b_pin, uint8_t ea_pin, uint8_t eb_pin);
|
||||
void Setup();
|
||||
void Loop();
|
||||
void Start();
|
||||
void Stop();
|
||||
void SetSpeed();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue