Notes: There is still approximately a 1:30 chance for the camera to still require a power cycle. Call Camera_Comm_Check() from the slow loop (auto and regular). We do it in Process_Data_From_Master_uP(), but our auto doesn't use a separate, independent loop. Make the following global in camera.c Initialize_Camera() so they can be reset: unsigned char boot_initialization_flag = 1; unsigned char initialize_flag = 1; #define PACKET_MISS_THRESH 8 // This is really looking for 2 missing packets in a row. (= #missing * 4) /******************************************************************************* * * FUNCTION: Camera_Comm_Check() * * PURPOSE: This detects the failure of communications with the camera. * * CALLED FROM: Process_Data_From_Master_uP() * * PARAMETERS: none * * RETURNS: nothing * * COMMENTS: * MLM - Written 3/20/06 * Several things here, such as "flag", are unnecessary and only used during debug. *******************************************************************************/ #include "user_routines.h" #include "clock_routines.h" #define TIMEOUT 2 // (sec) Allow camera time to initialization before trying again // A typical camera re-initialization takes 1.2 seconds void Camera_Comm_Check(void) { static unsigned int old_camera_t_packets=9999; // Local check static unsigned long camera_init_timeout=TIMEOUT; static unsigned char packet_err_cnt = 0; static char flag=TRUE; // Is the camera still communicating? if(old_camera_t_packets == camera_t_packets) // We didn't receive a new camera packet { if(packet_err_cnt >= PACKET_MISS_THRESH) { if (camera_init_timeout < Clocksec) { // Need to do periodically until power (& communication) is restored camera_init_timeout = Clocksec + TIMEOUT; Reset_Mode(); Restart_Camera2(); flag = TRUE; printf("Restart Camera ****** Clockms=%ld\r", Clockms); } else // Just wait for the camera. Give it time. { // printf("Restart: bytecount=%d, ", Camera_Serial_Port_Byte_Count()); } } else { packet_err_cnt++; // Normally see T packets at 10Hz. This count is ~4 times quicker. // Could check & increment at 10Hz as well... } } else { packet_err_cnt = 0; old_camera_t_packets = camera_t_packets; if (flag) printf("Received new packet ****** Clockms=%ld\r", Clockms); flag = FALSE; } } /******************************************************************************* * * FUNCTION: Reset_Mode() * * PURPOSE: Properly formats and sends a camera RS (Reset) command * to the camera assuming camera is in either raw or ascii mode. * Too close together increases the camera hang rate. * * CALLED FROM: Camera_Comm_Check() * * PARAMETERS: unsigned char * * RETURNS: nothing * * COMMENTS: * MLM - Written 3/20/06 *******************************************************************************/ void Reset_Mode(void) { // Raw mode Write_Camera_Serial_Port(255); // Raw mode start flag Write_Camera_Serial_Port('R'); Write_Camera_Serial_Port('S'); Write_Camera_Serial_Port('\r'); // Ascii mode // Write_Camera_Serial_Port('R'); // Write_Camera_Serial_Port('S'); // Write_Camera_Serial_Port('\r'); } /******************************************************************************* * * FUNCTION: Restart_Camera2() * * PURPOSE: This command will force a camera reinitialization * * CALLED FROM: Camera_Comm_Check() * * PARAMETERS: none * * RETURNS: nothing * * COMMENTS: * MLM - Written 2/20/06 * Assumes the use of Kevin Watson's camera.c and serial communications code * Requires a couple of internal variables be made global within * camera.c so they may be reset. * unsigned char boot_initialization_flag = 1; * unsigned char initialize_flag = 1; *******************************************************************************/ void Restart_Camera2(void) { camera_initialized = 0; //Added the following to original Restart_Camera()... camera_t_packets = 0; // Counts new camera T packets received boot_initialization_flag = 1; // Reinitialize camera communication mode initialize_flag = 1; // Reinitialize the camera.c state machine }