View Single Post
  #59   Spotlight this post!  
Unread 09-03-2007, 01:07
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Programming tricks (and former trade secrets)

Our drive code was such that 3/54 teams approached us specifically asking how we get such fine control of our robot.

I know this is a lot of code, and it's not very advanced, but man does it work well.

Code:
int driveScaleFactor = 3;

void Left(int speed) {
  pwm03 = Safe_Values(speed);
}

void Right(int speed) {
  pwm04 = Safe_Values(254-speed);
}

int Safe_Values(int roughValue) {
  int toReturn = roughValue;

  if(toReturn> 254) {
    toReturn = 254;
  } else if(toReturn < 1) {
    toReturn = 1;
  }

  return toReturn;
}

int Scale_Offset(int roughValue, int scaleFactor) {
  int toReturn = roughValue;

  toReturn = ((toReturn-127)/scaleFactor) + 127;

  return toReturn;
}

//// later, in Process_Data_From_Master_uP()

if(p1_sw_trig && p2_sw_trig) {
  Left(p1_y);
  Right(p2_y);
} else {
  Left(Scale_Offset(p1_y,driveScaleFactor));
  Right(Scale_Offset(p2_y,driveScaleFactor));
}
The advantage of having a function to assign pwm values instead of assigning them inline, is, obviously, you can add other functions like the one I did. Let me know if you use this!

I will eventually post code that uses PD control with encoders to drive in a straight line autonomously.
__________________
What place are we at? ... TODAI!