Where do I begin to get the robot to move using the camera?

This is what I have? I haven’t done anything with turning the robot to the correct degree, I’m not very good at this stuff and I’m the only programmer and electrician on the whole team of 5, so i’d really like some help. Here is what I have for this:

if(Get_Camera_State() == 1)
	{
		if((Get_Tracking_State() == CAMERA_ON_TARGET) && (Find_Distance > set closest range)
		{
			pwm01 = desired forward velocity;
			pwm02 = same forward velocity;
			Switch3_LED = 1;
		}
		else if((Get_Tracking_State() == CAMERA_ON_TARGET) && (Find_Distance() <= set closest range))
		{
			pwm01 = 127;
			pwm02 = 127;
			Camera_Idle(); //Sets Camera in OFF mode so manual mode can continue.
			Switch3_LED = 0;
		}
		else
		{
			Switch3_LED = 0;
		}

Does any of this make sense? I think that Camera_Idle() will stop the whole process of moving the camera around, right? Later I have a button that I press that calls the Restart_Camera funciton which I think undoes the Camera_Idle() process, right? wrong? some help would be great. Also, will this work with moving the robot forward while the CAMERA is on target and the range (Find_Distance) is greater than the range that we want to be at when the robot stops. It looks to me like it would make sense but I realyl don’t know what I’m doing. Thanks a bunch everybody.

I know what it feels like to work so many roles. I’m the eletriction, programming, and website guy on our team. Let’s see if I can help you any:

Have you tested your code at all or are you just trying this out?

I have found that the CAMERA_ON_TARGET state doesn’t work to well. Even if the camera has located the target and its pointing directly at the target, it will modulate and will toggle off and on within state which won’t even turn on a relay. Do something like:


if(Get_Camera_State()) 
{  // You don't need the 1. Anything positive will trigger it.

if((Get_Tracking_State() != SEARCHING && (Find_Distance() > set closest range))
 {
			pwm01 = desired forward velocity;
			pwm02 = same forward velocity;
			Switch3_LED = 1;
}else if((Get_Tracking_State() != SEARCHING) && (Find_Distance() <= set closest range)) {
			pwm01 = 127;
			pwm02 = 127;
			Camera_Idle(); //Sets Camera in OFF mode so manual mode can continue.
			Switch3_LED = 0;
		} else {
			Switch3_LED = 0;
		}
}

This routine is running continously so the camera will update its distance and will stop once in the proper range. I’m not sure how to answer your CAMERA_IDLE and reset questions. Atonomous mode is only 15 seconds so I’m not going to bother with disabling the camera. If you have it running during gameplay that’s another story…

The switch leds are really unessicary. Those turn on LEDs on the OI when the camera is on target. I took then out because we won’t be looking down too much during the game.

When you start getting down to coding the specifics of the routine, post again and we’ll help.

Thanks. I’m getting an error report though

if(Get_Camera_State())
	{
		if((Get_Tracking_State() != SEARCHING) && (Find_Distance() > 20) && (I_Want_To_Search == 1)) //(errored line)
		{
			pwm01 = 150; //Desired Forward Velocity
			pwm02 = 150;
			Switch3_LED = 1;
		}
		else if((Get_Tracking_State() != SEARCHING) && (Find_Distance() <= 20)) //(errored line)
		{
			pwm01 = 127;
			pwm02 = 127;
			I_Want_To_Search = 0; //Stops calling Servo_Track().
			Switch3_LED = 0;
		}
		else
		{
			Switch3_LED = 0;
		}
	}

The Find_Distance() function is this:

unsigned int Find_Distance(void)
{
	return(targetRange[pwm07-67]);
}

The error I get is this:

C:\USFIRST\frc_camera_s_21\CAMERA CODE\user_routines.c:254:Warning [2058] call of function without prototype
C:\USFIRST\frc_camera_s_21\CAMERA CODE\user_routines.c:260:Warning [2058] call of function without prototype

On the lines that I commented “//(errored line)”

What’s wrong?

I believe you are missing tracking.h in your #includes and therefore it does not find the prototype for Get_Tracking_State() which was called on lines 254 and 260.

Tracking.h is already in there. It still says the prototype error thing on those lines.

Here’s your problem you need to add a declaration of the function at the top of your user_routines_fast.c (or what ever file is running the camera code).

At the top below the includes add:

unsigned int Find_Distance;

and you should be fine. If that errors out just incase try this:

unsigned int Find_Distance(void);

It compiles now, I’ve changed some things here and there, but the robot wont move. I think I’m doing something completely wrong with the code. Check out this forum if you can help me out. http://www.chiefdelphi.com/forums/showthread.php?t=53916&page=2

Make sure there isn’t a call to the joystick values after the code. The default code calls Default_Routine(). So make sure that is still commented out, and any mapping of the joystick values is done before the camera tracking.

It all goes in order, so if you set a value for the motor speed after locking on, and then later in the function, go and overwrite the value with your joystick, its going to be assigned the joystick in the end of the loop.

Yes, no?

Thanks. I made these changes, hopefully it will work:

At the top of user_Routines.c I declared this

int pwm03_On_Off = 1;

Then in the Default_Routine() where I map to the joysticks I put this

if(pwm03_On_Off == 1)
  {
	pwm03 = p3_y; //ForkLift
  }

An example of my switch-case statements (for a metal sensor that increments the ‘count’ variable each time it passes…and there each time it passes certain things happen in the CASE…) is this

if((pwm03 < 125) || (pwm03 > 129))  //if py_3 is being used (forklift going up or down)
 	{
		if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, sends a signal...
		{
			count++; //Number of times tape passes through the sensor.
			Switch1_LED = 1; //Switch01 goes on when the tape passes the sensor.
		}
		else
		{
			Switch1_LED = 0;
		}

		switch(count) //for sensor module
		{
			case 1:			//if count = 1 then that just means that it passed through the first piece of tape which will be used to show that it is in full DOWN position.

				Relay2_green = 1;
				Relay2_red = 0;
				printf("count = 1");
				break;

			case 2:
		
				Relay2_green = 1;
				Relay2_red = 0;
				pwm03 != p3_y;
				pwm03_On_Off = 0;
				pwm03 = 127; //Motor stops when it reaches 1st level of rack.
				printf("count = 2");
				break;

There are more cases, but those are the basic formats of the others anyway. Basically for case 2: I want to have he motor pwm03 stop and the joystick not mapped to pwm03 anymore. I have this in my code that allows me to reset the counter and to remap pwm03 to the joystick (so we can move it again):
This is all still in Default_Routine()


             last = now;
	now = rc_dig_in04;

	last2 = now2;
	now2 = p3_sw_trig;

	last3 = now3;
	now3 = p3_sw_aux1;

//some other stuff, but then:

if((now3 == 1) && (last3 == 0)) //p3_sw_aux1 sets counter to 0 in case forklift needs to be reset.
	{
		count = 0;
	}


	if((now2 == 1) && (last2 == 0)) //p3_sw_trig sets joystick 3 y-axis to forklift motor. Use after each level.
	{
		pwm03_On_Off = 1;
	}

So, think this will work? there is a snowday at my school today and they wont let us in to work on the robot, so I have to wait another day before I can test any of this. Thanks

That won’t work because the next time around the fork lift is going to be reconnected to the joystick.

This does not do what you think it does:
pwm03 != p1_y;

Lets say p1_y is equal to 200 at the moment, so we have
pwm03 != 200;

Which means pwm03 is going to be set to 0 (for the moment). You will need an if or switch statement for your joystick.

Also you might want to put a
in your print statements. Keep up the good work!!

Jason

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)

		
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:

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
};

So I would like to know why my distance thing isn’t working (Max tilt is 194 and min is 94, center at 144. My degree per pwm step was 1.7647 (50/90? is that right?) Then I multiplied that by the pwm index up to 51 and found 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). ALSO, how do I program the robot to move forward???