-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepper.h
58 lines (46 loc) · 2.54 KB
/
stepper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "stepperbase.h"
namespace TwinsyStep
{
class Stepper : public StepperBase
{
public:
Stepper(int stepPin, int dirPin)
: StepperBase(stepPin, dirPin)
{}
int32_t getPosition() const { return pos; }
void setPosition(int32_t p) { pos = p; }
Stepper& setMaxSpeed(int32_t speed); // steps/s
// StepperBase& setVStart(int32_t vIn); // steps/s
// StepperBase& setVStop(int32_t vIn); // steps/s
Stepper& setAcceleration(uint32_t _a); // steps/s^2
//
void setTargetAbs(int32_t pos) { target = pos; }; // Set target position absolute
// void setTargetRel(int32_t delta); // Set target position relative to current position
void moveAsync();
void moveAbsAsync(int32_t target, uint32_t v = 0);
void moveAbs(int32_t target, uint32_t v = 0);
void moveRelAsync(int32_t delta, uint32_t v = 0);
void moveRel(int32_t delta, uint32_t v = 0);
void rotateAsync(int32_t v = 0);
void stopAsync();
void stop();
int32_t vMax = vMaxDefault;
uint32_t acc = aDefault;
uint32_t avMax;
// uint32_t s_t = 0;
protected:
static constexpr int32_t vMaxMax = 100'000; // largest speed possible (steps/s)
static constexpr uint32_t aMax = 999'999; // speed up to 500kHz within 1 s (steps/s^2)
static constexpr uint32_t vMaxDefault = 1'000; // should work with every motor (1 rev/sec in 1/4-step mode)
static constexpr uint32_t vStartDefault = 100; // start speed
static constexpr uint32_t vStopDefault = 100; // stop speed
static constexpr uint32_t aDefault = 1'000; // reasonably low (~1s for reaching the default speed)
friend class StepperGroup;
// compare functions
// static bool cmpDelta(const StepperBase* a, const StepperBase* b) { return a->A > b->A; }
// static bool cmpAcc(const StepperBase* a, const StepperBase* b) { return a->a < b->a; }
// static bool cmpVmin(const StepperBase* a, const StepperBase* b) { return std::abs(a->vMax) < std::abs(b->vMax); }
// static bool cmpVmax(const StepperBase* a, const StepperBase* b) { return std::abs(a->vMax) > std::abs(b->vMax); }
};
}