-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse_runner_state.h
96 lines (70 loc) · 2.24 KB
/
mouse_runner_state.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "randomizing_functions_state.h"
#include "probe.h"
#include "warningTone.h"
#include "motor.h"
class MouseRunner
{
public:
//uint32_t globalStartTime;
struct StageParameters
{
// How long we'll run the mouse for in this stage.
uint32_t duration;
// How fast the motor will run during this stage.
float speed;
// The difference between the current stage's speed and the speed of the next stage.
float speed_difference;
// The accel for the current stage (the speed change at the beginning of the stage).
float accel;
// A marker for if this stage is a probe trial & what kind.
enum Probe probe;
};
int stageTotal;
private:
enum class State
{
// We're waiting for the initial starting signal
Waiting,
// We're running the mouse
Running,
// We're done running the mouse
Done,
};
enum State state = State::Waiting;
// Our stages
const struct StageParameters *stageParameters;
// When we started our last stage
uint32_t timeStageStarted;
// The stage we're currently handling
int currentStage = 0;
// Our motor
Motor &motor;
// Our warning tone object;
WarningTone &warningTone;
// Create flag for when the code first reaches the "Done" stage. Initialize as false.
bool everFinished = false;
private:
/**
* \brief Gets the time since a start time
*
* \param startTime
* The start time
*
* \return uint32_t
* The time since
*/
static inline uint32_t TimeElapsed(uint32_t startTime)
{
return (uint32_t)millis() - startTime;
}
void StartNextStage(void);
public:
MouseRunner(const struct StageParameters *stageParameters, Motor &motor, WarningTone &warningTone);
void Start(void);
void Stop(void);
void RunOnce(void);
void StartNewTrial(void);
};