Go to Post We can help make those dreams, maybe. ;) - Adare180 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-01-2007, 20:41
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
Post 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;
}
}
  #2   Spotlight this post!  
Unread 25-01-2007, 20:46
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Camera for turning

Quote:
Originally Posted by DustinB_3 View Post
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(&quot;gyro_angle = %d\r\n&quot;, (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;
}
}
Why are you setting all four PWM outs to the same value? If you want to turn left, set your right motors forward and your left motors either stopped or reversed and opposite for turning right.
__________________
  #3   Spotlight this post!  
Unread 25-01-2007, 20:53
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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.
  #4   Spotlight this post!  
Unread 25-01-2007, 20:57
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
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.
__________________
  #5   Spotlight this post!  
Unread 25-01-2007, 21:33
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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?
  #6   Spotlight this post!  
Unread 25-01-2007, 21:52
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
  #7   Spotlight this post!  
Unread 25-01-2007, 22:18
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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.
  #8   Spotlight this post!  
Unread 25-01-2007, 22:24
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
Re: Camera for turning

i actually have a bit of code that may help you.

PHP Code:
unsigned char PIkDControl(char Kpchar Kichar Kdint error) {
    static 
int errorTotal 0;  //there is a better way to do this... meh
    
static int prevError 0;
    
int P 0;
    
int I 0;
    
int D 0;
    
    
= (error*Kp)/100;
    
= (errorTotal*Ki)/100;
    
= ((error prevError)*Kd)/100;

    
errorTotal += error;
    
prevError error;

    return  (
Limit_Mix(2000+127+P+I-D));

There are a couple of other tweaks, but i edited them out. you should come across them whilst testing (=
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY

Last edited by Uberbots : 26-01-2007 at 00:22. Reason: MINUS D NOT PLUS D... oops
  #9   Spotlight this post!  
Unread 25-01-2007, 22:26
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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.
  #10   Spotlight this post!  
Unread 25-01-2007, 22:47
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
Re: Camera for turning

limiting output, of course. you don't want your unsigned char to overflow, that would be bad
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY
  #11   Spotlight this post!  
Unread 25-01-2007, 22:48
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
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.
  #12   Spotlight this post!  
Unread 25-01-2007, 23:46
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
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.
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY
  #13   Spotlight this post!  
Unread 26-01-2007, 00:18
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Camera for turning

Quote:
Originally Posted by DustinB_3 View Post
Sorry for all the questions but PID loops are still very new to me.
PID Without a Ph.D

All you had to do was ask...
  #14   Spotlight this post!  
Unread 25-01-2007, 22:47
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Camera for turning

Quote:
Originally Posted by DustinB_3 View Post
...I couldn't find anything about an output to control more than one pwm.
A brief look at your existing code reveals that to be a non-issue. If you supply the same PID-computed value to all your motor pwms, your robot will turn in place. That's exactly what you want it to do, isn't it?
  #15   Spotlight this post!  
Unread 26-01-2007, 20:44
DustinB_3 DustinB_3 is offline
Registered User
FRC #0935 (Railerobotics)
Team Role: Leadership
 
Join Date: Nov 2005
Rookie Year: 2001
Location: Newton, Kansas
Posts: 78
DustinB_3 is an unknown quantity at this point
Re: Camera for turning

Thanks a lot for all of your help. I finally got a PID loop running and it works great.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Turning 18... Astronouth7303 Chit-Chat 16 22-05-2006 09:29
Turning Trouble! Cadetdan General Forum 18 05-03-2005 08:55
Slowing down Camera drive turning Zalumaskov Programming 1 27-02-2005 10:11
Connections For Camera Eupher Programming 3 02-02-2005 14:35
Canadian fined for turning left while on his Segway MrToast Dean Kamen's Inventions 2 21-10-2004 17:34


All times are GMT -5. The time now is 04:13.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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