View Single Post
  #2   Spotlight this post!  
Unread 23-01-2006, 00:14
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,187
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: gyro and shooting angle

Well, it depends on what you are doing.

Are you changing the tilt angle of the shooter (up and down rotation, like when your arm picks something up), or the yaw angle (side to side roatation, like the turret on top of a tank) ?

If you only want to use 3 angles, it would probably be eaiser to use some kind of digital switch, like a limit switch or a light sensor, to detect when your arm is in the right position. You could then map a joystick button to a function you write, or create in EasyC that would move the shooting mechanism until it comes in contact with the switch.

The software side could be very simple... as simple as something like this.

In this code, your shooter will be set up with a limit switch at 3 predetermined positions, and will start with at least one of them closed. The Step variable tells you where you are. The WantedStep variable tells you where you want to be. The assignment statement for Motor tells you how to get there. The idea for "How to get there" is as follows: Speed controllers control motors at variable speeds by interpreting a PWM signal sent at it which contains a integer value 0-255. The speed contol interprets 0 as full reverse, 127 as neutral, and 255 as full forward. By subtracting WhereYouAre from WhereYouWantToBe, you can obtain which direction you need to move your motor. Multiply this by the scale factor and add 127, and viola, you have the PWM value to send to your motor. Then, check if you are where you need to be. If not, keep driving.
Code:
int Step = 1; //Step is what step your shooter is at. 1 = 0 deg, 2 = 30 deg, 3 = 45 deg. Your robot starts with the shooter at step 1.
int WantedStep = 1; //Where You Want to Be
unsigned char ScaleFactor = 127;// How fast you want your motors to drive (127 = fastest, you'll see why.)

void ControlShooter(void){

if(Button1 == 1) WantedStep=1;
if(Button2 == 1) WantedStep=2;
if(Button3 == 1) WantedStep=3;

Motor = 127 + ( (WantedStep - Step) * ScaleFactor ); //Motor values hit max and min at 255 and 0

if(Switch1==1) Step=1;
if(Switch2==1) Step=2;
if(Switch3==1) Step=3;

}