I am really confused on how to write an auton code that uses the camera to find the green and then drive to it and aquire our angle with our tilt motor and then shoot the balls, i keep looking and looking on how to do so but i have no idea what to do, and i need to have this done by friday, preferably thursday (because we will be at the vegas regional). but if anyone can help me or if someone is really generous to accually write me one that i can manipulate to work for me im using the latest cmu cam coding from kevins site. thank you
Well, there are several steps to this. Let me assume that you are using MPLab and have the camera code in your project. If so:
- the auto code is coded in user_routines_fast.c, in the userAutonomousCode routine
- make use of the 3 functions that Kevin uses to track the light (info terminal, camera handler, servo track) - in that order.
- you will have full access to all the variables that you need, especially the getTrackingState function from tracking.c
- establish a path in which you want the robot to move, and use the 26.2 ms loop timer as a rough estimate (38 loops per second). Code that motion first - make it move in the direction you want (probably forward), and stop
- then, start calling the camera functions. You will have the getTrackingState info to establish when the camera is locked on the target
- once the camera is locked, you can manipulate and adjust your shooter/robot to whatever positions you want - use the pan servo and tilt servo aliases from tracking.h as reference
for example (my code is very simplistic, since we dont use any other sensors):
////////////// move forward //////////////////
if (AutoClock < 10) //AutoClock is a timer that counts every 10 loops
{
FWD(); //bot moves forward
}
else if (AutoClock < 35)
{
Stop(); //bot stops
AimFire(); //calls the camera aim routine [see below]
}
else
{
Stop(); //stop robot
//stop shooter
}
/////////////////// use camera to light up and fire /////////////
/* Camera Controls */
// send diagnostic information to the terminal
Tracking_Info_Terminal();
// This function is responsable for camera initialization
// and camera serial data interpretation. Once the camera
// is initialized and starts sending tracking data, this
// function will continuously update the global T_Packet_Data
// structure with the received tracking information.
Camera_Handler();
// This function reads data placed in the T_Packet_Data
// structure by the Camera_Handler() function and if new
// tracking data is available, attempts to keep the center
// of the tracked object in the center of the camera's
// image using two servos that drive a pan/tilt platform.
// If the camera doesn't have the object within it's field
// of view, this function will execute a search algorithm
// in an attempt to find the object.
Servo_Track();
/***************************************/
if (Get_Tracking_State() == SEARCHING)
{
AutoCMULookingForTarget = 1; //indicate if camera is locked or searching
AutoCMULockedOnTarget = 0;
}
else if (Get_Tracking_State() == TARGET_IN_VIEW | Get_Tracking_State() == CAMERA_ON_TARGET)
{
AutoCMULookingForTarget = 0;
AutoCMULockedOnTarget = 1;
}
if (AutoCMULockedOnTarget) //Line up if Locked
{
if (PanAngle < LeftLockLimit) //Camera is pointed LEFT -> turn LEFT
{
Left();
}
else if (PanAngle > RightLockLimit) //Camera is pointed RIGHT -> turn RIGHT
{
Right();
}
else //Robot is Horizonally Locked on target -> STOP Auto Alignment Procedure
{
Stop(); //stop robot
//Shoot
}
}
else //CMU Searching
{
Stop(); //stop robot
}
sorry for the messy code and long post
best of luck
Thank you, this should help me. Are all the variables initialized in the base CMU cam coding?
The variables you see there are my own aliases. All the variables that you use from the CMU code are in tracking.h and camera.h - I just aliased them to names more meaningful to me (i.e. PAN_SERVO is PanAngle). The counters and shooter controls are also my own of course. Your best bet is to look through tracking.h and read Kevin’s comments about every variable, then alias them to names that you can easily understand.
Here is a program I made for the camera workshop team 40 held. Its in easyC but it works great.
Check the easyC forum to download easyC for FRC.
4.3.2 Autonomous Tracking the Camera.zip (1.58 KB)
4.3.2 Autonomous Tracking the Camera.zip (1.58 KB)