Compare commits

..

3 Commits

5 changed files with 63 additions and 38 deletions

View File

@ -106,5 +106,6 @@ bool ContactPrinter::IsRunning () {
} }
void ContactPrinter::Loop () { void ContactPrinter::Loop () {
timer = millis();
drive_motor.Loop(); drive_motor.Loop();
} }

View File

@ -2,13 +2,14 @@
#define CONTACT_PRINTER #define CONTACT_PRINTER
#include <Arduino.h> #include <Arduino.h>
#include "EncoderMotor.h" #include "DriveMotor.h"
class ContactPrinter { class ContactPrinter {
private: private:
EncoderMotor drive_motor; //use default drive motor pins
DriveMotor drive_motor;
const uint16_t serial_delay = 5; const uint16_t serial_delay = 5;
const uint16_t baud = 115200; const uint16_t baud = 115200;
@ -26,6 +27,8 @@ class ContactPrinter {
const uint8_t takeup_stock_pwm_channel = 2; const uint8_t takeup_stock_pwm_channel = 2;
const uint8_t pwm_resolution = 8; const uint8_t pwm_resolution = 8;
volatile long timer = 0;
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

View File

@ -0,0 +1,45 @@
#include "DriveMotor.h"
DriveMotor::DriveMotor () {
};
DriveMotor::DriveMotor (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 DriveMotor::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);
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
}
void DriveMotor::Start() {
ledcWrite(pwm_channel, pwm_duty_cycle);
digitalWrite(forward_pin, HIGH);
digitalWrite(backward_pin, LOW);
}
void DriveMotor::Stop() {
pwm_duty_cycle = 0;
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
ledcWrite(pwm_channel, pwm_duty_cycle);
}
void DriveMotor::SetSpeed() {
pwm_duty_cycle = 255;
}
void DriveMotor::Loop () {
//monitor speed
}

View File

@ -1,9 +1,9 @@
#ifndef ENCODER_MOTOR #ifndef DRIVE_MOTOR
#define ENCODER_MOTOR #define DRIVE_MOTOR
#include <Arduino.h> #include <Arduino.h>
class EncoderMotor { class DriveMotor {
private: private:
@ -14,16 +14,22 @@ class EncoderMotor {
volatile uint8_t encoder_a_pin = 27; volatile uint8_t encoder_a_pin = 27;
volatile uint8_t encoder_b_pin = 26; volatile uint8_t encoder_b_pin = 26;
volatile uint8_t pwm_duty_cycle = 255; volatile uint8_t pwm_duty_cycle = 0;
const uint32_t pwm_frequency = 30000; const uint32_t pwm_frequency = 30000;
const uint8_t pwm_channel = 0; const uint8_t pwm_channel = 0;
const uint8_t pwm_resolution = 8; const uint8_t pwm_resolution = 8;
const uint8_t ppr = 11;
const float ratio = 187.0 / 3.0;
const uint32_t maxPulses = (int) round((float) ppr * ratio);
const uint8_t speed = 255;
const uint8_t framesPerRotation = 18;
public: public:
EncoderMotor(); DriveMotor();
EncoderMotor(uint8_t e_pin, uint8_t f_pin, uint8_t b_pin, uint8_t ea_pin, uint8_t eb_pin); DriveMotor(uint8_t e_pin, uint8_t f_pin, uint8_t b_pin, uint8_t ea_pin, uint8_t eb_pin);
void Setup(); void Setup();
void Loop(); void Loop();
void Start(); void Start();

View File

@ -1,30 +0,0 @@
#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);
digitalWrite(forward_pin, LOW);
digitalWrite(backward_pin, LOW);
}
void EncoderMotor::Loop () {
}