Compare commits
No commits in common. "c036aad6cb04242a3b068faeb080509e473e91ef" and "1c1978107df78adeb58e444eea2a11c2f82660f7" have entirely different histories.
c036aad6cb
...
1c1978107d
|
@ -106,6 +106,5 @@ bool ContactPrinter::IsRunning () {
|
|||
}
|
||||
|
||||
void ContactPrinter::Loop () {
|
||||
timer = millis();
|
||||
drive_motor.Loop();
|
||||
}
|
|
@ -2,14 +2,13 @@
|
|||
#define CONTACT_PRINTER
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "DriveMotor.h"
|
||||
#include "EncoderMotor.h"
|
||||
|
||||
class ContactPrinter {
|
||||
|
||||
private:
|
||||
|
||||
//use default drive motor pins
|
||||
DriveMotor drive_motor;
|
||||
EncoderMotor drive_motor;
|
||||
|
||||
const uint16_t serial_delay = 5;
|
||||
const uint16_t baud = 115200;
|
||||
|
@ -27,8 +26,6 @@ class ContactPrinter {
|
|||
const uint8_t takeup_stock_pwm_channel = 2;
|
||||
const uint8_t pwm_resolution = 8;
|
||||
|
||||
volatile long timer = 0;
|
||||
|
||||
volatile float drive_speed = 1.0; //calculated rpm
|
||||
volatile float takeup_speed = 1.0; //estimated rpm
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
#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
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#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 () {
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef DRIVE_MOTOR
|
||||
#define DRIVE_MOTOR
|
||||
#ifndef ENCODER_MOTOR
|
||||
#define ENCODER_MOTOR
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class DriveMotor {
|
||||
class EncoderMotor {
|
||||
|
||||
private:
|
||||
|
||||
|
@ -14,22 +14,16 @@ class DriveMotor {
|
|||
volatile uint8_t encoder_a_pin = 27;
|
||||
volatile uint8_t encoder_b_pin = 26;
|
||||
|
||||
volatile uint8_t pwm_duty_cycle = 0;
|
||||
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;
|
||||
|
||||
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:
|
||||
|
||||
DriveMotor();
|
||||
DriveMotor(uint8_t e_pin, uint8_t f_pin, uint8_t b_pin, uint8_t ea_pin, uint8_t eb_pin);
|
||||
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();
|
Loading…
Reference in New Issue