Servomotor Control
Pivotnewb
Posts: 18
Explanation:
We were given a task to run a continuous servomotor for 45.5 seconds in a clockwise motion; record the number of rotations every 1/2 second and then at the end write the data to a USB to be read by "Data Logger PRO"
We deduced that we can use an RTC to help record the number of rotations.
My questions are as follows:
We were given a task to run a continuous servomotor for 45.5 seconds in a clockwise motion; record the number of rotations every 1/2 second and then at the end write the data to a USB to be read by "Data Logger PRO"
We deduced that we can use an RTC to help record the number of rotations.
My questions are as follows:
- How would we use the RTC to record the number of rotations?
- How would we then write down the data onto a USB (The data has to then be read by Logger Pro 3.8.2 found here: http://www.vernier.com/location/?redirect=/products/software/lp/
' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]------------------------------------------------- DataIO PIN 0 Clock PIN 1 CS1302 PIN 2 ' -----[ Constants ]------------------------------------------------------- ' -----[ Variables ]------------------------------------------------------- servomotor VAR Word '--------[Main routine]---------------------------------------------------- DO FOR servomotor = 1 TO 2275 PULSOUT 14, 1250 PAUSE 20 NEXT LOOPThank you!
Comments
I'm saying this because the results have to be taken down at the end of the duration (Which is 45.5 Seconds)
Then again by assuming that servomotor rotates at 1 Rev/Sec I can just say that it has rotated 45.5 times and carry on my merry way; but that's not the point. What I'm trying to do is figure out a way to grab the number of times the servomotor rotates using an RTC.
Sorry if I'm being hard to understand and thanks for all the help!
If anything needs clarification please don't hesitate to ask me.
But if it were me, I'd forget the RTC and use a higher resolution encoder and the COUNT command to count how many stripes passed in a given interval. Here's how I did it, counting stripes and stopping after exactly 1 full revolution:
http://www.youtube.com/watch?v=PfMnl4oGzs8
We don't have to use the RTC. It was a suggestion brought up by another team-member.
How would we implement this encoder into the code presented in the original post?
He's doing navigation using optical encoders, so there's more geometry there than you need, but he shows how to use encoders.
However is there any chance of getting a simple example on how Encoders work?
Or a code-template that I can take a look into that explains how to implement an encoder into your program?
By using a black/white optical disk.... even if you DID miss the transition when it happened, by alternating from black to white around the disk (as opposed to black lines on a white disk), you can still check for a change of state from the sensor.
If you do not have the luxury of a RTC, I guess the code would look like the following:
FOR k=0 to 91 run the inside loop 45.5 * 2 half second times
ROUTINESTART:
sensorflag = current sensor state
COUNT = 0
FOR i=0 to 25 (as in fifty checks per second (50Hz servo update).... twenty five checks per half second, which may have to be tweaked a bit)
PULSOUT to your servo
PAUSE 20
IF sensorflag <> current sensor state THEN COUNT = COUNT + 1
NEXT i
save COUNT somewhere, or display it, whatever
NEXT k
DEBUG COUNT
Thank you; this will help out a lot.
However; what do you mean "Don't have the luxury of an RTC"
Our first idea was to use an RTC - Can you clarify?
Edit: Actually! I just realized something...
To plot an accurate Rotations/Time graph we would still need an RTC; no matter how we gather the number of rotations we need to keep track of the time as well.
So I think I have to stick with the RTC and now we're at the beginning again.
How would I use an RTC to record the number of rotations?
Can I just use the Encoder to gather the number of rotations and the RTC to record the time and then use both data in the same log?
Thank you!
Edit2: After some work on it; here's what I came up with.
Can someone check it out for me? I'm sure it's not going to work in it's current state.
Would that work and solve my problem?
Please note that I still haven't programmed the Encoder; but I'll work on that soon.
The idea is, you know with fair certainty how long it takes to execute the loop, so multiplying that time by some number of times through the loop, you come up with a decent time base.
I've not used a RTC before and I can't check your code through right now, but it looks like it'll work. Heck, try it and see! The worst that happens is.... it don't work and you have to troubleshoot it DEBUG statements will be your friend for that. Don't worry about timing until the routines work though. DEBUG statements take an eternity to execute in the uC world.
Good luck!
EDIT: Code notes
Ok, #1 I made a mistake in that it should be FOR....1 to 25, which would execute 25 times and #2 the "rotations" variable name is as valid as any name, but it'll be a little misleading if you have multiple triggers around the encoder disk.... That's up to you though.
Ok guys; sorry again!
But I can't use an encoder at all apparently; the reason for this is because this (As I figured out recently) is a test for the hardware team for their project. They will not be using an encoder in the project so their is no reason for them to learn how to wire one up to a circuit-board. But they will be using an RTC so to clarify the project is to.
1) Run a servomotor for 45.5 seconds
2) Record number of servomotor rotations using only an RTC.
3) Record the data on a USB to be used later by Logger pro.
Sorry for the trouble.
I'll ask him today.
http://en.wikipedia.org/wiki/Furlongs_per_fortnight#Furlong_per_fortnight
Not so sure about this; But my instructor did indeed say that we were to only use an RTC and a Servomotor and then gather data (Number of servomotor rotations).
As to how to do it; that's up to me.
I still can't think of it logically; how would you record rotations using only an RTC?
average revs per second multiplied by elapsed time would work..... kinda. It'd be like throwing darts though.
That's all I have with no encoder
The simple way out of this is to make the Servomotor rotate at a fixed Revolutions/Second (Maybe 1 or 2)
So now my new question is:
How can I make my Servomotor rotate at 1 Rev/Sec using the Pulsout command?
Pulsout port, XXXX? What value should I set for XXXX to get it to rotate at 1 Rev/Sec
Cheers.
I should mention that we are using a continuous servomotor not a standard.
This is what I have so far:
The reason I think this would work as
Pulsout 14,1250 should do a 180 degree turn on the servomotor which can be considered a half rotation
So if 50 pulses = 1 second in the "For servoPulse = 1 to 25" then it should take 0.5 seconds for a 180 degree turn and 1 seconds for a full turn.
Therefore it should run for 91 half-turns in 45.5 seconds.
I can't tell whether what I'm doing is right or wrong at this point and would appreciate some help!
Thank you.
There is no correlation between the number you PULSOUT and the servo rotate speed across any two servos due to different gear ratios, quality, bearing type, etc. I would suspect even two servos of the same make and model may be a little different. Get yourself a stopwatch, run the servo for one minute using PULSOUT 1250... count the revs and divide. The number you PULSOUT should relate to the speed linearly..... I think....
Once you get your number, take note of the voltage, cause you're going to need to keep that constant between tests and on your presentation.
Spiral; I could do that but I'm supposed to figure out how to make it run at a steady rate that I can control.
Erco: I've run the program countless times.
First mistake was that the 91 half-rotations didn't work and I'm working on that at the moment.
As for the Rev/Sec I need to figure out how to control it within the program.
Thank you anyways.
You'll find out when you want to stop that there are 2 ways. First, just stop sending pulsouts, and your servo will gently coast to a stop. Or if instead you send pulsout 750s, the servo will stop suddenly using dynamic braking.
Be sure to let us know how the class does!
Everything going great in class - I've managed to borrow the Circuit board with the Data-logger, Servomotor, RTC attached so me and a couple of my team-mates can work on it in our free time (We live in a boarding school)
So right now we're working in and out of class to finish this A.S.A.P
This is all a practice run for a bigger project later on that we haven't decided on as of now.
I can consider this thread solved!
Most sincere thanks to Erco/Spiral you both had great suggestions and helped me think of many new and different ways to finish this program.