We want to put a potentiometer on our control board for controlling our turret. I think i know how to program it if we were to put another potentiometer on the actual robot but there’s no room and i don’t want to mess around with the gear tooth sensor. Is there anyway to rotate the potentiometer and based on how many degrees it rotated turn the motor for the turret on for a certain amount of time???
Yes it can easily be done.
Goto http://www.ifirobotics.com/docs/oi-ref-guide-1-30-07.pdf and check out page 7-10 it will show you how to wire a potentiometer to one of the joystick analog ports. Treat it exactly like a joystick input. You should receive a value between 0-255 all you have to do is map that to 360 degrees.
The best way to do this is a PID control loop, with two inputs:
-
The potentiometer hooked up to one port of your OI telling it the desired angle of your robot
-
A potentiometer on the bot telling the current angle of the turret.
For the PID loop itself, it will look something like
error=phi-theta; // phi is current turrent angle, theta is desired angle
// make sure that the units match on both
Kp=20;
omega=(long)Kp*(long)error/2000L;
// Set limit bands
if(omega>64){omega=64;}
if(omega<-64){omega=-64;}
motor_pwm+=omega;
how would i go about doing this in the code?? i’m really new to this programing stuff and don’t understand alot of it
If you want any decent control of the turret (or any other mechanism), you need to put sensors on it. Period. Potentiometers are pretty small. Surely you can find someplace around the turret that isn’t crowded out. (I’ve never seen a robot that full.) If this is a problem for you, I think you’re doing something wrong. (Also, limit switches of some kind at the ends of travel would not be out of order. Partly for calibrating the “pots”, mostly for keeping the bot from tearing itself apart.)
What you’re suggesting is to basically “dead recon” the turret. Yes this can be done, but as soon as a robot runs into whatever is attached to the turret and turns it, you’re hosed; all your movement will be off. (And heaven forbid you don’t put the turret in the same place at the start of every match. It starts off wrong, then.)
Any closed control loop (something with a sensor) will compensate for such movement.
All of these are important factors in FIRST, especially this year, because you can’t always see so well if your robot is on the far side of the field.
Bottom line: yes, you could do it, but it is far more worth your time to squeeze in those sensors.
I agree with Jamie, sensors, sensors, sensors, very important, for your robot to do anything more intelligent than blindly firing motors it needs information. Also, shameless plug, in my signature is a paper on PID control theory, and lots of examples, and common pitfalls and some tricks, let me know if you use it and if its any help!
In reply to kaszeta’s post, what you’ve described is a P loop only, there is no ID control in that, see the formulas in my paper for further examples of that control.
With just P you’re either going to under or overshoot a lot, and it will probably slip more because small errors won’t generate a significant output. Also I would never ever recommend starting with such a high gain, you’re just asking for something to snap around at full speed, but you did remember to include a speed limiter sanity check after, so it’s not really a problem, but you won’t see anything other than 64 in either direction until you have a really tiny error, which means more than likely an overshoot.
I’m tempted to make T-shirts that say this that the programmers can wear during the build season, since this seems to get forgotten most years, with the sensors being badly installed at the last minute. :ahh:
are motors or servos being used?
we are using a window motor. I went over the final design robot this morning and the drive train is in the way for placing the potentiometer. Eliminating this problem would call for some major design changes that we don’t want to start at this point. Does anyone one have a simple code that will measure the rotation of the potentiometer on the oi?
Reading the OI potentiometer is easy – just connect it between +5 and one of the OI analog inputs (x, y, wheel, or aux) on a joystick connector.
But without a position sensor on your turret, you won’t be able to do much with the value coming back from the OI. How will you know which way to drive the turret motor if you don’t know where it’s pointing at any given moment?
If you don’t have room for a pot on the window motor, how about putting a gear on the shaft it’s turning and putting the pot on a matching gear connected to it?
Yeah, I should’ve been clear that the example I gave is P-only code (the code I lifted it from was a full PID loop, but I figure it was best to leave some of it for the reader to implement themselves).
If I had a dollar for every time this has happened… Too many times the sensors get added in as an afterthought.
You won’t get anything useful from the OI, you need feedback from the actual rotating turret to have a real control loop. Anything else is just open-loop control and prayer.
Methods for retrofitting some sort of feedback sensor include:
-
The abovementioned technique of adding a gear to the turning shaft, and hook a pot or encoder to that shaft.
-
Similarly, Team 95 has used friction wheels against the turning shaft. I don’t recommend this, since it almost always will have a bit of slip.
-
Depending on the shaft size, you might be able to put a gear or nubs on it and use the Gear Tooth Sensor (note that with just one sensor, you won’t be able to tell direction of rotation).
-
You can get shaft encoders that slip over an existing shaft, but you might have trouble procuring these in time.
-
I’ve seen string potentiometers (both professional and jury-rigged) used in all sorts of interesting setups where nothing else fit, if you can find or make one in time.
I want to see the picture of this turret with absolutely no space in its entire 360° for a ¼" by ¼" potentiometer. (You couldn’t point it the other way and have it over the drivetrain?)
Bottom line: You MUST put in a pot if you expect any decent control. (How can I emphasize it further?)
Give me sensors or give me death!
A sensor is worth a thousand words.
A sensor in hand is worth two in the bush.
Early to wire and early to read makes a robot healthy, wealthy, and wise.
When the pot’s away, the arms will play.
A sensor a day keeps the mentor away.
A pot is a bot’s best friend.
The sensor is always nicer on the other side.
Hell hath no fury like a sensor ignored.
Knowledge is power.
Sensors are made, not born.
It’s not whether you win or lose, it’s how you read your pots.
A bot is known by the sensors it keeps.
i was wondering how much your arm weighs now
You can use one of the gear tooth sensors suplied with the kit, with a sprocket on the window motor.