forward/reverse motion with standard servo?
Dan E
Posts: 61
I've noticed about every object or example I've read about programming a servo involves centering, or defining a center location. Is it necessary to do this for all servo applications?
I have a single standard servo that I want to rotate about 10 degrees clockwise by pressing one push-button, and about 10 degrees counterclockwise by pressing another push-button. The application is to aim a leightwight ramp (PVC pipe,0.75" diameter, 3.5lbs). The ramp has legs with castors that roll in all directions, 8 inches away from the pivot point to decrease torque.
Is there a straightforward object for forward and reverse motion for 1 servo? Also, I have a propeller servo controler, is it necessary to use the controller for only 1 servo?
Thanks,
Dan
I have a single standard servo that I want to rotate about 10 degrees clockwise by pressing one push-button, and about 10 degrees counterclockwise by pressing another push-button. The application is to aim a leightwight ramp (PVC pipe,0.75" diameter, 3.5lbs). The ramp has legs with castors that roll in all directions, 8 inches away from the pivot point to decrease torque.
Is there a straightforward object for forward and reverse motion for 1 servo? Also, I have a propeller servo controler, is it necessary to use the controller for only 1 servo?
Thanks,
Dan
Comments
There are a variety of servo drivers in the Object Exchange. All of them will drive from one to some maximum number of servos. Pick whichever one has the features you want and just use one servo with it.
Although you can use a Propeller Servo Controller with just one servo, it indeed seems like overkill. You can run the same servo driver (from the Object Exchange) on your own board.
If you're using a continuous motion servo, the normal feedback mechanism in the servo is disabled, so the control pulse width controls the speed and direction of the servo rather than the position. It's useful to have a centering adjustment on the servo itself to set the stop motion point of the control pulse width.
I've read through some objects and threads today, and learned that a 1.5ms PW corresponds to a center position, a 1ms PW rotates to a fully counterclockwise position, and a 2ms PW moves to a fully clockwise position.
If this is true, would sending out a pulse of 1.4ms or 1.6ms rotate my servo marginally clockwise or counterclockwise??
My servo is already attached inside of the mechanism I am using it for unfortunately, and opening it up may damage mechanical parts. Is it possible to make each stationary point after each motion the new center point?
Not marginally but approximally 10% of the full clockwise or counterclockwise turn as 1.5msec - 1.4 msec = 0.1 msec and 1.6msec - 1.5msec = 0.1msec
and a full turn is 2.0 msec - 1.0msec = 1 msec.
I want to explain a little bit more about how servo-control works
The servo contains an electronic circuit that compares ALL THE TIME WITHOUT ANY PAUSING the pulselength (1.0 milliseconds - 2 milliseconds) with the actual position of the servowheel.
As soon as there is a deviation between pulselength and wheelposition the circuit will drive the motor in the right direction to equalise pulselength with the corresponding wheelposition.
This is a closed-loop control. The pulselength is compared all the time with the position and in case of a deviation between what should be and what is - the deviation gets eliminated.
If you try to turn the servowheel by hand the circuit will try to keep the wheelposition with the full power the servomotor can give
If you change the pulselength the circuit will drive the servowheel to the new position corresponding with the new applied pulselength.
So if you want to have the servo staying at a certain position for hours days or months you just have to keep the pulselength at a constant value.
But it is NOT possible to say to the servo "now your new actual position is the new center."
If you tell us what you want to do in the end and if you give us an overview about your complete project I'm sure a good solution can be found.
best regards
Stefan
The project is a bowling ramp system for blind kids. The servo in my project is attached to a turntable with a small light-weight ramp attached to it with wheels. At the end of the ramp is a MaxBotix ultrasonic range detector. The PWM output signal from the range detector is feed to a piezo buzzer chime. Depending on the how frequent the chime noise is, this gives clues for kids which direction to aim the ramp so that they can locate and hit the closest bowling pins with a bowling ball.
So what I am looking to do is to move the ramp back and forth with the use of two push-buttons, just about 5 or 10 degrees each press of each button.
It sounds like this is very possible from the information you've given, I am new to programming in general since I am an electrical engineering student, I have a little experience in C, which makes makes the structure of SPIN somewhat understandable me, but I've received a lot of help from the manual, propeller tool, technical support, and the forum.
So it seems that as long as I send out a constant pulse every 20ms I can use the two pushbuttons I have to either decrement or increment the puslewidth and hold that position until altered. Is this correct?
Sending pulses every 20 msecs is done by the servodriver-object.
You simply integrate the servodriver-object into your SPIN-program and start the driver.
After that all you have to do is call a "Set Servo position" method once everytime you want to make the servos drive into a new position.
The driver will keep sending the pulses every 20 msecs all the time.
So you just have two variables that are incremented/decremented by the pushbuttons.
You use just these two variables to call the setposition method
best regards
Stefan
Thanks again,
Dan
Does this code constitute as a servo driver?
Thanks,
Dan
In that driver, if You change the line "tHa := tInc * 1500" to "tHa := tInc * 750 ", the Servo will turn left,
and if You change it to "tHa := tInc * 2450", it will turn to the Right... Yes this is correct...
There is a Servo Driver in the OBEX that says it will run 32 Servo's at once, but it does very well with just one Servo attached.
A Driver that has Ramping is also available. a very nice feature if You have a spare cog...
Does it require extra pins and/or input pulses to ramp? Also, would this be able to control torque?
Thanks,
Dan
No it requires no extra pins. Standard servos are always interfaced by just one pin. On this pinthe pulselength coded signal is transferred to the servo.
If you change the pulselength - let's say from 0.8 msecs to 1.7 msecs - the servo-control circuit sees a BIG
difference between its actual position and the new applied pulselength and will drive the servowheel as fast
as possible to the new position. For RC-cars or RC-planes that is what a servo should do.
Now the ramping does the following:
actual position "0.8msecs" new position "1.7msec"
the ramping creates a pulselength of
0.81msecs holding this value for a short time
0.82msecs holding this value for a short time
0.83msecs holding this value for a short time
0.84msecs holding this value for a short time
0.85msecs holding this value for a short time
etc. etc.
the holdingtime depends on the defined rampspeed
So the former immediate jump from 0.8msecs to 1.7secs is
divided into a lot of very small steps making the servo moving slowly.
You can't control torque through this. For controlling the torque you would have to reduce
the motorcurrent. But you can't go below a certain voltage at the servosupply-voltage because then
the control-circuit wouldn't work anymore.
One idea about this would be to measure the current externally and if it does exceed a limit
to switch of the voltage or driving the servo into the opposite direction to reduce the applied force
until the current is below the limit-value.
But how about building it in a way that the servomechanic can't be overloaded accidentically?
In the Servo32V7-object you have to activate every PIN you want to work as a servo-pulselength-output
If you just want two servos connected to PIN 7 and PIN 8
you would code
If you have servos handy connect them without the mechanic to your propeller and start
experimenting with it.
best regards
Stefan
5 to 10 degrees is alot for a bowling lane, Yes?
I suppose it wouldn't make that big a difference either way, the Stepper would need some extra hardware.
but I think the Aiming would be more "Robust", as in, a finer degree of movements...
Stepper Motors are kinda like Servo's on Steroids...
Not trying to talk You out of anything, in fact, You should master the Servo first, then move on to the Stepper Motor's.
The Servo's only require one "control" Pin from the Propeller, where a stepper requires at least four "control" Pin's.(not that you asked...)
I think the torque is "built in" to the Servo's
like when My BOE robot gets wedged under the couch or refrigerator, the Servo's draw more current,
giving the Servo's more Torque, and thus more power, up to a point,(the voltage regulator starts smoking)..
I am trying to say that You really can't "give" the Servo more Torque, it just makes torque, untill it can't make's no more.
in other word's, You can't Pulse the Servo any more then You allready are...
StefanL38 has a more eloquent explaination of how it all works..
Anyway's, good luck with the Kids, and keep us posted on the Bowling Ball Aiming Device..
So I attached here my sample code, first I used a sample object that centers the pin and holds the position, then I added a couple IF statements that would increment or decrement the puslewidth if a push-button toggled the pin's a.state. I commented on the parts I added or changed. Naturally it didn't work correctly, but my battery was low on power, so i am going out to get a new one.
motorProgram.spin
I'm positive that IF statements were the wrong choice, I think I need some interrupt sequence that runs the approriate code when the push-buttons are pressed. Also, not sure if just by pressing the push-button that it would switch that pin from low to high, perhaps I need to write some code that toggles the state.
When I power up my chip and servo, and load the program, the servo slowly jerks to the left then back repeatedly, barely moving from its originally position.
Any suggestions?
what is the reason for not using the Servo32-object?
%0
what is the reason for not using the Servo32-object?
If you like you can use this object with ONE pin creating servopulses
and all 31 pins left stay free to do any kind of other things beeing inputs or outputs.
If it would occupy all 32 IO-pins all the time it would be almost useless.
In your code you have several unconditional repeat-loops.
Your code wil stay in the first repeat-loop as the loop is unconditional meaning repeat forever.
If you don't believe it add some code that switches an LED on right before your first loop
and switch it of right behind your first loop.
For buttons you have to add code that does debouncing. As your complete project requires not many
cogs you could engage a debounce-button-object from the obex
A better way to debug your code is to use the serial connection to send some debug-data to the PST.EXE
or to use the EZLog-tool from hannoware to monitor variables
http://hannoware.com/ezlog/
to see WHERE your program is executing code you simply add a variable that is set to different values
in the different places of your code
best regards
Stefan
Is it possible for a debounce-button to interrupt the program at any point when pressed to execute its function, then return to where the program was interrupted?
The debounce buttons are not working at the moment but will debug more tomorrow.
Thanks,
Dan
the short answer is no.
the long answer is yes. Youcan code something similar to interrupts but it is not nescessary.
And I would like to explain a fundamental difference between between a propeller-chip and other MCUs. A propeller-chip has 8 cogs that can work completely independant from each other
So there is no need to interrupt the program. The repeat-loop that you have coded will be executed more than a 1000 times per second.
You include everything that should be checked and executed all the time into this repeat-loop.
If you are not familiar with an object you should test it "stand alone" with a demoprogram that is really simpel and gives you easy to understand results.
You packeged everything together with a high density in your code. This means a bug could be at a minimum of 5 places.
Now if you start changing the code how do you know that you changed the right detail?
Not possible! Testing every detail seems to be more work but in the end it is much less work because you will find the bugs quickly.
You should add code always as an attachment. If I would like to test your code - with a picture I'm forced to retype it. And I don't know which "button-object you are using. The standard buton.spin contains code that has only one one parameter.
There is an archive-function in the propeller-tool that will put ALL files needed to compile in one zipfile. This will make sure that
others have exactly the same code as you.
In your code-example you definded S_Width as byte but want to use it with values greater than 255 which is not possible.
There are also some small hardware-things you have to pay attention to. Nothing dificult but important. The buttons should have a pull-up or pull-down-resistor.
Without such a resistor the state of a "free floating" input-pin will jump randomly between high and low. especially when a wire of more than 2cm is connected.
The input-pins have a very high impedance. Then any kind of wire will work as an antenna catching up electromagnetic noise making the state switching between
high and low randomy. The pul-down-resistor will clear this that an unpressed button always means logic low
best regards
Stefan
in the meantime I had fun coding a program for your application myself.
see attached files for this.
It is a somehow a quite advanced version as the two programs do debouncing and catch up
if you press the button for a longer time it does NOT increase/decrease the pulselength
until the button was released for a minimum time.
And it does limit the pulselength to borders defined through constants
This logic is realised with a software-construction called statemachine.
I have inserted comments but if you are completely new to statemachines
it will take some time to understand it.
If you have questions feel free to ask me whatever you want
one program does all with one cog in one big loop
the second program uses a second cog for the buttonpress-checking
I have included some debugcode that uses Hanno Sanders EZLog to watch values of variables
I have attached the software as a third attachment. You load the program into the EEPROM
and then start EZLog.EXE and then connect it to the propeller-COMport.
It will show the values of the variables in realtime so you can watch them change while pressing
the buttons
best regards
Stefan
The S_width was set to 1500 and both button count remained at 1, even when pressed. I have both buttons attached with a wire from the normally closed pins on each button, to their respective pin on the prop, and from the common tab on each button to ground.
The table that holds my ramp has about a 30 degree window in each direction, and the turn table that the servo is attached to was stationary against one wall, so I changed the center position to 1300, then reloaded the program. Eventually figured out that 1375 corresponds closest to being centered for my ramp. Although, still a "1" response at all times from the butttons.
Is the switch from normally closed to normally open enough to toggle the state of the pin?
Attached here is the code you provided, and i modified the center position.
Servo-Button-2cogs - Archive [Date 2010.12.19 Time 19.43].zip
Dan
see attached pictures how a switch with pulldown / pullup-resistors has to be connected
best regards
Stefan
I needed the schematic. Today I bought the 470 ohm resistors I was missing, and also wired the buttons to power which also was lacking. I originally didn't quite understand how to connect the push-buttons.
I need to modify the pulsewidth to make smaller turns, but that is easy now. Now I know how to add other buttons that are involved in my project that operate other functions. That takes care of an integral part of my project, and I can now focus on the rest.
Thanks again for all the help,
Dan