Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Camera isn't working (http://www.chiefdelphi.com/forums/showthread.php?t=43934)

Idaman323 13-02-2006 17:37

Camera isn't working
 
Hey, I have been working on this camera code for a while now... nothing seems to be working. This is what I have done so far.

I downloaded Kevins FRC code.
Opened it in MPLAB
Put in the Default_Routine(); in the Process_From_Master_uP
Changed it pwm03 = p1_y and pwm04 = p2_y
Commented out pwm01 and pwm02
I plugged a motor that we are using for pan into the pwm01
I plugged the servo we use for tilt into pwm02
Made the code
I used the IFI_Loader to put the made code onto the robot

The terminal window comes up and the "Searching..." does not come up and the camera does not move at all. The camera has the cable going from it to the TTL port. And the TTL is in the Robot Controller.

Right now I am powering the cam on the robot using the backup battery because I am not sure how it gets powered. I am not sure why the camera is not working. Is there anything I am missing?

Thanks in advance, Sorry for all of the trouble I am giving you guys!! I am the only one who knows anything about programming on my team. So anything would help. Thanks!!

Idaman323

nehalita 13-02-2006 18:06

Re: Camera isn't working
 
Um, a few questions
1) Did you check kevin watson's faqs on his site?
2) Is your backup battery charged?
3) Do the green/red LED lights show up on the camera?

Alan Anderson 13-02-2006 21:02

Re: Camera isn't working
 
Three things. First, you didn't mention having connected the OI to the RC (with either a tether cable or a pair of radio modems). The program won't run until you do that. Also, you said you're panning with a motor on pwm01, but that won't work using Kevin's camera code. You'll have to get a bit fancier than that in order to control the position rather than the speed of the motor. Finally, you should be powering the camera from a pwm output on the RC, which gets its voltage from the backup battery.

Idaman323 14-02-2006 16:42

Re: Camera isn't working
 
Okay the backup battery is powering the pwm. Ill go do that. The backup battery was never on. Yes the LEDs come on.

The robot is connected to the OI through a radio.

Okay so there isn't a way to use the motor for pan? The the gun and the camera will always be pointing in the same direction. Does that matter?

Is there a way to turn the turntable and the tilt the gun after the camera finds the target. Do we have to have some kidn of sensor. I really dont want to change our whole design a week before the ship date.

Thanks so far.
Idaman323

Alan Anderson 14-02-2006 16:59

Re: Camera isn't working
 
A servo is a tiny motor with a built-in position sensor, along with a small circuit that controls the motor in order to make the sensed position match the commanded position. You will need to duplicate that sort of system with a motor from the Kit of Parts and a position-sensing device such as a potentiometer, along with programming that controls the motor in order to make the sensed position match the commanded position. A simple algorithm would be to find the error between the desired and measured positions and drive the motor in the appropriate direction until the error is near zero.

For a fancier and more effective algorithm, search the forums for PID position control.

Idaman323 14-02-2006 17:12

Re: Camera isn't working
 
Okay,

I kinda sorta understanding this. Did the kit come with this sensor. Or do we need to go out and buy one. Do I need a sensor for both the tilt and pan of the gun. If I need to go out and buy a sensor. Is there a store I could get it from or do I need to order it off of the internet.

EDIT: Okay I also dont understand why we cant use the motor without the sensor. Out robot is using the pan for both the gun and the camera. They use the same motor. So the camera should focus in onto the light. Correct? So the pan motor should always be focusing on the light. As for the tilt, we are using a globe motor with the...not sure what its called... the pole with threads on it and the black plastic thing that slides up and down on it :). Would a sensor still work with this?

Also maybe, does anyone have a messanger that i could talk to them later tonight to make this a little easier. Thanks!

devicenull 14-02-2006 18:06

Re: Camera isn't working
 
Theres a difference between the servo's and the motor:

Lets say you have a servo on pwm01 and a motor on pwm02. You then set them both equal to 200. (pwm01=pwm02=200;)
With the servo's, your command of 200 represents POSITION. The servo will move to where it thinks position 200 is, and stay there.
With the motor's, your command of 200 represents SPEED. The motor will start spinning forward.

It sounds to me like you locked your camera and gun's pan together. Doing so, you lose the advantage of being able to use the included code. Your pans while scanning for the target may also be slower. You gain the advantage of not having to compensate for an off-center camera.

There is a simple way to control the motor from the camera, without any sort of feedback on the pan mechanism. To do this, change PAN_SERVO to an unused pwm port, and don't hook anything up to it, then take a look below:
Code:

if PAN_SERVO is facing left
PAN LEFT
else if PAN_SERVO is facing right
PAN RIGHT
else
DONT PAN

When the camera locks on to something, it will start trying to pan towards that object. The above "code" will read which way it is trying to pan, and pan for it with your rotation mechanism. It works pretty well, provided that your turret can keep up :)

Idaman323 14-02-2006 19:42

Re: Camera isn't working
 
So would it be something like this or am I doing it wrong?

Code:

        if(pan_error > (int)Tracking_Config_Data.Pan_Allowable_Error)
                       
                pwm01 = 200

                        else if(pan_error < -1 * (int)Tracking_Config_Data.Pan_Allowable_Error)
                        {
                                // calculate how far we need to step the pan servo
                                servo_step = pan_error / (int)Tracking_Config_Data.Pan_Gain;

                pwm01 = 60

                        }


Is it anythign even relativly close to this..? Maybe someoen could helpme with this part.

Also.. this is the code for the Pan. But what now for the Tilt?

devicenull 14-02-2006 22:59

Re: Camera isn't working
 
You do not even need to modify the tracking code. If you check the value of whatever PWM the pan servo is on, after the tracking code has done it's magic, you will know which way to turn... Don't even look at the tracking code right now.

What PWM is PAN_SERVO set to?
I have code similar to this:
Code:

if (PAN_SERVO > 127) TURRET = 255;
else if (PAN_SERVO < 127) TURRET = 0;
else TURRET = 127;

That code is in Process_Data_From_Master_Up, and is working fine.

Idaman323 15-02-2006 08:02

Re: Camera isn't working
 
Okay, I was talking to bombadier337 yesterday. He was telling me this would work fine but I would need it to have a bigger dead zone otherwise the motor will be jumping back and forth tryign to land right on the target. Also, he said I should make it so the farther away the target, the faster the turret spins. So maybe something like...

Code:

if (PAN_SERVO > 210) TURRET = 255;
else if (PAN_SERVO > 170) pwm01 = 180;
else if (PAN_SERVO > 150) pwm01 = 150;
else if (PAN_SERVO > 140) pwm01 = 140;
else if (PAN_SERVO < 114) pwm01 = 110;
else if (PAN_SERVO < 100) pwm01 = 100;
else if (PAN_SERVO < 60) pwm01 = 60;
else if (PAN_SERVO < 40) pwm01 = 30;
else pwm01 = 127;


Okay, that should be something like that. And it does need to be before PutData... right? Ill have to try it today after school. THANK YOU bombadier337!! And the rest of you.

Now for the Tilt. We were talking.... with the setup I have... would the Geartooth work for making the tilt of the gun. We have the threaded pole and it turns to raise and lower.

devicenull 15-02-2006 13:53

Re: Camera isn't working
 
If I had pasted the exact code I used, it would have confused you more :)

See, you don't need that giant if block. As the code tells the servo to move closer and closer to the center of the target, the value of PAN_SERVO decreases more and more, until it reaches 127. So if you left it alone, it would slow down as it reached the center for you.

Depending on your turret design, the code that I gave would have turned back and forth over and over trying to line itself up correctly. It may have worked how it was, it depends on your robot design.

The tilt code is going to be very, very similar to the pan code.

You may need to add some limit switches, mechanical stops, or both to prevent the turret from spinning too far.

Idaman323 15-02-2006 16:38

Re: Camera isn't working
 
Okay, well, I dont think it will work like the pan is. The camera isn't attached to the gun. So it wont center onto the light. The camera will have its own individual tilt from the gun. So if there is anotehr way.. please explain... or do I need to get a sensor. Or can I use the gear tooth or something like that. If all else fails... would there be a way to chagne the speed of the motors instead. I would rather not do this if I can get a sensor though. Maybe a Gyro? or Pentiometer... or....?

Idaman323 15-02-2006 18:25

Re: Camera isn't working
 
Okay, so I just went out and bough two pententiometers. Now to figure out how to program them... .. .... ... .. . . ... ... ... .....

Did we get two limit switches with the kit. Because we need four... and we bought two. Just wondering if they had more. Is there somehting can help me program these things.

PS. Sorry for asking so many questions. Its so disorginized in our room... hard to find things.

devicenull 15-02-2006 23:18

Re: Camera isn't working
 
Well, if you get the pot's installed, then you won't need limit switches, as they should be able to tell you how far you have rotated and in which direction. The pot's themselves get connected to the analog inputs, and I believe you need to use something like Get_Analog_Value to actually get sensible data from them. I can't check right now, because I just shut down the computer with all my code on it.

If you do a search for pot's, you should be able to find more detailed help on them


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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi