implemented SF_MoveMotorToZeroPosition

main
Jonas Arnold 4 years ago
parent 2b71e4a279
commit cf1489195f
  1. 21
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  2. 6
      ADIS_tinyK22_SplitFlap/source/splitflap.h

@ -28,9 +28,23 @@ SF_Handle_t SF_Init(SF_Config_t* instance, int id){
return splitflap;
}
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){
int numStepsMoved = 0;
while(SF_GetMagSensorAtZeroPosition((SF_t*)instance) == false && numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND ){
McuULN2003_IncStep(((SF_t*)instance)->motor);
McuWait_Waitms(20);
numStepsMoved++;
}
// success if less than one rotation
return numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND;
}
void SF_MoveSteps(SF_Handle_t instance, uint8_t steps){
// run move with acceleration & deceleration
McuULN2003_AccelerationStart(((SF_t*)instance)->motor);
// maybe move callback?
while(steps>0){
if(McuULN2003_StepCallback(((SF_t*)instance)->motor, true) == true){
steps--;
@ -38,7 +52,10 @@ void SF_MoveSteps(SF_Handle_t instance, uint8_t steps){
McuWait_Waitms(1);
}
McuULN2003_AccelerationEnd(((SF_t*)instance)->motor);
// Power off necessary? -> what to do after power off? init again?
// Power off disables all outputs of the ULN,
// required since it is possible that one is still active, which would result in the motor getting hot
// no re-init is required
McuULN2003_PowerOff(((SF_t*)instance)->motor);
}

@ -15,6 +15,7 @@
/****** SETTINGS ******/
#define SPLITFLAP_CONFIG_USE_FREERTOS_HEAP 0
#define SPLITFLAP_STEPS_ONE_ROUND 200
/****** TYPES ******/
@ -39,6 +40,11 @@ typedef struct {
* Initialization will be made inside the SF_Init method */
SF_Handle_t SF_Init(SF_Config_t* instance, int id);
/* Moves split flap slowly to zero position.
* returns true if the move was successful, false if not
* (depending on if the sensor was hit before one round) */
bool SF_MoveMotorToZeroPosition(SF_Handle_t instance);
/* split flap moves number of steps maybe uint16_t? */
void SF_MoveSteps(SF_Handle_t instance, uint8_t steps);

Loading…
Cancel
Save