mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
use atmega32 to control stepper motors
Signed-off-by: Stepan Usatyuk <usaatyuk@ustk.me>
This commit is contained in:
33
Firmware/MotorControl/include/Globals.h
Normal file
33
Firmware/MotorControl/include/Globals.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include "Pen.h"
|
||||
#include "Stepper.h"
|
||||
|
||||
#ifndef GLOBALS_H
|
||||
#define GLOBALS_H
|
||||
|
||||
#define EGG_DIA 35.0
|
||||
#define Y_DEGREES_PER_MM (360 / (PI * EGG_DIA))
|
||||
|
||||
#define X_LIMIT 70.0
|
||||
#define EGG_LENGTH 50.0
|
||||
#define X_DEGREES_PER_MM (X_LIMIT / EGG_LENGTH)
|
||||
|
||||
#define STEPS_PER_REVOLUTION 4076
|
||||
#define DEF_RPM 2
|
||||
|
||||
Stepper eggStepper(28, 29, 30, 31, STEPS_PER_REVOLUTION, 0, Y_DEGREES_PER_MM);
|
||||
Stepper servoStepper(24, 25, 26, 27, -STEPS_PER_REVOLUTION, X_LIMIT,
|
||||
X_DEGREES_PER_MM);
|
||||
|
||||
Pen pen(23, 100, 150);
|
||||
|
||||
float eggStepperDelay;
|
||||
float servoStepperDelay;
|
||||
|
||||
float eggStepperRPM;
|
||||
float servoStepperRPM;
|
||||
|
||||
bool recalculateDelays;
|
||||
bool needAdjust;
|
||||
|
||||
#endif
|
||||
22
Firmware/MotorControl/include/Pen.h
Normal file
22
Firmware/MotorControl/include/Pen.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <Servo.h>
|
||||
|
||||
#ifndef PEN_H
|
||||
#define PEN_H
|
||||
|
||||
class Pen {
|
||||
private:
|
||||
int posEngaged;
|
||||
int posDisengaged;
|
||||
bool engaged = true;
|
||||
Servo servo;
|
||||
|
||||
public:
|
||||
Pen(int pin, int posEngaged, int posDisengaged);
|
||||
void engage();
|
||||
void disengage();
|
||||
void init();
|
||||
bool getEngaged();
|
||||
~Pen();
|
||||
};
|
||||
|
||||
#endif
|
||||
39
Firmware/MotorControl/include/README
Normal file
39
Firmware/MotorControl/include/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
39
Firmware/MotorControl/include/Stepper.h
Normal file
39
Firmware/MotorControl/include/Stepper.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef STEPPER_H
|
||||
#define STEPPER_H
|
||||
|
||||
class Stepper {
|
||||
private:
|
||||
int stepsPerRevolution;
|
||||
unsigned int pin1;
|
||||
unsigned int pin2;
|
||||
unsigned int pin3;
|
||||
unsigned int pin4;
|
||||
unsigned int curStep = 1;
|
||||
unsigned int remainingSteps;
|
||||
float degreesPerMM;
|
||||
bool direction;
|
||||
void clockwise();
|
||||
void counterClockwise();
|
||||
float pos = 0;
|
||||
int limit;
|
||||
|
||||
public:
|
||||
Stepper(int pin1, int pin2, int pin3, int pin4, int stepsPerRevolution,
|
||||
int limit, float degreesPerMM);
|
||||
void step(int steps);
|
||||
int getRemainingSteps();
|
||||
void rotate(float degrees);
|
||||
void rotateTo(float degrees);
|
||||
void moveTo(float dist);
|
||||
void setPos(float degrees);
|
||||
float getDist(float degrees);
|
||||
int degreesToSteps(float degrees);
|
||||
int mmToSteps(float dist);
|
||||
void doStep();
|
||||
bool finished();
|
||||
float getPos();
|
||||
float getPosMm();
|
||||
float getDistMm(float pos);
|
||||
};
|
||||
|
||||
#endif
|
||||
1
Firmware/MotorControl/include/common
Symbolic link
1
Firmware/MotorControl/include/common
Symbolic link
@@ -0,0 +1 @@
|
||||
../../common
|
||||
Reference in New Issue
Block a user