Go to Post Darn, I won't be at Pittsburgh. But I ain't going anywhere this year without my gracious professionalism! - Eugenia Gabrielov [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 21-01-2006, 17:03
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
get distance from cmucam

Does anyone know how to retrive the distance from what ever your tracking from the CMUcam?

I need a way to determine distance to target.

if someone knows how to get the distance to target from the CMUcam please post a copy of the code.

Thanks
Ben
übergeeks Programmer
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #2   Spotlight this post!  
Unread 21-01-2006, 17:53
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: get distance from cmucam

Haven't written the code yet, but just so you know, you can't get the distance to target *directly* from the camera (without some elegant code that I don't know about). However, it is still rather easy.

Using Kevin Watson's Default camera code, there should be a variable called something like tilt_value. Using this value, after converting the PWM value into a useable angle, you can employ a bit of triganometry to derive the distance to target.

(Vert_goal_hight/(tan(angle_to_goal)))= distnce to goal

I would use a lookup table, it'll be much faster than constantly calculating the distance.
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #3   Spotlight this post!  
Unread 21-01-2006, 18:40
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
Re: get distance from cmucam

I need one that gives me the distance from the camera to the target.. not to the base of the target..

does this do it? or does it give the distance from the base of the robot to the base of the target?
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #4   Spotlight this post!  
Unread 21-01-2006, 19:00
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: get distance from cmucam

From the base of the robot to the base of the target. However, you can easily modify it so as to give you the distance to the target, directly.

To derive the hypotenuse of our virtual triangle:

(height_of_camera_to_goal)/(sin(angle_to_goal))= distance, directly to goal.

For anyone who hasn't had trigonometry, I would highly recommend it; it's a very applicable math course! For those who have it coming up, but haven't had it yet, have someone on the team teach you the basics! It really is the most useful math you'll ever learn!
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #5   Spotlight this post!  
Unread 21-01-2006, 19:20
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
Re: get distance from cmucam

Thanks... do you know how to get the angle using easyc? its what my team has decided to use to code it this year instead of mplab.


Thanks a bunch
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #6   Spotlight this post!  
Unread 21-01-2006, 19:22
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: get distance from cmucam

No idea. There should be a way that you can code functions in it; you'll need to code a function to do what you want. I haven't used EasyC yet myself.
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #7   Spotlight this post!  
Unread 21-01-2006, 20:06
Chris_Elston's Avatar
Chris_Elston Chris_Elston is offline
Controls Engineer
AKA: chakorules
FRC #1501 (Team THRUST)
Team Role: Engineer
 
Join Date: Feb 2004
Rookie Year: 2001
Location: Huntington, Indiana
Posts: 751
Chris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond repute
Re: get distance from cmucam

I might be way off base here...

but what we did was make a global varible called cam_Size. Then in the "Capture Tracking Data", there is a pull down box called Region Size. We selected cam_Size in that box. cam_Size needs to be declared as an unsigned char in your globals.

Region size is the size of your "blob" from the CMU cam. The closer you are to your color tracking parmeters, the larger the "blob" will appear on the screen. The futher away you are, the smaller the region will be on the screen.

This relationship is almost linear.

Let's assume that you get a region size of 255. That would mean your camera lens is right ontop of your light or let's just say 1 foot away.

Then let's assume you get a region size of 1, and you note that your camera is 30 feet away.

Everything inbetween can be calculated on a linear scale with some kind of a conversion factor.

(note, I didn't crunch the numbers, I just assumed for this topic of discussion)

1 foot = 255
1.1 feet = 254 etc...

29.9 feet = 2
30 feet = 1
__________________
Team T.H.R.U.S.T. 1501
Download all of our past robot's source code here:Repository

Favorite CD quote:
"That can't be their 'bot. not nearly enough (if any) rivets to be a 1501 machine." ~RogerR: Team #1369
  #8   Spotlight this post!  
Unread 21-01-2006, 20:11
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: get distance from cmucam

Yeah, that was what I was reffering to with the elegant bit of code I didn't know about! I had been trying to find out a good way to look at the size of the blob to determine distance, but it looks like you've done it! Good job!
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #9   Spotlight this post!  
Unread 21-01-2006, 21:09
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
Re: get distance from cmucam

does anyone actually know the numbers and equations for this? my team is still building stuff so as yet I have nothing to test this on.

im sure someone else is trying to do this. if anyone out there is willing to help it would be greatly apprciated.
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #10   Spotlight this post!  
Unread 22-01-2006, 18:51
Dillon Compton Dillon Compton is offline
Jack-Of-All-Trades
FRC #1391 (Metal Moose)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Malvern, PA
Posts: 186
Dillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud ofDillon Compton has much to be proud of
Send a message via AIM to Dillon Compton
Re: get distance from cmucam

Quote:
Originally Posted by ModMan24
does anyone actually know the numbers and equations for this? my team is still building stuff so as yet I have nothing to test this on.

im sure someone else is trying to do this. if anyone out there is willing to help it would be greatly apprciated.

Hi,
I'll be using last years Robot and some printF statements to do this sometime in the next week. I can give you the values I get, but no garauntee that your camera will respond the same as mine; one can find minor changes in mass produced products, and people have indeed found such variances in the CMU CAM responses.

Good luck!
__________________
www.metalmoose.com
  #11   Spotlight this post!  
Unread 22-01-2006, 18:55
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
Re: get distance from cmucam

Thanks.. it will at least be a decent starting point.
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #12   Spotlight this post!  
Unread 05-02-2006, 07:39
aaronm_k aaronm_k is offline
Registered User
no team
 
Join Date: Jan 2006
Rookie Year: 2006
Location:  
Posts: 10
aaronm_k is on a distinguished road
Lightbulb Re: get distance from cmucam

Quote:
Originally Posted by chakorules
I might be way off base here...

but what we did was make a global varible called cam_Size. Then in the "Capture Tracking Data", there is a pull down box called Region Size. We selected cam_Size in that box. cam_Size needs to be declared as an unsigned char in your globals.

Region size is the size of your "blob" from the CMU cam. The closer you are to your color tracking parmeters, the larger the "blob" will appear on the screen. The futher away you are, the smaller the region will be on the screen.

This relationship is almost linear.

Let's assume that you get a region size of 255. That would mean your camera lens is right ontop of your light or let's just say 1 foot away.

Then let's assume you get a region size of 1, and you note that your camera is 30 feet away.

Everything inbetween can be calculated on a linear scale with some kind of a conversion factor.

(note, I didn't crunch the numbers, I just assumed for this topic of discussion)

1 foot = 255
1.1 feet = 254 etc...

29.9 feet = 2
30 feet = 1
Actually, the relationship is hyperbolic (inversely proportional), NOT linear. You can set up a proportion as follows:
Code:
(target distance)/(image distance (i.e. camera focal length)) = (target height (illuminated part))/(blob height)
This is the standard formula for a single lens (which is what the CMU Cam has). Of course, experimental factors (such as amount of the target that's illuminated) make using the above formula unrealistic. Therefore, it's more accurate to calculate a best-fit line. Solving for the target distance, you get the simplified formula:
Code:
(target distance) = (some constant)(1/(blob height))
The blob size is an area, so it's proportional to the blob height squared:
Code:
(blob size) = (some constant)(blob height)^2
or
Code:
(blob height) = (some constant)squareRoot(blob size)
Therefore, the formula in terms of blob size is:
Code:
(target distance) = (some constant)(1/squareRoot(blob size))
        |                  |                   |
        y         =        m                   x
The graph of target distance vs. blob size is a hyperbola, so in order to get a straight line, you have to compare target distance to 1/squareRoot(blob size).

Using this information, my team's programming group took some data using the blob sizes printed to the terminal screen (with Kevin Watson's code) when the camera is locked on to the target. We took data every 4in from 6ft (simulating when the robot is right below the target) to 25ft (simulating when the robot is at half court), and analyzed the data. Fortunately for us (and any team wanting distance data from the camera), the graph of target distance vs. 1/squareRoot(blob size) is a very straight line.

I analyzed the data using some fancy PHP code, and put the results, along with the graph and formula, in an Excel spreadsheet on Team 1717's website. (Links to the raw data can be found under "Programming Team" > "FRC robot code" on our downloads page.)

The final formula is then:
Code:
(target distance) = 798.48871156253/squareRoot(blob size)
The formula can be easily converted to code:
Code:
#define TARGET_DISTANCE_FORMULA_CONSTANT 798.48871156253
targetDistance = TARGET_DISTANCE_FORMULA_CONSTANT / sqrt((double)T_Packet_Data.pixels);
So, one formula down, several more to go for an accurate ball launcher!
  #13   Spotlight this post!  
Unread 05-02-2006, 13:57
ModMan24's Avatar
ModMan24 ModMan24 is offline
Team Programmer/Webmaster
AKA: Ben F.
FRC #1028 (übergeeks)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Alabama
Posts: 14
ModMan24 is an unknown quantity at this point
Send a message via AIM to ModMan24
Re: get distance from cmucam

the whole trig thing works pretty well.
__________________
ÜberGeeks Programmer/Webmaster.
übergeeks
  #14   Spotlight this post!  
Unread 18-09-2010, 08:34
sampath sampath is offline
Registered User
no team
 
Join Date: Sep 2010
Location: Sri Lanka
Posts: 1
sampath is an unknown quantity at this point
Re: get distance from cmucam

Hi,

It's not clear for me whether how are you getting the blob size from the following parameter

"T_Packet_Data.pixels"

Can anybody please explain it to me? I'm new to CMUcam2 sensor.

Thanks!

Sampath
  #15   Spotlight this post!  
Unread 29-10-2010, 17:51
steve d steve d is offline
Registered User
FRC #1277
 
Join Date: Jan 2007
Location: Groton, ma
Posts: 38
steve d is an unknown quantity at this point
Re: get distance from cmucam

"T_Packet_Data.pixels" = number of pixels in tracked area. Attached is the CMUcam manual if you need it.
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
Sharp IR distance sensors Gdeaver Electrical 13 10-02-2007 20:36
Major CMUcam issues - LabView app won't work, very low-quality picture scottmso Programming 5 19-01-2006 17:51
CMUcam setup Ryan Collings Programming 26 13-01-2006 01:00
Long distance... Ashley Christine Chit-Chat 6 27-04-2005 15:11
CMUCam not working. Matt Krass Programming 4 18-01-2005 14:08


All times are GMT -5. The time now is 01:53.

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