Go to Post Chit Chat is frivilous but CD would be a colder place without it. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-04-2006, 00:10
Alan T Alan T is offline
Registered User
FRC #1696
Team Role: Programmer
 
Join Date: Mar 2006
Location: Black Eagle, MT
Posts: 2
Alan T will become famous soon enough
Fix for CMU cam initalization code 131 error.

We had been fighting the Camera: Inititialized abnormally with code 131 error. Sometimes the camera would work perfectly. Then other times it would fail initialization. It was very inconsistant. Sometimes we would have to pull the backup battery and reset the RC to get it to initialize.

When I tried using the cmu cam on a VEX it happened everytime. I thought it was a hardware communication problem.

My theory is that sometimes the camera "misses" the commands sent during boot initialization. Possibly the camera processor is still initializing? I think the problem is worse on a vex because the getdata loop time is only 18ms on the vex vs 26ms on a FRC.

I added a bit of code in the camera initialization routine. If the initialization fails with error 131 it resets the boot initialization flag.

So far this has completely fixed the problem. The initialization will still fail the first time at state 3. The camera then initializes sucessfully at the next call to Initialize_Camera. It now works great on both the FRC and VEX controllers.

I added the below code to the end of the Initialize_Camera routine in Kevin's camera.c. It goes just before return(return_value);

Code:
 
 //Added 3/26/2006 AAT
 //If initialization fails after waiting for first ACK
 //in state 3, retry boot initialization.
 if(return_value == 131)
 {
  boot_initialization_flag = 1;
 }

alan

Last edited by Alan T : 05-04-2006 at 10:38.
  #2   Spotlight this post!  
Unread 05-04-2006, 10:56
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,856
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Fix for CMU cam initalization code 131 error.

It looks like you found a good solution to your problem.
We've had success with a similar approach. We also look to handle any case where communication with the camera fails in addition to never happening in the first place.

http://www.chiefdelphi.com/forums/sh...88&postcount=9

I agree it looks like the specific problem you're seeing is probably because the PIC sends out commands before the camera has time to complete it's power-up sequence.
We also use a generic startup delay in our main loop of a few milliseconds, so the code doesn't attempt to do any sensor I/O or even pay attention to the regular OI communication packet until everything's had a chance to settle.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 05-04-2006 at 11:07.
  #3   Spotlight this post!  
Unread 05-04-2006, 11:58
Don Reid Don Reid is offline
Registered User
#0997
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Corvallis, Oregon
Posts: 45
Don Reid will become famous soon enough
Re: Fix for CMU cam initalization code 131 error.

I thought of another approach. After writing my own PC program to work with the CMUCam, I realized that part of the problem in the robot is that reseting the RC doesn't directly reset the camera. It expects the code to reset the camera over the serial link, but if the camera is in an odd mode (or even raw mode), that may not always work.

The only way to really reset the camera is to cycle its power. With the camera powered by a RC PWM port, that doesn't happen.

So why not power the camera through a relay (spike). That way it gets turned off when the RC resets (or when the code wants it to be). The code can then turn on the camera, wait a while, and know its state.

A single relay could be used to power a lot of other sensors (IR etc.) at the same time.
__________________
Don Reid
  #4   Spotlight this post!  
Unread 05-04-2006, 14:05
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Fix for CMU cam initalization code 131 error.

Quote:
Originally Posted by Don Reid
After writing my own PC program to work with the CMUCam, I realized that part of the problem in the robot is that reseting the RC doesn't directly reset the camera. It expects the code to reset the camera over the serial link, but if the camera is in an odd mode (or even raw mode), that may not always work.

The only way to really reset the camera is to cycle its power. With the camera powered by a RC PWM port, that doesn't happen.
Don & others,
We ran into this problem last year with our camera. We do not use any of the provided camera code as our camera is controlled by our custom circuit. This presents an interesting problem because whenever the "reset" button is pushed on the RC the camera seems to get reset as well (apparently power to the PWM ports is disrupted? It doesn't happen when the "RC Reset" button is pressed on the OI.) We use raw mode when communicating with the camera, and so anyway the bottom line is that when our custom circuit initially talks to the camera it can be in either normal or raw mode. Below is my camera_reset() routine which works effectively to reset the camera regardless of it's current state. We haven't had any trouble with it using this reset sequence. camera_send() and camera_recv() are just aliases for sending/reading from the serial port. camera_flush() just flushes the serial input buffer.

Anyway, just posting it in case it is helpful to someone...
Code:
CameraReturnType camera_reset(void)
{
    CameraReturnType ret_val = CAM_FAILURE;
    UINT8 buf;

    // Send the reset command to the camera.  If the camera is already in raw
    // mode, then this command should succeed.  If the camera is not in raw
    // mode, the camera will NCK this command.  If we try to send the normal
    // mode reset command first, and the camera is in raw mode, then it gets
    // stuck trying to read in 32 more bytes from us (because the space after
    // RS is decimal 32, which in raw mode indicates the number of arguments
    // that we're sending to the command).  Bottom line is that it needs to be
    // done this way for it to work reliably in either mode.
    camera_send("RS\0\r", 4);

    // Read in the first character of the response from the camera.
    camera_recv(&buf, 1);

    // Take appropriate action depending on whether the camera 'A'cked or
    // 'N'cked the command.
    if(buf == 'N')
    {
        // NCK received.  This likely means we are not in RAW mode, so
        // try a non-raw reset command.
        camera_send("RS\r", 3);

        camera_flush();

        ret_val = CAM_SUCCESS;
    }
    else if(buf == 'A')
    {
        // ACK received.  Camera should now be reset.  Nothing else to do.
        ret_val = CAM_SUCCESS;
    }

    // Flush the input buffer from any garbage that might be remaining.
    // When the CMUcam is reset, it outputs a version string, but also
    // sometimes truncates the previous ACK statement, so it's easiest
    // to just get rid of whatever is in the buffer before continuing.
    camera_flush();

    return ret_val;
}
  #5   Spotlight this post!  
Unread 05-04-2006, 14:34
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: Fix for CMU cam initalization code 131 error.

Like Dave, we have our own custom camera code. However, we use the raw mode only for the output from the camera (RM 1). This eliminates the need to determine what mode the camera is in before sending commands.

Mike
  #6   Spotlight this post!  
Unread 05-04-2006, 15:36
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Fix for CMU cam initalization code 131 error.

Quote:
Originally Posted by Mike Bortfeldt
Like Dave, we have our own custom camera code. However, we use the raw mode only for the output from the camera (RM 1). This eliminates the need to determine what mode the camera is in before sending commands.
How do you handle knowing which mode the camera is in when you power up? If the camera was previously initialized, it should be in raw mode, but if it just powered up as well, it'll be in normal mode.
{edit} Sorry, didn't read closely enough - I missed the part about "only for the output", so that obviously changes things. {/edit}

Last edited by Dave Flowerday : 06-04-2006 at 09:25.
  #7   Spotlight this post!  
Unread 06-04-2006, 02:59
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Fix for CMU cam initalization code 131 error.

Quote:
Originally Posted by Mark McLeod
It looks like you found a good solution to your problem.
I agree it looks like the specific problem you're seeing is probably because the PIC sends out commands before the camera has time to complete it's power-up sequence.
We also use a generic startup delay in our main loop of a few milliseconds, so the code doesn't attempt to do any sensor I/O or even pay attention to the regular OI communication packet until everything's had a chance to settle.
I had the same problem with WPILib (which is used in EasyC). So WPILib won't send any camera commands until two seconds after power on. This isn't a serious problem since that's the time that the robot is sitting on the field before the match starts. Also, users can initialize everything else before starting the camera and that can often burn up the 2 seconds anyway, then it would start right away.

The library also receives in RAW mode, but always sends commands in ASCII. It didn't seem like a worthwhile optimization, since 99% of what the camera was doing was receiving T-packets, and those were received in binary. That way there was no ambiguity when interrupting the camera and sending commands to it.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code error on RC after downloading "bells and whistles" version of Kevins camera code DanDon Programming 6 10-01-2006 18:07
Intermittent Code Error Plloyd Programming 9 09-04-2005 21:37
CAM ERROR! magical hands Programming 0 03-02-2005 13:44
Error w/ FRC code JamesBrown Programming 2 08-01-2005 16:17
heres the code. y this not working omega Programming 16 31-03-2004 15:18


All times are GMT -5. The time now is 23:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi