Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Servo Control with Netduino


  • Please log in to reply
9 replies to this topic

#1 Igor Kondrasovas

Igor Kondrasovas

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts
  • LocationPorto, Portugal

Posted 20 July 2012 - 12:49 AM

Hello, I'm trying to control a very simple (and cheap) servo (TowerPro sg90) directly from the PWM output port on Netduino, but the results are not satisfatory so far. I suspect the reason of my problems is that this servo must be operated from 3.5V to 8.4V. Although I powered up the servo to 5V, the PWM signal is 3.3V (0.2 V under the nominal specification). The symptom is the servo moves sometimes great, but most of the time there is a small noise and you feel it is trying to move (it gets a little warm to, but this should be OK). I think this is what is called "jitter" I also tried to power the servo with an external power supply, but it did not change anything, so I believe this is not the issue. I would like to hear from you if you experienced something similar, since this type of small servos seems to have the same specification and maybe I am wasting my time with a broken device. Meanwhile, I will try to use a transistor and the 5V supply to switch PWM pulses at a higher voltage with a regular 2222a transistor. (it seems the turn on/off timing is in nanoseconds, so it should not be a problem. I will let you know the results later. Thank you, Igor.

Igor Kondrasovas

www.inovativatec.com


#2 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 20 July 2012 - 05:36 AM

I've just acquired some TowerPro servos but I have yet to try them. If you paste a sample of your control code I would be delighted to include it in my experimentation.Forgive me for telling granny how to suck eggs, but are you adding the 1ms trigger time to the your pulse duration?The first ms of pulse width is there to differentiate signals from noise. This is why a common servo pulse width range is from 1000us to 2000us; it's actually 1-1000us with a 1ms "header". 1500us is the halfway mark aka the neutral position, 1000 is full anticlockwise deflection and 2000 is full clockwise deflection.You are supposed to repeat this pulse every 20ms. These values can vary from brand to brand but the gist of it holds. There's a sample program on the wiki that assumes the above values and winds the rotor lock to lock endlessly. Try that.
One day, all this too shall parse.

#3 Igor Kondrasovas

Igor Kondrasovas

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts
  • LocationPorto, Portugal

Posted 20 July 2012 - 11:53 AM

Hello Arbiter,

Thank you for the reply back.

The code I am running is from the oomlout kit and can be found here: http://nedx.org/CODE04. Although the circuits are very similar to the ones on Netduino wiki, including the program logic, the implementation is a little bit different and the testing result are too.

Lets stick with the Netduino Wiki code you suggested. When I ran it and the servo movements got more consistent, but I still have jitter and the movement the servo performs seems to be at 60 degrees.

The servo specs at DealExtreme site says: "Operating speed (4.8V no load): 0.12sec/60 degrees. "


Could you please test it in your side to see if has the same results?

Thank you,

Igor.

Igor Kondrasovas

www.inovativatec.com


#4 Igor Kondrasovas

Igor Kondrasovas

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts
  • LocationPorto, Portugal

Posted 20 July 2012 - 01:16 PM

Hello Arbiter, Let me share the progress I did. It seems this servo works well with PWM pulse duration from 1000 to 2000 ms. This servo seems to move up to 60 degrees. As I am not used to work with servos, I was scared with the strange noise, but after looking at the Netduino wiki servo experiment video, the noise seems to be very similar. Regarding the code on oomlout, I changed the min an max variables to 1000 and 2000 respectively. This improved the results but is still not the same as the code on the wiki. I suspect this is due to the fact code on oomlout gets the desired position in degrees and calculates the corresponding pulse duration (casted to uint). This will lead to very specific values. I added a breakpoint after the servo.setpulse call and there are some values the servo seems not to like (jitter). Well, the answer to my original question seems to be "YES", I can drive the servo using 3.3 volts. It would be great if you could share your results. Thanks, Igor.

Igor Kondrasovas

www.inovativatec.com


#5 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 21 July 2012 - 12:50 AM

Well, the answer to my original question seems to be "YES", I can drive the servo using 3.3 volts.


Working on it right now.

Most servos require 4.8 to 6V to operate under load. Depending on load which determine back EMF, current draw may be as high as one amp. I suggest you do NOT supply power to the servo from the Netduino, but simply maintain common ground.
One day, all this too shall parse.

#6 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 21 July 2012 - 01:28 AM

OK the results are in.

My unit which is badged HobbyTech but has a Tower Pro QC sticker inside the housing, has the designation YM-2763 with a defined turn path of 90 degrees described by control pulses between 1 and 2ms at 20ms intervals with 1 being the nominal zero position and 2ms indicating nominal full deflection. This is reflected by unit behaviour except that the full deflection is closer to 95 degrees.

Control pulses longer than 2ms overdrive the unit and produced undefined results matching your description of jitter. The reason for this is that the control circuit inside the servo obtains positional telemetry from a linear potentiometer directly coupled to the final driveshaft. Turning this past its defined range produces undefined telemetry (in some cases it goes off the end of the resistive strip and position is reported as 0) which confuses the controller.

That said YMMV and further tests reveal that for my particular unit the reliable range is from 800us to 2150us spanning a physical arc of about 120 degrees before overdrive jitter occurs.

Try this test program and see whether your jitters disappear. It should go smoothly to the zero position and then smoothly to the other end of the defined range and then stop. Another cause of jitter is failure to allow actions to complete before issuing another command. You can demonstrate this by reducing the daly in the sample below to 500ms. If you wanted to wrap it all up in a bozo proof class you would have to time the turn rate for the servo in use and remember the current position so you could figure out the required travel time. Or you could use a servo controller which you can buy from various places, my favourite is the pololu mini 12. These use a Cortex processor and have all the anti jitter logic built in. They aren't cheap but they take things to the next level and are heavily used for animatronics in the film industry.

using System.Threading;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace ServoSample
{
  public class Program
  {
    public static void Main()
    {
      PWM servo = new PWM(Pins.GPIO_PIN_D9);
      servo.SetPulse(20000, 1000);
      Thread.Sleep(1000);
      servo.SetPulse(20000, 2000);
    }
  }
}
I did encounter small amounts of occasional stuttering within the defined ranges. I surmise that imprecisions in thread sleep timing cause some kind of misalignment with the the 20ms cycle used by PWM but that's just a guess.
One day, all this too shall parse.

#7 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 23 July 2012 - 12:03 AM

Igor, I find this site very helpful.
One day, all this too shall parse.

#8 Igor Kondrasovas

Igor Kondrasovas

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts
  • LocationPorto, Portugal

Posted 23 July 2012 - 05:29 PM

Igor, I find this site very helpful.



Hi Arbiter,


Thank you for the website link. It is a nice reference indeed.


It is clear for me that pulses from 1 to 2 ms do not produce 90 degrees. It stays about 60 (maybe a little bit more, since I am not measuring this in a reliable way).

In order to move 90, I changed it from 0.9 to 1.1 ms and visually it seems moving 90 degrees.

I tried some 180 degrees movement, ranging grom 0.5 to 2.5 ms and it did work, but tests were not reliable.

I agree that changing PWM configuration very often may cause this "jittering" since we have no control over the exact moment the new pulse configuration takes place and how it afects the servo control logic. But I am also not sure about that.

Let's see if anyone else has some data to share.

Thank you very much!

Igor.

Igor Kondrasovas

www.inovativatec.com


#9 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 23 July 2012 - 11:01 PM

I wonder if you have inadequate motor power supply. If you have a 6V motorcycle battery handy try that, otherwise you can chain a dozen 1W diodes to drop 13V from a typical car battery to just under 6V (they have a forward drop of 0.6-0.65V). This is pretty crude but it worked well for my initial experiments. Eventually I built a switching power supply but that's a matter of efficiency and reduced heat dissipation rather than effectiveness. When I hook the battery to the motor I also connect battery negative to Netduino ground so that the Netduino and the servo electronics have common ground for interpreting the control pulse. If the problem isn't power then it is not beyond the realms of possibility that your servomotor is defective. All the literature I have seen suggests that Tower equipment conforms to the 1-2ms control pulse model.
One day, all this too shall parse.

#10 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 03 August 2012 - 02:13 AM

Further investigation suggests that the whole PWM timing thing is actually about producing a voltage. A pulse of 1ms every 20ms is a duty cycle of 5%, 2ms is 10%. These correspond to average voltages of 3.3/20 = 0.165V and 3.3/10 = 0.33V respectively. There are comparators and capacitors on the little board inside the servo housing that controls the motor, and no obvious PIC chip, so I strongly suspect it's all analog! There's a laboratory power supply at work with this kind of voltage precision, so I think I'll run a few tests on this.
One day, all this too shall parse.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.