View Full Version : gyro and shooting angle
CharlieWilken
22-01-2006, 23:48
Can someone explain to me how I could use a gyro to gauge shooting angles of a ball thrower. Lets say I wanted to shoot 0, 30 and 45 degrees. I want to put a switch on my Operator interface to change the angle. How would I wire the operator interface and how would I connect the robot controller and how would the default program be modified to control a motor to move until the gyro feedback gave the proper value? Is this asking too much??? :)
Tom Bottiglieri
23-01-2006, 00:14
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.
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;
}
Alan Anderson
23-01-2006, 00:42
The yaw rate "gyro" senses turn rates. To track the absolute angle, you need to know at which angle it starts, integrate the sensor signal to turn rate into position, and account for bias and drift.
For a vertical angle, the dual-axis accelerometer would be more appropriate. If it's stationary or moving at a constant velocity, it measures gravity quite well, and can tell you the angle it is at with respect to "down".
For your application, however, I'd use a potentiometer connected to the tilt mechanism to sense the throw angle directly.
you can also put a potentiometer on it and preset the angle to buttons on the OI.
CharlieWilken
23-01-2006, 01:24
Thank you guys for the input. It sounds like I don't want a gyro but want one of the various techniques that you described.
1. Using limit switches or light sensors - This idea is great however Im not sure how to use 3 limit switches with regards to moving in a particular directions. Even with the light sensing switches what tells the motor which way to start moving to find the next postion ( Thanks for the sample code by the way). A plus of This technique is it lends itself to visual recalibration after a major accident and repair job!
2. Potentiometer- This is a great idea because it has direction built in to a numeric value. However Im not quite sure how to physically set it up on the controller and OI. I assume you would use digital inputs on port 3 or 4 for the input and do something with the analog input on the robot controller for the potentiometer. How to program this I could use some help with?
- A team in search of a programmer!!! :)
CharlieWilken
23-01-2006, 02:03
Tom-
with regards to your 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;
[B]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;
See if Im doing this right:
from step two to wanted step 3 at full speed
Motor = 127 + (-1*127) = 0
that seems right
but from step 1 to 3
Motor = 127 +(-2*127) = -127
that doesn't seem right
or am I doing this wrong?
Tom Bottiglieri
23-01-2006, 11:35
but from step 1 to 3
Motor = 127 +(-2*127) = -127
that doesn't seem right
or am I doing this wrong?
Wanted - 3
Current - 1
3-1 = 2
2*127 = 255
127 + 255 = (in unsigned char talk) 255
CharlieWilken
30-01-2006, 00:30
Im trying to go with the potentiometer and see what happens. I have spliced a pot onto a PWM cable and stuck it onto the analog input on the robot controller.
When my programmer did a print f stament to read the input we found that it does indeed read from 0 to 1024 in integers.
Question 1
Assuming I want to use the 3 digital inputs on joystick port 4 to get change my angle of shooting to the integers 0, 300 and 400. How would I program this in such a way that it ramps down a little bit when it gets close to its destination so it doesn't overshoot the number due to momentum. I am using a motor and lead screw to change my positions.
Question 2
Is there a way to program the joystick to work with the pot on the angle making ramp to match values so that when the joystick is at rest the ramp is at 0 degrees. When the joystick is all the way back the ramp is at 45 degrees. Assume the pot dial moves ~300 degrees for the 1024 increments that the controller sees.
Question 1
Assuming I want to use the 3 digital inputs on joystick port 4 to get change my angle of shooting to the integers 0, 300 and 400. How would I program this in such a way that it ramps down a little bit when it gets close to its destination so it doesn't overshoot the number due to momentum. I am using a motor and lead screw to change my positions.
Search here on ChiefDelphi for "PID Controllers" for discussion and sample code on how to implement an appropriate feedback loop.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.