Index: firmware/App/Controllers/Ejector.c =================================================================== diff -u -r9a8e1fc597eb4f681527e691fb6cb24e550d8b92 -ra0b8983fa00aa8e2e8ec74744978cffaa4011dcd --- firmware/App/Controllers/Ejector.c (.../Ejector.c) (revision 9a8e1fc597eb4f681527e691fb6cb24e550d8b92) +++ firmware/App/Controllers/Ejector.c (.../Ejector.c) (revision a0b8983fa00aa8e2e8ec74744978cffaa4011dcd) @@ -30,7 +30,7 @@ // ********** private definitions ********** -#define EJECTOR_RETRACT_OP_TIME ( ( MS_PER_SECOND * 5 ) / TASK_GENERAL_INTERVAL ) ///< Ejector retract operation interval. +#define EJECTOR_RETRACT_OP_TIME ( ( MS_PER_SECOND * 10 ) / TASK_GENERAL_INTERVAL ) ///< Ejector retract operation interval. #define EJECTOR_EXTEND_OP_TIME ( ( MS_PER_SECOND * 10 ) / TASK_GENERAL_INTERVAL ) ///< Ejector extend operation interval. #define EJECTOR_BACKOFF_OP_TIME ( 50 / TASK_GENERAL_INTERVAL ) ///< Ejector back-off operation interval. #define EJECTOR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Ejector data publish interval. @@ -43,10 +43,10 @@ /// Enumeration of ejector states. typedef enum EjectorOperations { - EJECTOR_OPERATION_HOME = 0, ///< Ejector home operation - EJECTOR_OPERATION_RETRACT, ///< Ejector retract operation - EJECTOR_OPERATION_EXTEND, ///< Ejector extend operation - NUM_OF_EJECTOR_OPERATIONS, ///< Number of ejector operations + EJECTOR_OPERATION_HOME = 0, ///< Ejector home operation + EJECTOR_OPERATION_RETRACT, ///< Ejector retract operation + EJECTOR_OPERATION_EXTEND, ///< Ejector extend operation + NUM_OF_EJECTOR_OPERATIONS, ///< Number of ejector operations } EJECTOR_OPERATION_T; // ********** private data ********** @@ -103,37 +103,6 @@ /*********************************************************************//** * @brief - * The resetEjectorFlags function resets the ejector flags to FALSE. - * @details \b Inputs: none - * @details \b Outputs: ejectorHomeRequested, ejectorRetractRequested, - * ejectorExtendRequested, ejectorAbortRequested - * @return none - *************************************************************************/ -static void resetEjectorFlags( void ) -{ - ejectorHomeRequested = FALSE; - ejectorRetractRequested = FALSE; - ejectorExtendRequested = FALSE; - ejectorAbortRequested = FALSE; -} - -/*********************************************************************//** - * @brief - * The setEjectorSpeed function records the requested ejector speed and - * sets the ejector motor speed to that speed. - * @details \b Inputs: none - * @details \b Outputs: currentEjectorSetSpeed - * @param speed Target speed for ejector motor. - * @return none - *************************************************************************/ -static void setEjectorSpeed( F32 speed ) -{ - currentEjectorSetSpeed = speed; - setEjectorMotorSpeed( currentEjectorSetSpeed ); -} - -/*********************************************************************//** - * @brief * The homeEjector function requests an ejector home operation. * @details \b Inputs: currentEjectorState * @details \b Outputs: ejectorHomeRequested @@ -336,7 +305,7 @@ { EJECTOR_STATE_T state = EJECTOR_STATE_HOMING; - if ( ++ejectorOperationTimerCounter >= EJECTOR_RETRACT_OP_TIME ) + if ( ( ++ejectorOperationTimerCounter >= EJECTOR_RETRACT_OP_TIME ) || ( TRUE == isEjectorOpticalSensorActive( EJECTOR_OPT_SENSOR_RETRACT ) ) ) { ejectorOperationTimerCounter = 0; setEjectorSpeed( EJECTOR_OFF_MOTOR_SPEED_RPM ); @@ -410,7 +379,8 @@ { EJECTOR_STATE_T state = EJECTOR_STATE_RETRACTING; - if ( ++ejectorOperationTimerCounter >= EJECTOR_RETRACT_OP_TIME ) + // If the optical sensor is active it means the ejector has reached to the full retract position + if ( ( ++ejectorOperationTimerCounter >= EJECTOR_RETRACT_OP_TIME ) || ( TRUE == isEjectorOpticalSensorActive( EJECTOR_OPT_SENSOR_RETRACT ) ) ) { ejectorOperationTimerCounter = 0; setEjectorSpeed( EJECTOR_OFF_MOTOR_SPEED_RPM ); @@ -476,7 +446,8 @@ { EJECTOR_STATE_T state = EJECTOR_STATE_EXTENDING; - if ( ++ejectorOperationTimerCounter >= EJECTOR_EXTEND_OP_TIME ) + // If the optical sensor is active it means the ejector has reached to the full extended (engage) position + if ( ( ++ejectorOperationTimerCounter >= EJECTOR_EXTEND_OP_TIME ) || ( TRUE == isEjectorOpticalSensorActive( EJECTOR_OPT_SENSOR_ENGAGE ) ) ) { ejectorOperationTimerCounter = 0; setEjectorSpeed( EJECTOR_OFF_MOTOR_SPEED_RPM ); @@ -510,6 +481,37 @@ /*********************************************************************//** * @brief + * The resetEjectorFlags function resets the ejector flags to FALSE. + * @details \b Inputs: none + * @details \b Outputs: ejectorHomeRequested, ejectorRetractRequested, + * ejectorExtendRequested, ejectorAbortRequested + * @return none + *************************************************************************/ +static void resetEjectorFlags( void ) +{ + ejectorHomeRequested = FALSE; + ejectorRetractRequested = FALSE; + ejectorExtendRequested = FALSE; + ejectorAbortRequested = FALSE; +} + +/*********************************************************************//** + * @brief + * The setEjectorSpeed function records the requested ejector speed and + * sets the ejector motor speed to that speed. + * @details \b Inputs: none + * @details \b Outputs: currentEjectorSetSpeed + * @param speed Target speed for ejector motor. + * @return none + *************************************************************************/ +static void setEjectorSpeed( F32 speed ) +{ + currentEjectorSetSpeed = speed; + setEjectorMotorSpeed( currentEjectorSetSpeed ); +} + +/*********************************************************************//** + * @brief * The publishEjectorData function constructs and sends the air pump data * broadcast message. * @details \b Message \b Sent: MSG_ID_TD_EJECTOR_DATA @@ -524,8 +526,10 @@ { EJECTOR_PAYLOAD_T data; - data.h5State = getEjectorState(); - data.h5SetSpeed = currentEjectorSetSpeed; + data.h5State = getEjectorState(); + data.h5SetSpeed = currentEjectorSetSpeed; + data.retractOpticalSensor = (U32)isEjectorOpticalSensorActive( EJECTOR_OPT_SENSOR_RETRACT ); + data.engageOpticalSensor = (U32)isEjectorOpticalSensorActive( EJECTOR_OPT_SENSOR_ENGAGE ); broadcastData( MSG_ID_TD_EJECTOR_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( EJECTOR_PAYLOAD_T ) ); ejectorDataPublicationTimerCounter = 0;