How do you interface the streamlined version of Kevin’s CMUCam code with the default code? I understand that you change the position o fthe robot as a whole based upon the pulses you send to the camera’s servos, but how or where do you put the camera code into the default code?
The default code, from what I understood, focuses on giving you the simplest code to control your robot. It doesn’t include other components except those related to the “cart”.
Kevin’s CMU code takes the default code and adds the camera functions and varibles so you can use them to work on targeting the lights on the rack and using the functions and varibles to do things around the arena(such as going to the spiders).
I’m affraid that using the default code with the camera won’t be possible(you’ll be controling the tilt of the camera with the Y axis of your joysticks ).
You shouldn’t have any problem at all using codes you’ve written in the default code(and those that actuall worked) and transfer them to the CMU code. The CMU code is there to give your more options.
Hope I helped and good luck!
You don’t. Instead, you do it the other way around, and make the necessary modifications to Default_Routine in the camera code project. Just map the OI inputs you need to the motors and relays you’re using, and make sure you let the camera tracking code control the servos.
Then, when you have the robot running manually and the camera still tracking the light at the same time, you can start getting fancy with software to run the robot automatically based on what the camera is telling you.
I have a question. Do I need to measure the degree angle of the camera (pan/tilt) and do I need to use it in order to allow the robot to move itself during manual routines?
if (get_tracking_state() == CAMERA_ON_TARGET)
{
set pwm values;
}
Would that work? Might I put this in Process_Data_From_Master_uP?
Also, I’d need to calculate the distance to the light in order to stop the pwm’s? (if so…I know the formula, but how the heck to I get it to work? I don’t even know where to begin for that)
Well, you asked me to answer like this, so my answer is yes.
Cool. Now I see that the camera code is just kind of inserted into the default code. How convenient, no?
Yep, just one thing, you’ll need to commnet/uncomment some code lines in the camera code in order to use some of the default code stuff, such as the engines. It’s more of where exactly you call the functions. Don’t worry, if something doesn’t work in your code(and it was compiled succesfuly) it probablly means that you need to change the place where you call the code lines or functions.
Really, it’s no big deal.
yeah, i heard about uncommenting some functin like “default_routine()” or something like that and change something with PWM01 and PWM02. What exactly is that that because it confused me, and it didn’t work.
Uncomment Default_Routine() and comment pwm01 = p1_y and pwm02 = p2_y.
If you have two different sets of code trying to control one pwm output, the processor is well going to be confused just like you. When you write your code, you need to make sure only one set of values is output to a pwm at any given time. Therefore, when using Kevin Watson’s code, you need to comment out pwm01 and pwm02(or whichever you choose to use really). Look at the above post also.
I kind of figured that, but it didn’t work. the good thing is, it doesn’t matter anyway. I need to know how to work the camera from autonomous code.
Demothesis
You call the same processes used in user_routines.c. Off the top of my head, I think they are Camera_Hander(); and Servo_Track();.
Camera_Handler() *
Okay, camera_handler() and not servo_track()? Is there any other special code that I have to write or work around in order to use the PWMs in autonomous mode? If so, will it conflict with the values mapped to the camera PWMs?:o
Demothesis
Please help me, I can’t figure out how to use the camera to actually MOVE the robot. I have the camera code working along with the camera itself, but how do I move pwm01 (left drive wheel) and pwm02 (right drive wheel) individually according to the pan of the camera? I have no idea where to begin with this code. (I just got the code to work for the camera and I’ve been trying for weeks. Now I only have 2 days, Please help if you can)
Pretend you have your hands on the joysticks and you can see which way the camera is facing. What would you do in order to make the robot move where you want it to go?
In theory, all you need to do is write some software to read the camera tracking information and control the motors the same way you would do it with your hands. The details are up to you.
Here’s what I have so far
int I_Want_To_Search = 1;
int pwm01_On_Off = 1;
int pwm02_On_Off = 1;
int pwm03_On_Off = 1; //these are all at the top of user_routines.c Everything else is in Processfrom master UP (except TARGETRANGE] and FIND_DISTANCE())
if(I_Want_To_Search == 1)
{
Servo_Track();
}
if((Get_Tracking_State() == CAMERA_ON_TARGET) || (Get_Tracking_State() == TARGET_IN_VIEW))
{
pwm01_On_Off = 0;
pwm02_On_Off = 0;
pwm01 = 230; //Desired Forward Velocity
pwm02 = 230;
Switch3_LED = 1;
//printf("2"); //these statements are just to see if it worked
}
else
{
Switch3_LED = 0;
pwm01_On_Off = 1;
pwm02_On_Off = 1;
//printf("4"); //these statements are just to see if it worked
}
/*
if(Find_Distance() <= 50) //THIS DOESN"T WORK!! WHY NOT?
{
pwm01 = 127;
pwm02 = 127;
pwm01_On_Off = 1;
pwm02_On_Off = 1;
I_Want_To_Search = 0; //Stops calling Servo_Track(). THEN CALL ANOTHER THING
Switch3_LED = 0;
//printf("3"); //these statements are just to see if it worked
}
*/
if(p1_y > 129 || p2_y > 129)
{
pwm01_On_Off = 1;
pwm02_On_Off = 1;
}
else if(p1_y < 125 || p2_y < 125)
{
pwm01_On_Off = 1;
pwm02_On_Off = 1;
}
The Find_Distance() function is this:
unsigned int Find_Distance(void)
{
return(targetRange[pwm07-144]);
}
and target range is this: (I just changed this, but the new values are on my other computer. So that might be the problem, but ya never know. Look at the bottom at my explanation to see if it makes sense)
const rom unsigned int targetRange] =
{
3355,
1676,
1116,
835,
666,
553,
472,
411,
363,
325, //place 10
293,
267,
244,
225,
208,
193,
179,
167,
156,
146, //place 20
137,
128,
121,
113,
107,
100,
94,
89,
83,
78, //place 30
73,
68,
64,
60,
56,
51,
48,
44,
40,
36, //place 40
33,
29,
26,
23,
19,
16,
13,
10,
6,
3, //place 50
0, //place 51
};
SoThere are a few problems with this so far. My Find_Distance doesn’t seem to be working. (Default Max tilt is 194 and min is 94, center at 144. Should I change these? My degree per pwm step is 1.9608 (100/51? is that right?) Then I multiplied that by the pwm indexes up to 51 and found the degree value and then the radian value and plugged it into TAN(x) and then did 116-12.625(my height)/tan(the radian value from before)) Assuming that’s correct, what’s wrong with the rest of the code? It’s not working properly. Camera looks away from the light when I comment in the Find_Distance code (less than 50 or whatever). This could be because I just changed the degree per pwmstep to 1.9608 from 1.7something. I have yet to change the values in the code. I will do that tomorrow. Also, to move the robot forward could I do something like this?:
if((Get_Tracking_State() == CAMERA_ON_TARGET) || (Get_Tracking_State() == TARGET_IN_VIEW))
{
pwm01_On_Off = 0;
pwm02_On_Off = 0;
Switch3_LED = 1;
if(PAN_SERVO > PAN_CENTER_PWM_DEFAULT)
{
pwm01 = 180;
pwm02 = 74;
}
else if(PAN_SERVO < PAN_CENTER_PWM_DEFAULT)
{
pwm01 = 74
pwm02 = 180;
}
else
{
pwm01 = 180;
pwm02 = 180;
}
}
That make any sense? Thanks for your help
by the way…pwm01_On_Off maps pwm01 to the p1_y joystick. (same with 2) So if its 1, it maps it so the joystick functions. If its not 1 then the joystick cannot function so the camera will take control of pwm01 and pwm02.
you just need to tighten up the code a bit