|
|
|
@ -59,7 +59,7 @@ SF_Handle_t SF_Init(SF_Config_t* instance, int id){ |
|
|
|
return splitflap; |
|
|
|
return splitflap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, int8_t offsetSegments){ |
|
|
|
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, uint16_t offsetSteps){ |
|
|
|
int numStepsMoved = 0; |
|
|
|
int numStepsMoved = 0; |
|
|
|
|
|
|
|
|
|
|
|
// move out of sensor
|
|
|
|
// move out of sensor
|
|
|
|
@ -68,30 +68,28 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, int8_t offsetSegments){ |
|
|
|
McuWait_Waitms(20); |
|
|
|
McuWait_Waitms(20); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// turn until sensor is on
|
|
|
|
// turn until sensor is on and not reached one full rotation already (timeout)
|
|
|
|
while(SF_GetMagSensorAtZeroPosition((SF_t*)instance) == false && numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND ){ |
|
|
|
while(SF_GetMagSensorAtZeroPosition((SF_t*)instance) == false && numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND ){ |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuWait_Waitms(20); |
|
|
|
McuWait_Waitms(20); |
|
|
|
numStepsMoved++; |
|
|
|
numStepsMoved++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// one more segment if not already one round
|
|
|
|
// offset after init
|
|
|
|
if(numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND){ |
|
|
|
if(numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND){ |
|
|
|
// +0.5 so that the rounding is done correctly
|
|
|
|
|
|
|
|
int8_t offsetSteps = offsetSegments * SPLITFLAP_STEPS_ONE_ROUND/SPLITFLAP_AMOUNT_OF_SEGMENTS; // (int8_t)((float)offsetSegments*SPLITFLAP_STEPS_PER_SEGMENT + 0.5);
|
|
|
|
|
|
|
|
for(int i=0; i < offsetSteps; i++){ |
|
|
|
for(int i=0; i < offsetSteps; i++){ |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_IncStep(((SF_t*)instance)->motor); |
|
|
|
McuWait_Waitms(20); |
|
|
|
McuWait_Waitms(20); |
|
|
|
numStepsMoved++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
McuULN2003_SetPos(((SF_t*)instance)->motor, 0); |
|
|
|
McuULN2003_SetPos(((SF_t*)instance)->motor, 0); |
|
|
|
McuULN2003_PowerOff(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_PowerOff(((SF_t*)instance)->motor); |
|
|
|
|
|
|
|
|
|
|
|
// success if less than one rotation
|
|
|
|
// success if less than one rotation
|
|
|
|
return numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND; |
|
|
|
return numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SF_MoveSteps(SF_Handle_t instance, int32_t steps){ |
|
|
|
void SF_MoveSteps(SF_Handle_t instance, uint32_t steps){ |
|
|
|
// run move with acceleration & deceleration
|
|
|
|
// run move with acceleration & deceleration
|
|
|
|
McuULN2003_AccelerationStart(((SF_t*)instance)->motor); |
|
|
|
McuULN2003_AccelerationStart(((SF_t*)instance)->motor); |
|
|
|
while(steps>0){ |
|
|
|
while(steps>0){ |
|
|
|
|