@@ -156,25 +156,31 @@ int BLDCMotor::initFOC() {
156156 // added the shaft_angle update
157157 sensor->update ();
158158 shaft_angle = shaftAngle ();
159- }else {
160- exit_flag = 0 ; // no FOC without sensor
161- SIMPLEFOC_DEBUG (" MOT: No sensor." );
162- }
163159
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+ }
175172 }
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
176183 }
177- else { SIMPLEFOC_DEBUG (" MOT: No current sense." ); }
178184 }
179185
180186 if (exit_flag){
@@ -219,14 +225,18 @@ int BLDCMotor::alignSensor() {
219225 // stop init if not found index
220226 if (!exit_flag) return exit_flag;
221227
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+
222232 // if unknown natural direction
223233 if (sensor_direction==Direction::UNKNOWN){
224234
225235 // find natural direction
226236 // move one electrical revolution forward
227237 for (int i = 0 ; i <=500 ; i++ ) {
228238 float angle = _3PI_2 + _2PI * i / 500 .0f ;
229- setPhaseVoltage (voltage_sensor_align , 0 , angle);
239+ setPhaseVoltage (voltage_align , 0 , angle);
230240 sensor->update ();
231241 _delay (2 );
232242 }
@@ -236,13 +246,13 @@ int BLDCMotor::alignSensor() {
236246 // move one electrical revolution backwards
237247 for (int i = 500 ; i >=0 ; i-- ) {
238248 float angle = _3PI_2 + _2PI * i / 500 .0f ;
239- setPhaseVoltage (voltage_sensor_align , 0 , angle);
249+ setPhaseVoltage (voltage_align , 0 , angle);
240250 sensor->update ();
241251 _delay (2 );
242252 }
243253 sensor->update ();
244254 float end_angle = sensor->getAngle ();
245- setPhaseVoltage (0 , 0 , 0 );
255+ // setPhaseVoltage(0, 0, 0);
246256 _delay (200 );
247257 // determine the direction the sensor moved
248258 float moved = fabs (mid_angle - end_angle);
@@ -270,7 +280,7 @@ int BLDCMotor::alignSensor() {
270280 if (!_isset (zero_electric_angle)){
271281 // align the electrical phases of the motor and sensor
272282 // set angle -90(270 = 3PI/2) degrees
273- setPhaseVoltage (voltage_sensor_align , 0 , _3PI_2);
283+ setPhaseVoltage (voltage_align , 0 , _3PI_2);
274284 _delay (700 );
275285 // read the sensor
276286 sensor->update ();
0 commit comments