Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Camera Code Update (http://www.chiefdelphi.com/forums/showthread.php?t=53984)

Kevin Watson 12-02-2007 13:53

Camera Code Update
 
I've made a few changes to the camera code and would like to get some feedback before releasing it. If you can think of something you'd like changed or added, please leave a message here. These are the changes do far:

2/11/07 changes made for version 2.2:

Important: after loading the new software, make sure
you "Load default values" and then "Save changes" from
the tracking menu.

terminal.c/.h:
-Fixed benign bug where old_camera_t_packets was not getting updated in Tracking_Info_Terminal().

-Altered code to use Tracking_Config_Data values for center tilt and pan values instead of hardwired values in Tracking_Info_Terminal().

-Altered code to use Get_Camera_T_Packets() function instead of directly accessing camera_t_packets variable.

camera.c/.h:
-Added Poll_Mode() function.

-Added Get_Camera_ACKs() function.

-Added Get_Camera_NCKs() function.

-Added Get_Camera_T_Packets() function.

tracking.c/.h:
-Altered code to use Get_Camera_T_Packets() function instead of directly accessing camera_t_packets variable.

-Changed default CONFIDENCE_THRESHOLD_DEFAULT values to 10 (was 20).

-Greatly simplified search code (same functionality with less code).

-Changed search parameters so that a fixed tilt angle of about 30 degrees is used.

-For finer control, moved camera pan servo to PWM output 15.

-For finer control, Moved camera tilt servo to PWM output 16.

user_routines_fast.c:
-Replaced call to Generate_Pwms() in User_Autonomous_Code() with a call to PWM().

serial_ports_readme.txt:
-Corrected installation instruction #4.

camera_readme.txt:
-Added Virtual_Window() function description.

-Added Poll_Mode() function description.

-Added Get_Camera_ACKs() function description.

-Added Get_Camera_NCKs() function description.

-Added Get_Camera_T_Packets() function description.

pwm.h:
-Using new PWM() software, optimized camera tilt for a range of 0 to 90 degrees.


-Kevin

Tom Bottiglieri 12-02-2007 14:04

Re: Camera Code Update
 
After I just finished porting your tracking software to work with WPILib...!!!!:mad:

;) Can't wait to test the new stuff out. I'm particularly excited about the increased servo resolution.

Kevin Watson 12-02-2007 14:17

Re: Camera Code Update
 
Quote:

Originally Posted by Tom Bottiglieri (Post 576720)
After I just finished porting your tracking software to work with WPILib...!!!!:mad:

;) Can't wait to test the new stuff out. I'm particularly excited about the increased servo resolution.

This is the new search code:
Code:

///////////////////
// //
// search code //
// //
///////////////////
 
// To provide a delay for the camera to lock onto the
// target between position changes, we only step the camera
// to a new position every SEARCH_DELAY times while we're
// in search mode. SEARCH_DELAY is #define'd in tracking.h
loop_count++;
 
if(loop_count >= Tracking_Config_Data.Search_Delay)
{
// reset the loop counter
loop_count =0;
 
// If we're starting a new search, initialize the pan
// and tilt servos to the search starting point.
// Otherwise, just continue the search pattern from
// where we left off. The variable new_search is reset
// to one each time the tracking code (above) executes.
if(new_search ==1)
{
new_search =0;
temp_pan_servo = Tracking_Config_Data.Pan_Min_PWM;
temp_tilt_servo = Tracking_Config_Data.Tilt_Center_PWM;
}
else
{
// calculate new pan position based upon the current pan servo position
temp_pan_servo = (int)pan_servo_position;
 
// step the pan servo to its next destination
temp_pan_servo += (int)Tracking_Config_Data.Pan_Search_Step_Size;
 
// is the new pan servo position beyond the end of its travel?
if(temp_pan_servo > (int)Tracking_Config_Data.Pan_Max_PWM)
{
// send the pan servo back to the starting position
temp_pan_servo = (int)Tracking_Config_Data.Pan_Min_PWM;
 
// calculate new tilt position based upon the current pan servo position
temp_tilt_servo = (int)tilt_servo_position;
 
// step the tilt servo to its next destination
temp_tilt_servo += (int)Tracking_Config_Data.Tilt_Search_Step_Size;
 
// is the new tilt servo position beyond the end of its travel?
if(temp_tilt_servo > (int)Tracking_Config_Data.Tilt_Max_PWM)
{
// send the tilt servo back to the starting position
temp_tilt_servo = (int)Tracking_Config_Data.Tilt_Min_PWM;
}
// update the local variable used to store the current tilt servo positions
tilt_servo_position = (unsignedchar)temp_tilt_servo;
}
// update the local variable used to store the current pan servo positions
pan_servo_position = (unsignedchar)temp_pan_servo;
}
 
// update the pan and tilt servo PWM value
Set_Pan_Servo_Position(pan_servo_position);
Set_Tilt_Servo_Position(tilt_servo_position);
}

The increased servo resolution was mentioned towards the end of this thread:

http://www.chiefdelphi.com/forums/sh...ad.php?t=51802

-Kevin

team 2244 12-02-2007 14:25

Re: Camera Code Update
 
Thanks for this new version!!!
Our team is having some problems with the CMUCam2.1 version, the tilt and pan is not moving and stuff like this!We`ll try to test this one.
Probably we`ll need to change the PWM`s to other outputs. Am I correct??(we`re newbies, and we need a lot of help!!!)
We hope it works!!!;)

Bye!

Greg Marra 12-02-2007 14:29

Re: Camera Code Update
 
Quote:

Originally Posted by team 2244 (Post 576735)
Probably we`ll need to change the PWM`s to other outputs. Am I correct??

Kevin's revised code takes advantage of the ability to use hardware built into the PIC to generate higher-precision PWM signals on PWM 13-16. This allows you finer control over the tilt and pan of the camera for better triangulation.

So, you could modify the code to use the PWMs you were before, but I would recommend moving to PWM 15 and 16 as Kevin has done.

Goldeye 12-02-2007 14:37

Re: Camera Code Update
 
Sounds excellent. I think you should release it as soon as possible; time is running short :)

team 2244 12-02-2007 14:40

Re: Camera Code Update
 
What you mean when you say better triangulation??
And where do I add this new search code that Kevin has created??
Probably I will do a lot of questions don`t be mad please:rolleyes:
Thanks for your help!

Alan Anderson 12-02-2007 15:54

Re: Camera Code Update
 
Quote:

Originally Posted by team 2244 (Post 576751)
And where do I add this new search code that Kevin has created??

If you don't already understand the innards of tracking.c, I think you're better off leaving it alone. The 2.1 code does exactly the same thing as this update, just not as elegantly.

Bharat Nain 12-02-2007 16:08

Re: Camera Code Update
 
Request: Please release the streamlined version of this too.

Kevin Watson 12-02-2007 17:08

Re: Camera Code Update
 
Quote:

Originally Posted by Bharat Nain (Post 576806)
Request: Please release the streamlined version of this too.

Yes, once I'm reasonably happy with the code, I'll quickly port it over to the streamlined version. Unless I need to make some last minute changes, I'll zip-up the bells & whistles code tonight and post a link here.

-Kevin

Bomberofdoom 12-02-2007 17:22

Re: Camera Code Update
 
Kevin, PWM outputs 15 and 16 are used for the (left?) motors. If you take those PWM outputs, we won't be able to use the camera to move the robot to the light. But of course, that's not a real issue, since I can change the Servo PWM outputs. But mabye others don't know how do to it and could freak out a bit because some of thier engines are not working.
I don't mind you have changed it, but just thinking about the weaker ones. :)

Our team will check the code tommorow, tweak it as needed.

Thanks for the update.;)

Kevin Watson 12-02-2007 17:25

Re: Camera Code Update
 
Quote:

Originally Posted by Alan Anderson (Post 576799)
If you don't already understand the innards of tracking.c, I think you're better off leaving it alone. The 2.1 code does exactly the same thing as this update, just not as elegantly.

I'm not sure the new code is elegant, but I am sure the old search code is not elegant :).

-Kevin

Kevin Watson 12-02-2007 17:33

Re: Camera Code Update
 
Quote:

Originally Posted by Bomberofdoom (Post 576876)
Kevin, PWM outputs 15 and 16 are used for the (left?) motors. If you take those PWM outputs, we won't be able to use the camera to move the robot to the light. But of course, that's not a real issue, since I can change the Servo PWM outputs. But mabye others don't know how do to it and could freak out a bit because some of thier engines are not working.
I don't mind you have changed it, but just thinking about the weaker ones. :)

Yes, it's a pain, but I need to move the pan and tilt servos to the range 13 through 16 to exploit the new PWM() functionality. You make a good point and I'll make sure it's very clear in the readme_first.txt document that the assignments have changed.

-Kevin

Bio 12-02-2007 17:46

Re: Camera Code Update
 
Considering you've got a get, you may very well be including it already, but we would definitely appreciate Reset_Camera_ACKs() and Reset_Camera_NCKs() functions. Not a real big deal, but it would save us a variable.

Tyr333 12-02-2007 19:48

Re: Camera Code Update
 
I've noticed that when the camera is in a search, if the camera is resetting its pan for a new sweep:
"if(temp_pan_servo >= PAN_MAX_PWM_DEFAULT)
{
temp_pan_servo = PAN_MIN_PWM_DEFAULT;"

and if the camera sees the light during this motion of resetting the pan to its minimum, when it arrives at this new pan position, the camera tilts down. It continues to search at this lower tilt, reaches the maximum pan, tilts back up, sweeps to its minimum pan, sees the light during this trip, and tilts down again. It continues this loop and never tracks the light. We don't usually have this problem, but at certain distances from the light it becomes impossible to track. What can we do to fix this?

Alan Anderson 12-02-2007 23:06

Re: Camera Code Update
 
Quote:

Originally Posted by Tyr333 (Post 576971)
I've noticed that when the camera is in a search, if the camera is resetting its pan for a new sweep:...and if the camera sees the light during this motion of resetting the pan to its minimum, when it arrives at this new pan position, the camera tilts down. It continues to search at this lower tilt, reaches the maximum pan, tilts back up, sweeps to its minimum pan, sees the light during this trip, and tilts down again. It continues this loop and never tracks the light...What can we do to fix this?

You can change the search pattern code to do a zigzag sweep instead of always going left-to-right. That way it will never be panning too fast to stop when it sees the light, and it won't need to restart the search immediately upon glimpsing and then losing it.

Here's an overview of one way to go about it. Where it tests for the pan value being greater than the maximum limit, set a flag instead of resetting to minimum. Add a similar test for the pan value being less than the minimum and reset the flag if it is. Where the code adds the step size to the current pan value, have it subtract instead if the flag is set.

Kevin Watson 13-02-2007 02:45

Re: Camera Code Update
 
1 Attachment(s)
I've uploaded version 2.2 of the bells & whistles camera code. See the attached document for a list of changes. As it's very close to the ship date, I would caution everyone to think really, really hard before ripping open your nearly complete code and dumping my changes in. For this reason I'm not sure if I'll add a link to this code on my website before the ship date. I guess I'll wait to see what the Chief Delphi crowd thinks. As always, please let me know if you find any bugs in the code or documentation. Anyway, here's a link: http://kevin.org/frc/frc_camera_22.zip.

Edit: I found a bug in the search code I published above, so don't use it.

-Kevin

Tom Bottiglieri 13-02-2007 07:21

Re: Camera Code Update
 
I found a bug in the old search code. Not sure if someone has seen this before or not. We have our camera mounted upside down. So, top is bottom and left is right. The camera still tracks the right way because the image is flipped, but the search code looks at the floor instead of the ceiling. When we have the target in front of the robot and elevated a bit, the search code freaks out. As it transitions from its max tilt pwm to its min tilt pwm, it does a diagonal. While traveling this path, it gets a new t packet (I see the red light on the camera flash) as it passes where the light is. As soon as it gets to the other corner, it doesn't see the light anymore, but it continues to drop to the middle tilt search pwm and scan on that level, at which it does not get a new t packet.

This problem will go away when we change the search code to our own algorithm, but I still think it is a bit of a problem.

Tom Line 13-02-2007 08:09

Re: Camera Code Update
 
I'd like to make one suggestion - we've found the common sense says the light is probably closest to the position that you lost at it. If you comment out the "New_Search = 1" line in the old code, the camera will just continue searching from it's current location.

Generally it results in a much quicker lock, because if it was only a temporary loss of the light (say a robot drives in front of you) the camera may well catch the light on the next pan, rather than resetting the tilt completely and starting a new search.

This is especially true when the robot is under the light to score. It also fixes the issue some teams are having where the camera "freaks out" and starts doing the tilt down then pan that someone else mentioned here.

jdejoannis 13-02-2007 11:55

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 577244)
I've uploaded version 2.2 of the bells & whistles camera code. See the attached document for a list of changes. As it's very close to the ship date, I would caution everyone to think really, really hard before ripping open your nearly complete code and dumping my changes in. For this reason I'm not sure if I'll add a link to this code on my website before the ship date. I guess I'll wait to see what the Chief Delphi crowd thinks. As always, please let me know if you find any bugs in the code or documentation. Anyway, here's a link: http://kevin.org/frc/frc_camera_22.zip.

Edit: I found a bug in the search code I published above, so don't use it.

-Kevin

Don't use what? Are you saying not to use v2.2 altogether?

Kevin Watson 13-02-2007 12:38

Re: Camera Code Update
 
Quote:

Originally Posted by jdejoannis (Post 577415)
Don't use what? Are you saying not to use v2.2 altogether?

No, I meant the snippet of search code I included in this posting. The problem is that when a new search is initiated, the servo PWM values could be initialized to values outside the min/max PWM range set in the code, which could lead to wacky behavior. I haven't had time to look at it yet, but the same bug may be present in older code. The new search code is easier to read and comprehend, should work better, and provide a better foundation for those that want to modify it for their specific needs.

-Kevin

jdejoannis 13-02-2007 13:40

Re: Camera Code Update
 
Does line 365 need to be changed to Tilt_Min?

Kevin Watson 13-02-2007 13:59

Re: Camera Code Update
 
Quote:

Originally Posted by jdejoannis (Post 577482)
Does line 365 need to be changed to Tilt_Min?

No, I changed it to Tilt_Center_PWM so that you can specify a starting angle for searches other than Tilt_Min_PWM, which is currently zero degrees. The comment associated with TILT_CENTER_PWM_DEFAULT in tracking.h was updated to reflect this change. Thanks for helping with the bug hunt.

-Kevin

jdejoannis 13-02-2007 15:00

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 577494)
No, I changed it to Tilt_Center_PWM so that you can specify a starting angle for searches other than Tilt_Min_PWM, which is currently zero degrees. The comment associated with TILT_CENTER_PWM_DEFAULT in tracking.h was updated to reflect this change. Thanks for helping with the bug hunt.

Are you sure? I believe its line 339 that pertains to the initial position for a new search. Line 365 is for when the tilt has exceeded its max. Tilt_Min_PWM is not mentioned even once within the search portion of the code.

Jason

Kevin Watson 13-02-2007 15:38

Re: Camera Code Update
 
Quote:

Originally Posted by jdejoannis (Post 577526)
Are you sure? I believe its line 339 that pertains to the initial position for a new search. Line 365 is for when the tilt has exceeded its max. Tilt_Min_PWM is not mentioned even once within the search portion of the code.

Jason

I'll have a look...

-Kevin

Kevin Watson 13-02-2007 16:01

Re: Camera Code Update
 
Quote:

Originally Posted by jdejoannis (Post 577526)
Are you sure? I believe its line 339 that pertains to the initial position for a new search. Line 365 is for when the tilt has exceeded its max.

Both lines of code return the tilt servo to the starting tilt angle, which may or may not be zero. The code as it is currently configured, does not change the tilt angle from 30 degrees because the vertical field of view of the camera from that angle can see the light from most of the field, including the entire starting area.


Quote:

Originally Posted by jdejoannis (Post 577526)
Tilt_Min_PWM is not mentioned even once within the search portion of the code.

Yes, I know. Tilt_Min_PWM is only used by the tracking algorithm to establish the minimum PWM value that the tracking algorithm will attempt to drive the servo to. Tilt_Center_PWM establishes the same baseline while tracking.

I realize that this may be confusing, so perhaps I need to consider changing the name(s) to something else.

-Kevin

jdejoannis 13-02-2007 16:17

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 577559)
I realize that this may be confusing, so perhaps I need to consider changing the name(s) to something else.

I got you now. You want it to search from 30-90 degrees and track from 0-90 degrees. I don't really see why they should be different ranges. Could just as well set the min to 30 rather than 0 (and use it as the starting point). This will work fine though, thanks!

Jason

Kevin Watson 14-02-2007 16:59

Re: Camera Code Update
 
How's it going with this code? Any problems, complaints, etc? Should I go public with it? Does Diet Pepsi taste better that Diet Coke?

-Kevin

DanDon 14-02-2007 17:33

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 578306)
How's it going with this code? Any problems, complaints, etc? Should I go public with it? Does Diet Pepsi taste better that Diet Coke?

-Kevin


So far, after small amounts of testing the new code (i.e. seeing if it searches and tracks, and testing the menus), I have not found any bugs.

Tom Bottiglieri 14-02-2007 17:37

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 578306)
How's it going with this code? Any problems, complaints, etc? Should I go public with it? Does Diet Pepsi taste better that Diet Coke?

-Kevin

For some reason I was under the presumption that the tracking software was broken. I'll start testing tonight.

whytheheckme 14-02-2007 17:39

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 578306)
Does Diet Pepsi taste better that Diet Coke?

-Kevin

Duh..... Diet Pepsi (Boycott Coke!!)

Diet Pepsi is the best soda ever!

Jacob

gnirts 14-02-2007 23:42

Re: Camera Code Update
 
Quote:

Originally Posted by Kevin Watson (Post 578306)
How's it going with this code? Any problems, complaints, etc? Should I go public with it? Does Diet Pepsi taste better that Diet Coke?

I don't know if it's significant, but I found the PWM center values were way too high at the defaults. They are both under 15,000 now (so that tilt goes 0* thru 90* and pan goes -45* thru 45*). Maybe my servos are just mounted funky? And just out of curiousity, how did you decide 90* was enough in the pan direction?

Also, what are your thoughts on adjusting the PWM Pan Center so that 127 causes pixel 80 to be on the center of the bot? Right now, when you square up the camera with our chassis, the actual field-of-view (which we found to be around 42* in the pan direction) is about 75% on the right side of our 'bot. (We have adjusted the Pan Target pixel so that when tracking the camera unit points straight at the target, but now I am thinking that this isn't really desirable. Who cares where it points, you want the mx values on the center of the image sensor, right?)

Other than that, assuming merged the changes correctly into my copy of the code, it works just fine.

Thanks in advance,
Robinson Levin

jdejoannis 15-02-2007 13:22

Re: Camera Code Update
 
Quote:

Originally Posted by gnirts (Post 578556)
Also, what are your thoughts on adjusting the PWM Pan Center so that 127 causes pixel 80 to be on the center of the bot? Right now, when you square up the camera with our chassis, the actual field-of-view (which we found to be around 42* in the pan direction) is about 75% on the right side of our 'bot. (We have adjusted the Pan Target pixel so that when tracking the camera unit points straight at the target, but now I am thinking that this isn't really desirable. Who cares where it points, you want the mx values on the center of the image sensor, right?)

We adjusted the center pixel too. It was at ~40 and we moved it to ~80. The main reason was because we just didn't like the way it looked. But as an afterthought, it will probably be less likely to lose the target and revert to the search pattern. And if the camera looks dead ahead when it facing the light, then you can use PAN_SERVO to drive towards the target.

Jason

PS: see you soon ;)

gnirts 17-02-2007 00:38

Re: Camera Code Update
 
Quote:

Originally Posted by jdejoannis (Post 578804)
We adjusted the center pixel too. It was at ~40 and we moved it to ~80.

Are you sure these are the right values? IIRC the camera has 160 pixels in the pan direction, and the default was at 79. To center our camera on the target ours needs to be about 108.

Quote:

And if the camera looks dead ahead when it facing the light, then you can use PAN_SERVO to drive towards the target.
You still can if you go into pwm.h and adjust the PWM_CENTER value like so:
  1. Put the light directly in front of your robot (but far enough away from it, until its just a few pixels).
  2. The camera should aim to the left or right of it if the pan tracking pixel is at the center of the image sensor (default).
  3. Go into the tracking menu and step the pan PWM until the pan error is as close to zero pixels as you can get it.
  4. Add (127 - pwmValueWithZeroPanError) * 36 to PWM_CENTER for the pan PWM (or subtract. test which one helps).
Now a pan servo of 127 should mean the light is dead ahead (though the camera unit will be pointed away from it).

Is this better than changing the pan target pixel?

Thanks in advance,
Robinson

[note] The value 36 should be replaced with whatever you are using for the pwm gain you are using, but 36 is the default with the new code.

JimGRobot 22-02-2007 19:21

Re: Camera Code Update
 
Thanks for updating the camera code...

One thing that we added to tracking.c were two accessor functions for getting pan and tilt error. We tried using a combination of PWM error and these finer values to control our motors. I'm not sure it helps, but having the functions in tracking.c was convenient.

We had to move the pan_error and tilt_error vaiables from local to file-global to make this work, and added function prototypes to tracking.h.

If you don't want to make this change to your code, no worries, we can just tweak the new version...

Thanks,
Jim Greenhaw
Team 1388


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

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