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

Continuous Rotation Servo


  • Please log in to reply
5 replies to this topic

#1 selljamhere

selljamhere

    New Member

  • Members
  • Pip
  • 6 posts

Posted 15 April 2012 - 06:23 AM

Hey all,

I just bought a continuous rotation servo from sparkfun, but I'm having trouble controlling it.

Here's my test code:
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using Servo_API;

namespace ServoTesting
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            PWM servo = new PWM(Pins.GPIO_PIN_D5);

            servo.SetDutyCycle(0);

            servo.SetPulse(20000, 19000);

            Thread.Sleep(1000);

            servo.SetDutyCycle(0);

            Thread.Sleep(1000);
            
            servo.SetPulse(20000, 11000);

            Thread.Sleep(1000);

            servo.SetDutyCycle(0);
        }

    }
}

At this point, I can only get it to rotate clockwise, and I can't figure out how to adjust the rotational velocity or change direction. in the PWM.setPulse(uint period, uint duration) method, I've tried changing both the period and duration values, but the servo's behavior changes somewhat erratically.

According to the servo's datasheet: "When analog signal inputs, servo chooses orientation according to impulse width. When intermediate value of impulse width is above 1.5ms, servo is clockwise rotation, conversely, anti-clockwise." I assume that the impulse is the durration, but in the above code, the servo rotates clockwise both times.

Thanks in advance,

selljamhere

#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 April 2012 - 07:56 AM

Hi selljamhere,

I think your problem is the width of your pulse is 10 times bigger than it should be:
servo.SetPulse(20000, 11000);
The period (the first value) is 20000us = 20ms which is correct, but the width (the second value) should be approximately 1500us = 1.5ms plus or minus a small amount to make the servo rotate.

I found this web page on servos, that has a picture of the basic pulse train:
Posted Image

This next picture then shows changing the pulse width (not period) to change the position of the servo:
Posted Image

In your case, when you change the "position" of the servo by modifying the pulse width, you should get continuous forward and backward rotation. With 1.5ms the servo should be stationary. With smaller or larger widths the servo should turn. The bigger the difference from 1.5ms the faster the rotation.

Hope this helps - Paul

#3 LUDIO

LUDIO

    New Member

  • Members
  • Pip
  • 3 posts

Posted 12 October 2014 - 12:39 PM

Hello guys,

 

First I wanna thank Paul for his explanation. This was what got me to understand how servos work.

 

Second comes my setup. I have a Summer Tree Micro Servo 4.3G continuously rotating servo. I was unable to find any technical documentation on it so far so I started experimenting. I use the following code:

PWM pwm = new PWM(PWMChannels.PWM_PIN_D5, 20000, 1500, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false);
pwm.Start(); 

So far I've found that the effective range of rotation of the servo is around 0-190 degrees and the pulse width is in the range 640-2800. Setting the PWM duration to any value below 500 makes the servo rotate continuously in the counterclockwise direction. I tried values all the way to 0 and it seems that the speed of rotation is unaffected. This however is of no importance in the current project so I can live with it.

 

Now my problem. I can't seem to find a way to make the servo rotate continuously in the clockwise direction. I have tried setting the PWM duration (pulse width) to all the values from 2800 to 20000 in increments of 10 but nothing works. Most of the time the servo only makes a buzzing sound vibrates but does not rotate at all. At some values it starts rotating but rotates fast in a range of around 300 degrees and then the remaining 60 degrees goes slowly. Does anyone has any clue/insight/experience with this sort of a problem. I any additional information is needed I would be glad to provide it.



#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 12 October 2014 - 05:28 PM

Hi Ludio,

 

How are you powering the servo?

 

When you say that it buzzed but did not move, it makes me think that there is not enough power for the servo to turn the motor, or there is not enough voltage for the analogue feedback circuit (in the servo) to work properly.

 

The ground and the PWM pins of the servo should connected to the Netduino, but the power should not be drawn from the Netduino.

Ideally, power the servo by taking a ground and +V to a separate battery pack.

 

Let us know how you get on.

 

Paul



#5 LUDIO

LUDIO

    New Member

  • Members
  • Pip
  • 3 posts

Posted 18 October 2014 - 12:43 PM

Hi Paul,

 

Initially I was using my N+2 to power the servo but after your question and a little help from you  :) in this post I made a battery pack to power the servo. I use 3 AA batteries and the wiring is the same as you have explained in the above mentioned thread. The servo +V (red) goes to the battery pack "+" and the gnd (black) is connected to the battery pack "-" and the Netduino GND. The result unfortunately is exactly the same. The servo rotates continuously in the counterclockwise direction but does not rotate smoothly in the opposite one. If this would be of any help I can make a video of the servo's behavior. 

 

I was thinking of trying a 9V battery as the servo power source but I am not sure if this would not harm the servo or the Netduino.



#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 18 October 2014 - 08:00 PM

Its always nice to here someone has followed my advice, but not as nice when it did not help. Just like being at work ;-)

Don't give up!

 

I think all the RC servos I have come across are designed for 5V, so a 9V battery is probably not a good idea as the extra volts could damage the electronics..

Also if you were thinking of a using a "PP3" 9V battery, be aware that these are intended for circuits that draw small amounts of current - like small radios, smoke alarms, etc. They are not really very good for supplying higher currents to motors.

 

I followed your link to the servo, you said it was a continuous  rotation servo, I assumed you meant something that could drive a buggy wheel, but the link you gave is to a normal micro servo. I don't think it matters, but is it a continuous rotation one, or normal one?

 

Following the link, I am using some very similar servos to control some N-gauge model railway points (aka "turnouts" in American). They were small enough for me to fit into the base board of my layout without having to fit any hardware or wires under the board. The layout fits under a table - so nothing can stick out underneath as it will catch on peoples' legs when they are sitting at the table!

 

I found they worked OK for me as normal left - right servos.

 

We need to work out where the problem is - the Netduino/software or the servo.

 

Have you got any other servos you can use to verify the Netduino and software?

Or, have you got anything else that can drive the micro servo (maybe a radio control receiver, perhaps a friend has something)?

 

See if you can work out where the problem is.

 

It also might help to post your whole program or at least the bit that drives the servo.

Perhaps you could cut it right down to a tiny 10 to 15 line program or "test harness" that just drives the servo and demonstrates the problem.

You may have done something someone else will spot as being a problem. Maybe the servo class is being deleted by mistake after you use it.... There are lots of people on this forum, and when shown the right thing, they will solve the problem.

 

Hope this helps - Paul






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.