1
1
#include " umiusi/outputs.hpp"
2
2
#include " umiusi/defered_delay.hpp"
3
3
4
+ using namespace std ::chrono_literals;
5
+
4
6
Outputs::Outputs () :
5
7
init_status(INIT_PIN),
6
8
bldcs{ mbed::PwmOut (BLDC1_PIN),
@@ -29,7 +31,7 @@ void Outputs::deactivate() {
29
31
30
32
// / ESC の起動待ち
31
33
void Outputs::wake_up () {
32
- DeferedDelay _ (2000 );
34
+ DeferedDelay _ (2s );
33
35
for (mbed::PwmOut& bldc : this ->bldcs ) {
34
36
bldc.pulsewidth_us (100 );
35
37
}
@@ -55,3 +57,43 @@ void Outputs::reset() {
55
57
reset_pulsewidths_us{};
56
58
this ->set_powers (reset_pulsewidths_us);
57
59
}
60
+
61
+ void OutputMachine::set_state (State s) {
62
+ std::lock_guard _guard (this ->state_mutex );
63
+ this ->_state = s;
64
+ }
65
+
66
+ OutputMachine::OutputMachine () : outputs(), _state(State::SUSPEND), state_mutex() {}
67
+
68
+ auto OutputMachine::state () -> State {
69
+ std::lock_guard _guard (this ->state_mutex );
70
+ return this ->_state ;
71
+ }
72
+
73
+ void OutputMachine::set_powers (
74
+ const std::array<std::pair<uint16_t , uint16_t >, THRUSTER_NUM>& pulsewidths_us
75
+ ) {
76
+ if (this ->state () != State::RUNNING) {
77
+ return ;
78
+ }
79
+ this ->outputs .set_powers (pulsewidths_us);
80
+ }
81
+
82
+ void OutputMachine::suspend () {
83
+ this ->outputs .reset ();
84
+ this ->set_state (State::SUSPEND);
85
+ this ->outputs .deactivate ();
86
+ }
87
+
88
+ void OutputMachine::initialize () {
89
+ if (this ->state () == State::INITIALIZING) {
90
+ return ;
91
+ }
92
+ this ->set_state (State::INITIALIZING);
93
+ this ->outputs .reset ();
94
+ this ->outputs .setup ();
95
+ if (this ->state () == State::INITIALIZING) {
96
+ // setup前後で値が変化する可能性がある
97
+ this ->set_state (State::RUNNING);
98
+ }
99
+ }
0 commit comments