Shop OBEX P1 Docs P2 Docs Learn Events
pulse feedback for pwm servo positioning — Parallax Forums

pulse feedback for pwm servo positioning

Hi everyone, I'm a experienced electronic tech making a driver for the parrallax standard servo but need to incorporate a pulse feedback to control
The servo position and increase stability. Anyone else experimenting in this type of feedback?

Comments

  • I don't understand your question. Hobby servos generally don't provide any sort of feedback. It's possible to hack a servo and monitor the pot with an ADC and there are a few other sorts of hacks to attempt to read the position of a servo but these hacks aren't trivial.
  • There are ways to do this without needing to hack or modify a servo and that will work with almost any micro controller and almost any hobby servo. You simply monitor the current draw of the servo motor when applying the "command pulse". If the motor is in error, then it will be energized and draw more current. If the micro doing the detection is in control of the command pulse then you can also determine the direction of the error. For example, if the error happens after your command pulse stops, then you know that the error is in one direction. If an error is produced before your command pulse stops, then you know the error is in the other direction.
  • Thanks for your replies Duane and Beau, To give more info on my project the servo position controls motor speed of a device which produces its own pulse tach. I would like to monitor this and give a feedback signal to the basic stamp 2.
    By doing this the rpm of the device is more accurate. The feedback must be inputed to the bs2 and made into a correction for the pwm drive out to the standard servo. I'm getting back into the program methods of microprocessors
    but need more study to get the full extent of their flexibility of these processors. They really are neat. Boone
  • Okay, so the servo is controlling a motor and you want to adjust the servo's position based on feedback from the motor's speed?

    Sounds like you want some sort of P.I.D. loop.

    https://en.wikipedia.org/wiki/PID_controller

    Often proportional control is enough to get motors to behave nicely.

    You'd want to adjust the servo proportional to the difference between your target speed and your currently measured speed.
  • Duane, I think your right on PID. how does bs2 receive and work with the correction from the PID? I'm not sure how to program it. Any idea? Thanks, boone
  • How are you monitoring the speed?

    Here's some pseudo code.
    DO
      Determine currentSpeed
      error = targetSpeed - currentSpeed
      servoPosition = previousServoPosition + (error * PROPORTIONAL_CONSTANT)
      Set servo to servoPosition
      previousServoPosition = servoPosition
      pause long enough to make complete loop 20ms long
    LOOP
    

    The loop should probably run at 50Hz since this is how often you need to pulse the servo.

    The value of PROPORTIONAL_CONSTANT is determined experimentally. If the speed of the motor oscillates, then this constant is likely too large.

    I don't program the BS2 enough to recall all the syntax for pulsing servos and pausing execution.
  • Duane, This will help a lot. I was just checking the learn heading on the bs2 and found a pid with bs2 tutorial. Didn't know where to find this info at first. I'll study and let you know how things are shaping up. Thank you again for your help. boone
  • Oh yeah, I have a pulse generator on the output giving me accurate feedback.
  • I think your code may work. I am using rctime to determine servo position with a variable resistor and have the pulse from a tack pulse generator on motor for feedback. I guess I would have to relate the tack pulse to something that works with the microsecond pulse drive value I am using for servo position to produce the error figure. Have any suggestions.
  • How long does it take you to measure the tack pulse? What sort of numbers do you expect?

    What's the lowest value you expect what's the highest value you expect?

    Does the motor speed up when the servo is sent longer pulses? Or do the shorter pulse lengths cause the motor to speed up?

    It would be good to know what servo pulses you expect to send (shortest pulse and longest pulse). It would be good to know what values you expect to read when measuring the tack pulses at these extremes.
  • Very good. The tack pulses are generated as soon as motion is detected on output shaft of motor. I spent sometime last night getting a feel for these numbers. I would say the pulse durations to the servo 700 - 1100 sweep giving me a
    Motor speed between 700 - 4000 rpm. The tach puts out 6 pulses per rev giving 4200 - 24000 rpm that's 70 - 400 Hz
    Feedback Signals. So at a position duration of 700 feedback should be 70 Hz up to a duration of 1100 a feedback of 400 Hz should be no error signals. Let me know your thoughts on this. Thank you so much for you attention.
  • Are the pulses used to monitor speed consistent enough for you to just measure a single pulse in order to determine speed or do you need to read several pulses and average them.

    I think a program which reads the pulses and displays the speed would be a useful starting point.
  • I would probably want to average the feedback pulses to give more precise values. You might be right I could try to write a program converting the feedback pulses to microsecond units and then let this figure be compared to my sweep duration at that moment. During set point change this could help smooth the transfer. I would assign input to a pin for pulse in and come up with some type of conversion formula to give it a microsecond value so I could compare feedback to the set point. Being new to writing code I certainly could use help. Let me know your thoughts while I try to find something similar in my bs2 material to guide me future. This stuff is really fun when I get some understanding in the basics and make something work. I have been into electronics for quiet awhile but coding is a great test for my imagination. Thanks again
  • Don't worry about converting the feedback pulse to microseconds yet. Just get a number so you can see if you need to average multiple values to get a good reading.

    I don't use Basic Stamps much but I think the PULSIN command may be what you want to use. I think there are several different ways PULSIN can be used so check the manual to see how it should be used in this case.

    If you post the code you write using code tags it will be a lot easier for us to read.
    code between tags
    

    Click on "Quote below this text to see how I entered the code tags.

    I think some code to display the value of the pulse read from tachometer would be a good start. As I said, don't worry about converting the raw pulse value since you'll need to convert this to the appropriate servo pulse later and you might as well make the conversion in as few of steps as possible in order to minimize rounding errors.

    Maybe someone following along will recommend some BS2 code for reading a tach? If no one has a better suggestion, I'd suggest starting with the PULSIN command.
  • Great Duane, I'll be working tomorrow but will study and write using pulsin and see how my numbers look. Have a good night.
  • ercoerco Posts: 20,250
    Seems like the external feedback pot on your servo is redundant. You should know the last servo position from whatever pulses you just sent. Or do you expect the servo response to lag a great deal? This sounds pretty much like cruise control in a car.
  • Erco, As far as I assume the internal feedback in servo is verifying the correct duration position of the servo regardless of actual motor speed which gives a great starting point to calculate the actual error in selected speed. Been studying PID feedback to loop the control signal from the tach to give stability to the circuit. Been working on the shift side of things using micro switches to stop and start the shift servo in the right places. Got that working using a MOSFET to drive the servo. Experimented on the pulsin command Duane directed me to which had a great sample in the Basic
    Syntax manual and that has helped a lot, unfortunately my signal generator had some problems so I decided to move to this shifter program until I receive my replacement gen.
  • ercoerco Posts: 20,250
    Have plenty of kill switches and override in your autonomous car project!
  • Courtney Jacobs just linked to the PID tutorial linked below in another thread.

    learn.parallax.com/pid-control

    I bet there's lots of great info in it.
  • I found everything I needed for a PID project in the link Duane just shared. Highly recommended.
  • Hey I'm back. Found a great way to program the shift part of my project, worked great. Got my new pulse gen in and also received my optocoupliers in. Right now I'm setting up my resistive network to handle the input voltages from my tach feedback pulse and use pulsin to apply this to the feedback. I have an understanding of the calculus from my college days so PID is not to hard for me to digest. Where my attention is most needed is in the syntax and programing. As I study these little microprocessors and their programs I can see how flexible they can be. And yes ergo I got a great way for shutdown which is not electrically dependent. I have a machine shop which I use a lot making little trinkets for my engineering projects. I'll post something soon about my lab simulator and program for speed control with PID and hopefully it will function and need only fine tuning. Thanks for everyone's interest and I'll look into that other thread Duane and Kieth has pointed me to.
  • Been busy studying. By experimenting I found that at low motor speed the duration on my bs2 was around 1000 and rpm is 700 now as I move speed up my top end duration numbers are around 600 and rpm is 4000. Pulsin will process the signal from the tach after a optocouplier and at the same time converts it to a usec figure. This is the length of one pulse which is long enough to use for a feedback figure. At low rpm its 1800 us and at high end its 300. How to use these figures in the bs2 rctime values for the feedback error figure is where I'm stumped. Any suggestions are deeply appreciated. Been really enjoying all the great tutorials in the stamp websites. Will be around, boone
  • Well been doing my studying with how to take my tach input and count it to frequency. Now to get that figure as an error and compare it to the duration output for my servo set point is where I could use some advice. Anyone?
  • Well thanks for the interest. Made great strides and got my functioning demo working well. I'm looking into increasing the intergral component even though its working so well as is. My function gen is a great help. These little micros are great. Still having probs with my propscope. Great tool really will miss it. Len












  • Well I see I must be very interesting to you all, if your following I'm got the P of PID going well. Been fun would be great
    To add the ID this. Unfortunately my bs2 went down. Started acting funning thought it was a cable switched didn't help, switched batteries, still no good, even took my other computer and downloaded bs2 software but no good. I believe it's the USB input chip. We'll see how things go with Parallax. Boone
  • ercoerco Posts: 20,250
    Your USB/serial adapter went bad? Very unusual. And Stamps don't usually just die on their own. Was there one big event (sparks and smoke) that you recall? :)
Sign In or Register to comment.