@@ -156,25 +156,31 @@ int BLDCMotor::initFOC() {
156
156
// added the shaft_angle update
157
157
sensor->update ();
158
158
shaft_angle = shaftAngle ();
159
- }else {
160
- exit_flag = 0 ; // no FOC without sensor
161
- SIMPLEFOC_DEBUG (" MOT: No sensor." );
162
- }
163
159
164
- // aligning the current sensor - can be skipped
165
- // checks if driver phases are the same as current sense phases
166
- // and checks the direction of measuremnt.
167
- if (exit_flag){
168
- if (current_sense){
169
- if (!current_sense->initialized ) {
170
- motor_status = FOCMotorStatus::motor_calib_failed;
171
- SIMPLEFOC_DEBUG (" MOT: Init FOC error, current sense not initialized" );
172
- exit_flag = 0 ;
173
- }else {
174
- exit_flag *= alignCurrentSense ();
160
+ // aligning the current sensor - can be skipped
161
+ // checks if driver phases are the same as current sense phases
162
+ // and checks the direction of measuremnt.
163
+ if (exit_flag){
164
+ if (current_sense){
165
+ if (!current_sense->initialized ) {
166
+ motor_status = FOCMotorStatus::motor_calib_failed;
167
+ SIMPLEFOC_DEBUG (" MOT: Init FOC error, current sense not initialized" );
168
+ exit_flag = 0 ;
169
+ }else {
170
+ exit_flag *= alignCurrentSense ();
171
+ }
175
172
}
173
+ else { SIMPLEFOC_DEBUG (" MOT: No current sense." ); }
174
+ }
175
+
176
+ } else {
177
+ SIMPLEFOC_DEBUG (" MOT: No sensor." );
178
+ if ((controller == MotionControlType::angle_openloop || controller == MotionControlType::velocity_openloop)){
179
+ exit_flag = 1 ;
180
+ SIMPLEFOC_DEBUG (" MOT: Openloop only!" );
181
+ }else {
182
+ exit_flag = 0 ; // no FOC without sensor
176
183
}
177
- else { SIMPLEFOC_DEBUG (" MOT: No current sense." ); }
178
184
}
179
185
180
186
if (exit_flag){
@@ -219,14 +225,18 @@ int BLDCMotor::alignSensor() {
219
225
// stop init if not found index
220
226
if (!exit_flag) return exit_flag;
221
227
228
+ // v2.3.3 fix for R_AVR_7_PCREL against symbol" bug for AVR boards
229
+ // TODO figure out why this works
230
+ float voltage_align = voltage_sensor_align;
231
+
222
232
// if unknown natural direction
223
233
if (sensor_direction==Direction::UNKNOWN){
224
234
225
235
// find natural direction
226
236
// move one electrical revolution forward
227
237
for (int i = 0 ; i <=500 ; i++ ) {
228
238
float angle = _3PI_2 + _2PI * i / 500 .0f ;
229
- setPhaseVoltage (voltage_sensor_align , 0 , angle);
239
+ setPhaseVoltage (voltage_align , 0 , angle);
230
240
sensor->update ();
231
241
_delay (2 );
232
242
}
@@ -236,13 +246,13 @@ int BLDCMotor::alignSensor() {
236
246
// move one electrical revolution backwards
237
247
for (int i = 500 ; i >=0 ; i-- ) {
238
248
float angle = _3PI_2 + _2PI * i / 500 .0f ;
239
- setPhaseVoltage (voltage_sensor_align , 0 , angle);
249
+ setPhaseVoltage (voltage_align , 0 , angle);
240
250
sensor->update ();
241
251
_delay (2 );
242
252
}
243
253
sensor->update ();
244
254
float end_angle = sensor->getAngle ();
245
- setPhaseVoltage (0 , 0 , 0 );
255
+ // setPhaseVoltage(0, 0, 0);
246
256
_delay (200 );
247
257
// determine the direction the sensor moved
248
258
float moved = fabs (mid_angle - end_angle);
@@ -270,7 +280,7 @@ int BLDCMotor::alignSensor() {
270
280
if (!_isset (zero_electric_angle)){
271
281
// align the electrical phases of the motor and sensor
272
282
// set angle -90(270 = 3PI/2) degrees
273
- setPhaseVoltage (voltage_sensor_align , 0 , _3PI_2);
283
+ setPhaseVoltage (voltage_align , 0 , _3PI_2);
274
284
_delay (700 );
275
285
// read the sensor
276
286
sensor->update ();
0 commit comments