Go to Post Let me tell you, the scariest day ever was the day that I realized since I am a mentor, people actually take my advice and I should be careful of what kind of advice I give. :ahh: - Elgin Clock [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 13-01-2007, 03:11
iBheat's Avatar
iBheat iBheat is offline
Registered User
FRC #0418 (Lasa Robotics)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Austin, TX
Posts: 24
iBheat is on a distinguished road
Re: Question about CMUCAM servo output

I haven't done any coding since the last FRC season so correct me if I am wrong. This is the way I would do it:
Code:
#DEFINE pan_allowance 5 //You have to allow for an allowance or your robot will jitter after the position is acquired
#DEFINE tilt_allowance 5 //Same thing as above
#DEFINE desired_tilt 190 //This has to be greater then 127 (which is the center) because if it was 127 then either you'll have to be really far away or the light has to be at the same height as the robot. I just picked 190 :)

unsigned char tilt;
unsigned char pan;

while (1) //Infinite Loop
{
	CaptureTrackingData(0, 0, 0, 0, 0, 0, 0, 0, &pan, &tilt); //Get the pan and tilt data back from the camera
	if (pan > 127 + pan_allowance) //The camera has to look to the right inorder to look at the center of the box
		Drive(255, 40); //Turn the robot to the right
	elseif (pan < 127 - pan_allowance) //The camera has to look to the left inorder to look at the center of the box
		Drive(40, 255); //Turn the robot to the left
	elseif (til > desired_tilt + tilt_allowance) //The camera has to look way too far up inorder to see the light meaning its too close
		Drive(0, 0); //Move the robot backwards
	elseif (tilt < desired_tilt - tilt_allowance) // The camera has to look below what it should to see the light so its too far away
		Drive(255, 255); //Drive forward
	else //If everything is right
		Drive(127, 127); //Don't drive!
}
Basically what happens is that first it aligns it so that it is parallel to the light and then it either moves forward or backwards to be with the light. I am not sure how you are doing the drive function but I assumed that what you are trying to do is Drive(Left Side, Right Side) and to go forward you would set both sides to a value greater then 127 and to go backwards you would set both sides to a value less then 127 which is what I did. Also you would want an allowance on both the pan and tilt which was discovered through testing that it would be very jittery if you didn't have it and it makes sense because the center of the rectangle might shift a little bit with each frame. Also you don't need a bunch of nested while statements unless you have some other piece of code that resets the values for the motors on the left and right side of the robot. Also I set the speed of the motors when going forward and backwards to full speed this is probably not a good idea since it'll pass it both ways again making it jittery what you want to do is test it and see what speed you can effectively track the green light at!

Last edited by iBheat : 13-01-2007 at 17:40.
 


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
Question about the CMUCam Dan Petrovic Programming 2 19-09-2006 21:27
Cmucam + track color + auto servo mode kheops1982 Programming 5 09-04-2006 13:32
servo output accuracy NextPerception Programming 9 07-02-2006 11:23
Servo behavior question / advanced servo/PIC programming question DanL Electrical 12 18-10-2005 18:33
Dashboard Output Question jnossen Technical Discussion 5 02-02-2002 19:52


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

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