|
Re: CMU Cam Autonomy code? NEED HELP B4 FRIDAY!
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
|