-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepper.cpp
74 lines (61 loc) · 1.47 KB
/
stepper.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Arduino.h"
#pragma push_macro("abs")
#undef abs
#include "stepper.h"
#include <algorithm>
namespace TwinsyStep
{
Stepper& Stepper::setMaxSpeed(int32_t speed)
{
vMax = constrain(speed, -vMaxMax, vMaxMax);
return *this;
}
Stepper& Stepper::setAcceleration(uint32_t a)
{
avMax = ((vMax*vMax)/2);
acc = std::min(a, avMax);
return *this;
}
void Stepper::rotateAsync(int32_t v)
{
StepperBase::startRotate(v == 0 ? vMax : v, acc);
}
void Stepper::moveAbsAsync(int32_t target, uint32_t v)
{
StepperBase::startMoveTo(target, 0, (v == 0 ? vMax : v), acc);
}
void Stepper::moveRelAsync(int32_t delta, uint32_t v)
{
StepperBase::startMoveTo(pos + delta, 0, (v == 0 ? std::abs(vMax) : v), acc);
}
void Stepper::stopAsync()
{
StepperBase::startStopping(0, acc);
}
void Stepper::moveAsync()
{
StepperBase::startMoveTo(target, 0, std::abs(vMax), acc);
}
void Stepper::moveAbs(int32_t target, uint32_t v)
{
moveAbsAsync(target, v);
while (isMoving)
{
delay(10);
}
}
void Stepper::moveRel(int32_t delta, uint32_t v)
{
moveRelAsync(delta, v);
while (isMoving)
{
delay(10);
}
}
void Stepper::stop()
{
StepperBase::startStopping(0, acc);
}
// void moveRelAsync(int delta);
// void moveRel(int delta);
}