-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASMC.h
205 lines (186 loc) · 6.37 KB
/
ASMC.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
//Created by jin on 8/30/2019
//
/*
* microstepping:
* 0 - Full
* 1 - Half
* 2 - 4 microstep
* 3 - 8 microstep
* 4 - 16 microstep
* 5 - 32 microstep
* 6 - 64 microstep
* 7 - 128 microstep
* 8 - 256 microstep
*/
#ifndef ASMC_ASMC_H
#define ASMC_ASMC_H
#include "SPI_DRV8711.h"
#include <Arduino.h>
#define NORMAL_RESPONSE -1
#define IDLE_RESPONSE 0
class ASMC {
public:
<<<<<<< HEAD
ASMC(int MotorNumber, float MotorCurrent, unsigned int max_speed, unsigned int min_speed, unsigned int home_speed, int microstepping, float lead, int sample_time_BEMF = 7, int stall_detection_count = 3, int stall_detection_threshold = 0, bool newboard=false);
=======
ASMC(int MotorNumber, float MotorCurrent, unsigned int max_speed, unsigned int min_speed, unsigned int home_speed, int microstepping, float lead,
int sample_time_BEMF = 7, int stall_detection_count = 3, int stall_detection_threshold = 0, bool newboard=false);
>>>>>>> 61168442869cac98de01d168e7409d146f666fae
public:
void BootUpSPI();
void Begin(unsigned int max_speed, unsigned int min_speed, unsigned int home_speed);
void InitializeMotors();
void Run(float target_position_mm);
int isrPulse_TIMER1();
int isrPulse_TIMER3();
int isrPulse_TIMER4();
int isrPulse_TIMER5();
void Home(float HomeDistance = -30000);
void ReverseHome(float HomeDistance = 30000);
void SupportHome(float support_home_distance = -30000);
void SwitchDirection();
void SetDirection();
void GetDirection();
bool CheckAtHome();
void SetAtHome();
void SetCurrentPosition(float position);
float GetCurrentPosition();
float GetTargetPosition();
void ResetMotors();
void PumpHome(float HomeDistance = -1100);
public:
int _STEP = 0;
int _DIR = 0;
int _SS = 0;
int _SLEEP = 0;
int _STLFLT = 0;
float _MCURRENT = 0;
int _HOME = 0;
int _RESET = 48;
int _MECHANICAL_HOME = 12;
int _motor_number = 0;
int _max_speed = 0; //max speed, unit = step/s
int _min_speed = 0;
<<<<<<< HEAD
int _mid_speed_1 = 0;
int _mid_speed_2 = 0;
=======
>>>>>>> 61168442869cac98de01d168e7409d146f666fae
int _home_speed = 0;
int POSITIVE = 1;
int NEGATIVE = 0;
int _sampling_time_BEMF = 7; //0: 50us, 1: 100us, 2: 200us, 3: 300us, 4: 400us, 5: 600us, 6: 800us, 7: 1000us
int _stall_detection_count = 3; //0~3
int _stall_detection_threshold = 0; //0~255
int _status = 0; // status of motor
<<<<<<< HEAD
int _DOUBLE_CHECK_HOME_1 = A8;
int _DOUBLE_CHECK_HOME_2 = A9;
=======
>>>>>>> 61168442869cac98de01d168e7409d146f666fae
private:
unsigned long _OCR_max_speed = 0;
unsigned long _OCR_min_speed = 0;
unsigned long _OCR_mid_speed_1 = 0;
unsigned long _OCR_mid_speed_2 = 0;
unsigned long _OCR_mid_speed_3 = 0;
unsigned long _OCR_mid_speed_4 = 0;
unsigned long _OCR_Update = 0;
unsigned long _OCR_home = 0;
int _is_acceleration = 1; //acceleration: 1, no acceleration: 0
float _acceleration_section_step_1 = 50;
float _acceleration_section_step_2 = 100;
float _acceleration_section_step_3 = 200;
float _acceleration_section_step_4 = 300;
float _acceleration_section_step_5 = 400;
float _deceleration_position_1 = 0;
float _deceleration_position_2 = 0;
float _deceleration_position_3 = 0;
float _deceleration_position_4 = 0;
float _deceleration_position_5 = 0;
int _count_moving_step = 0;
float _current_position = 0;
float _target_position = 0;
float _distance = 0; //_target_position - _current_position
float _abs_distance = 0;
float _lead_one_step = 0;
bool isHoming = false;
bool isPumpHoming = false;
int _positive_direction = 1; // positive: 1, negative: 0
unsigned int _microstepping = 0; //full-step
//public:
// int _STEP = 0;
// int _DIR = 0;
// int _SS = 0;
// int _SLEEP = 0;
// int _STLFLT = 0;
// float _MCURRENT = 0;
// int _HOME = 0;
// int _RESET = 48;
// const int _SPI_MISO = 50;//51; // Master Input Slave Output
// const int _SPI_SCK = 52;//53; // Synchronous Clock
// const int _SPI_MOSI = 51;//50; // Master Output Slave Input
// int _MECHANICAL_HOME = 12;
// int _motor_number = 0;
// int _max_speed = 0; //max speed, unit = step/s
// int _min_speed = 0;
// int _mid_speed_1 = 0;
// int _mid_speed_2 = 0;
// int _home_speed = 0;
// int POSITIVE = 1;
// int NEGATIVE = 0;
// int _sampling_time_BEMF = 7; //0: 50us, 1: 100us, 2: 200us, 3: 300us, 4: 400us, 5: 600us, 6: 800us, 7: 1000us
// int _stall_detection_count = 3; //0~3
// int _stall_detection_threshold = 0; //0~255
// int _status = 0; // status of motor
// int _DOUBLE_CHECK_HOME_1 = A8;
// int _DOUBLE_CHECK_HOME_2 = A9;
<<<<<<< HEAD
private:
const int _MAX_MOTOR_SPEED = 7000; //OCR: 285
const int _MIN_MOTOR_SPEED = 35; //OCR: 62500
const unsigned long _CLOCK_FREQUENCY_IO = 2000000;
const int _MIN_SPEED_OCR = 62500;
const int _MAX_SPEED_OCR = 3500;
=======
//
//private:
// int _FULL_STEP_PER_REVOLUTION = 200;
// unsigned long _OCR_max_speed = 0;
// unsigned long _OCR_min_speed = 0;
// unsigned long _OCR_mid_speed_1 = 0;
// unsigned long _OCR_mid_speed_2 = 0;
// unsigned long _OCR_Update = 0;
// unsigned long _OCR_home = 0;
// int _is_acceleration = 1; //acceleration: 1, no acceleration: 0
// float _acceleration_section_step_1 = 50;
// float _acceleration_section_step_2 = 100;
// float _acceleration_section_step_3 = 200;
// float _deceleration_position_1 = 0;
// float _deceleration_position_2 = 0;
// float _deceleration_position_3 = 0;
// int _count_moving_step = 0;
// float _current_position = 0;
// float _target_position = 0;
// float _distance = 0; //_target_position - _current_position
// float _abs_distance = 0;
// float _lead = 0;
// float _lead_one_step = 0;
// bool _sensing = false;
// bool isHoming = false;
// bool isPumpHoming = false;
// bool min_speed_mode = false;
// int _positive_direction = 1; // positive: 1, negative: 0
// unsigned int _microstepping = 0; //full-step
//
//
//private:
// const int _MAX_MOTOR_SPEED = 7000; //OCR: 285
// const int _MIN_MOTOR_SPEED = 35; //OCR: 62500
// const unsigned long _CLOCK_FREQUENCY_IO = 2000000;
// const int _MIN_SPEED_OCR = 62500;
// const int _MAX_SPEED_OCR = 3500;
>>>>>>> 61168442869cac98de01d168e7409d146f666fae
};
#endif //ASMC_ASMC_H