|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||||
|
|||||
|
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. |
|
#3
|
||||
|
||||
|
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? |
|
#4
|
|||||
|
|||||
|
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! |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
|||||
|
|||||
|
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.
|
|
#7
|
||||
|
||||
|
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 |
|
#8
|
|||||
|
|||||
|
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!
|
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
Re: get distance from cmucam
Quote:
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! |
|
#11
|
||||
|
||||
|
Re: get distance from cmucam
Thanks.. it will at least be a decent starting point.
|
|
#12
|
|||
|
|||
|
Quote:
Code:
(target distance)/(image distance (i.e. camera focal length)) = (target height (illuminated part))/(blob height) Code:
(target distance) = (some constant)(1/(blob height)) Code:
(blob size) = (some constant)(blob height)^2 Code:
(blob height) = (some constant)squareRoot(blob size) Code:
(target distance) = (some constant)(1/squareRoot(blob size))
| | |
y = m x
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) Code:
#define TARGET_DISTANCE_FORMULA_CONSTANT 798.48871156253 targetDistance = TARGET_DISTANCE_FORMULA_CONSTANT / sqrt((double)T_Packet_Data.pixels); ![]() |
|
#13
|
||||
|
||||
|
Re: get distance from cmucam
the whole trig thing works pretty well.
|
|
#14
|
|||
|
|||
|
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
|
|||
|
|||
|
Re: get distance from cmucam
"T_Packet_Data.pixels" = number of pixels in tracked area. Attached is the CMUcam manual if you need it.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |