![]() |
Camera for turning
I am using a combination of the camera and a gyro to turn until the camera is lined up with the green light. With the code I'm using the robot just rotates back and forth and will never stop. Is there a better way to accomplish this. Here is the code:
Camera_Handler(); Servo_Track(); temp_gyro = Get_Gyro_Angle(); tracking_state = Get_Tracking_State(); printf("gyro_angle = %d\r\n", (int)temp_gyro); if(capture == 0 && tracking_state == CAMERA_ON_TARGET ) { goal_angle = ((((int)PAN_SERVO - 124) * 65)/124); capture = 1; } milliradian_goal = ((goal_angle * 3.1415 * 1000)/180); if(capture == 1) { if((milliradian_goal - 60) < temp_gyro) { pwm03 = pwm06 = 150; //Turns robot left pwm04 = pwm05 = 150; } if(temp_gyro < milliradian_goal + 60) { pwm03 = pwm06 = 104; //Turns robot right pwm04 = pwm05 = 104; } if(((milliradian_goal + 60) >= temp_gyro) && (temp_gyro >= (milliradian_goal - 60))) { pwm03 = pwm06 = 127; pwm04 = pwm05 = 127; capture = 2; } } |
Re: Camera for turning
Quote:
|
Re: Camera for turning
The motors on the left side have to go in reverse in order to move the robot forward. So by using the same number the left side wheels and the right side wheels go opposite directions.
|
Re: Camera for turning
OK, we usually wire the motors up with the left motor polarities being opposite the right motor polarites so that 254==full forawrd on both the left and the right sides. Sorry bout that. In this case I would suggest using a proportional control loop where the output applied to the motors scales itself to the amount of error, lestening the oscillations.
|
Re: Camera for turning
I have messed around with control loops before build season but never could get one to work correctly. Could you post example?
|
Re: Camera for turning
Making the motor speed proportional to the error will stop the oscillations if the proportional constant is low enough. But then you'll probably find the robot won't quite get to the desired angle, and you'll want to add some error integration to force it to move after it's been off-angle long enough. At that point, you might have some overshoot, and to fix that requires some negative feedback based on the rate of change of the error.
In short, it's time to implement a PID control system for your robot direction. Search the forums to find plenty of information, and even some code, that will do what you need. |
Re: Camera for turning
I have actually searched all over chiefdelphi for information. I found a lot except that I couldn't find anything about an output to control more than one pwm.
|
Re: Camera for turning
i actually have a bit of code that may help you.
PHP Code:
|
Re: Camera for turning
Thanks, I'll try that. One question: What's the limit mix for. I have never seen it on a control loop.
|
Re: Camera for turning
limiting output, of course. you don't want your unsigned char to overflow, that would be bad
|
Re: Camera for turning
Quote:
|
Re: Camera for turning
While using your code how do i implement a target value and how do I out put it to four motors. Sorry for all the questions but PID loops are still very new to me.
|
Re: Camera for turning
the function is returning a motor value from 0-255. it is up to you to map it to your motors, like you would a joystick.
as for inputting the error... you need to figure out your error much like you did in your original loop. with the dual targets this year, though, you will have to do a little (lot) of extra math and AI to get your desired target. |
Re: Camera for turning
Quote:
All you had to do was ask...:cool: |
Re: Camera for turning
Thanks a lot for all of your help. I finally got a PID loop running and it works great.
|
| All times are GMT -5. The time now is 04:13. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi