-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteppergroup.h
68 lines (57 loc) · 2.02 KB
/
steppergroup.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
59
60
61
62
63
64
65
66
67
68
#pragma once
#include "stepper.h"
#include "steppergroupbase.h"
#include <algorithm>
#include <vector>
namespace TwinsyStep
{
class StepperGroup : public StepperGroupBase
{
public:
// construction ---------------------------------------------------------------------------------
StepperGroup() = default;
StepperGroup(Stepper* arr[], size_t n) { add(arr, n); }
StepperGroup(std::initializer_list<std::reference_wrapper<Stepper>> stepperList) { add(stepperList); }
// add and remove steppers ----------------------------------------------------------------------------
void add(Stepper& s) { add(&s); }
void add(Stepper* s) { steppers.push_back(s); }
void add(std::initializer_list<std::reference_wrapper<Stepper>> stepperList)
{
for (auto& s : stepperList)
{
add(s.get());
}
}
void add(Stepper* arr[], size_t n)
{
for (unsigned i = 0; i < n; i++)
{
add(arr[i]);
}
}
void remove(Stepper& s) { remove(&s); }
void remove(Stepper* s) { steppers.erase(std::remove(steppers.begin(), steppers.end(), s), steppers.end()); }
void clear() { steppers.clear(); }
void move()
{
startMove(); // start movement in the background
while (1) // wait until all steppers have stopped
{
delay(1);
bool done = true;
for (auto stepper : steppers)
{
if (stepper->isMoving)
done = false;
}
if (done) break;
}
}
// void rotateAsync(int32_t v1, int32_t, v2)
// {
// unsigned a2 = steppers[0]->acc *steppers[1]->vMax/steppers[0]->vMax;
// steppers[0]->rotateAsyncB(steppers[0]->vMax, steppers[0]->acc);
// steppers[1]->rotateAsyncB(steppers[1]->vMax, a2);
// }
};
}