Go to Post The minute you get a functioning mechanism start working on a better one - [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 15-02-2005, 00:16
ZZII 527's Avatar
ZZII 527 ZZII 527 is offline
"Scale Electric Vehicle"
AKA: Shane Colton
FRC #0097
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2003
Location: Cambridge, MA
Posts: 366
ZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond reputeZZII 527 has a reputation beyond repute
Send a message via AIM to ZZII 527
arm-limitting gyro PD loop producing some strange results

In an effort to make our arm a bit more controllable (and less dangerous) we are trying to limit its rate of rotation with a gyroscopic feeback loop. The goal is to map the joystick position to a particular angular rate ranging from -30 degrees/second to 30 degree/second. Then, detect the error between that desired angular rate and the actual angular rate as measured by the gyroscope. By using this error and a PD loop, we want to adjust the PWMs of our arm motors to match the actual angular rate to the desired angular rate.

The problem we have been having is the code is only recognizing error in one direction. The arm will hold itself stationary with no problem. When we pull the arm up (which rotates the gyroscope in its negative direction), the feedback works correctly. When we pull it down, however, it does nothing. So the arm will stay still until it detects upward motion, then begin to correct downwards but not stop.

As far as I can tell, this is not positive feedback. Moving the arm upwards does indeed cause a downwards correction. The problem is that moving it downwards does nothing at all. I'm also almost positive that the gyro is mounted in the correct orientation and the PWMs are correct.

The two most likely things that I can think of are 1) I made some stupid math mistake...this is the possibility I am hoping for...or 2) I am using variable types that for some reason can't handle what I am trying to do with them and is reading negative numbers incorrectly.

Anyway, here is the code:

Code:
// variable declarations from top of user_routines.c
unsigned int gyro;
float desired_rate, actual_rate;
float error_new, error_old;
float gyro_center = 502.5; // from calibration
float gyro_range = 493.5; // from calibration
float p, d;
float pwm01_temp = 127;

...

// gyro code

gyro = Get_Analog_Value(rc_ana_in01);

// map joystick to rate between -30 and 30 deg/sec
desired_rate = ((float)p3_y - 127) / 127 * 30;

// detect actual rate from gyro, minus sign accounts for
// gyro mounting orientation (- gyro corresponds to + PWM)
actual_rate = -((float)gyro - gyro_center) / gyro_range * 75;

error_new = actual_rate - desired_rate;
p = error_new;                                  // proportional term
d = (error_new - error_old) / 0.0262;   // differential term
error_old = error_new;

// adjustment with no differential term (for testing purposes)
pwm01_temp = pwm01_temp - 0.01*p - 0*d;
if (pwm01_temp > 254) { pwm01_temp = 254; }
if (pwm01_temp < 0) { pwm01_temp = 0; }

pwm01 = (int)pwm01_temp;
pwm02 = 254 - pwm01; // to adjust for backwards-mounted second motor
Any help would be great! Thanks in advance.

-Shane
__________________
MIT Mechanical Engineering
>> College Mentor, Team 97: Cambridge Rindge and Latin School with The Edgerton Center, MIT Mechanical Engineering, Bluefin Robotics, and Draper Laboratory
>> Alumnus, Team 527: Plainedge HS

Last edited by ZZII 527 : 15-02-2005 at 00:22.
 


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
Updated: Example Gyro Interface Code Kevin Watson Programming 2 28-03-2005 04:36
Example gyro code released. Kevin Watson Programming 60 17-03-2005 18:32
Gyro Calibration roboticsjenkins Programming 11 21-02-2005 20:39


All times are GMT -5. The time now is 00:56.

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