Stopping signal output to servo when input unchanging.

Hi there, I am wanting to use a variant of the knob servo library function except I want to code the arduino 2009 to stop sending signal to the servo when 'PotPin" is unchanging. Basically I'm over-volting my servo to get rapid response, 10V, so I don't want to burn it up holding position. Nominal voltage is 6V so sustaining 10V for long periods will decrease the servo's life. It only moves infrequently but when it does I need it to move fast with a lot of torque. I'm not worried about it holding position, only responding to changes. I feel like it shouldn't be too hard. Just need someone to point me in the right direction.

Sincerely, Rich

Use the "detach()" method.

Like Groove said, Detach will do what you ask - Stop the signal. It will still have full input voltage going to the servo through the power leads. Not sure if this is an issue.

What servo are you using? Will it handle 10v? Many servos die pretty much instantly on that voltage. Is there a reason you do not want to use a faster, stronger servo?

using a Hitec HS 985MG

Pretty much one of the strongest there is in the standard size. It still needs a little extra voltage though to get it as fast as I want it to go. I talked to Hitec and they said it would greatly reduce the life of the servo but if I turned it off while holding a position it probably would not be detrimental so long as it is not used continuously at that voltage. Having the voltage across the servo doesn't matter though I think. So long as it has no control it is not doing any work and thus not generating any heat. Thanks for the input. So I'll basically code that if potpin = the last void loop then detach()?

Thanks for the input guys.

Rich

So I'll basically code that if potpin = the last void loop then detach()?

Try that question again, please. "void" is a return type. We all know that loop()'s return type is void. There is no reason to tell us that.

I would presume, not seeing any code, that potpin is the pin that the potentiometer is attached to. I'm pretty sure that that is not going to change.

Sorry I’m a total noob here.

So void loop… whatever that is… reads the voltage from the pot on Analog 0 every couple milliseconds. If the voltage remains constant I’d like for the program to detach the digital output to the servo. Does that make more sense. Just need to figure out the code which can discern if the voltage or mapped digital value from the pot is constant or changing. Am I on the right track there?

Rich

So void loop... whatever that is... reads the voltage from the pot on Analog 0 every couple milliseconds.

So, the loop function...

Keep track of the value read and the last value read.

int thisVal;
int lastVal = -1;

void loop()
{
   thisVal = analogRead(potpin);
   if(thisVal != lastVal)
   {
      // attach the servo
      // write thisVal
      // detach the servo
   }
   lastVal = thisVal;
}

You may want to allow a little change in the values before writing the new value, as potentiometers can be a little jittery.

if(dabs(thisVal - lastVal) > 2)

I talked to Hitec and they said it would greatly reduce the life of the servo but if I turned it off while holding a position it probably would not be detrimental so long as it is not used continuously at that voltage. Having the voltage across the servo doesn't matter though I think. So long as it has no control it is not doing any work and thus not generating any heat.

That's not my take on it at all. As long as you have +10 vdc applied to the servo's power pin you are stressing the heck out of it and I would never recommend running a servo at above it's rated voltage range, most spec 4.8vdc to 6vdc. The fact that the servo is detached with no control signal just means the motor won't be drawing current, but that has nothing to do with voltage stress on all the semiconductors used inside the servo. Running components above their maximum recommended specification is never a good idea. If you need a stronger faster servo then buy or build one. At least that's my advice and worth what you are paying for it. ;)

Lefty

Instead of debating the subject with too many unknowns, just give it a try to see how it will actually work. Servos are not that expensive if things don't work out.

retrolefty: That's not my take on it at all. As long as you have +10 vdc applied to the servo's power pin you are stressing the heck out of it and I would never recommend running a servo at above it's rated voltage range, most spec 4.8vdc to 6vdc. The fact that the servo is detached with no control signal just means the motor won't be drawing current, but that has nothing to do with voltage stress on all the semiconductors used inside the servo. Running components above their maximum recommended specification is never a good idea. Lefty

Thanks for the POV. I think you have a good point. Although usually if a component cannot withstand a certain voltage it will let you know pretty quick. Like you said earlier some servos would just die immediately if given 10V. Of course a constant slight overload could cause excess heat build up and eventual failure. Perhaps I could add a lead to provide a nice regulated 6V to the position control PCB while still being able to over-volt the motor periodically. It's just so fast with 10V ]:D. I'm also working on reducing the load, but most it comes from a 2.5:1 gear ratio with the big gear on the Servo shaft. Thanks for the code Paul. I will try my hand with it over the weekend. I have not coded anything, except HTML, in about a decade so it should be interesting. I sure do appreciate the help.

Thanks Guys, Rich

Of course a constant slight overload

A 66% overload is "slight"?

zoomkat:
Instead of debating the subject with too many unknowns, just give it a try to see how it will actually work. Servos are not that expensive if things don’t work out.

That is a 60 servo he is playing with there ) I certainly would have second thoughts of applying 10vdc to a servo designed to work off 4 series AA cells. http://www.rcsuperstore.com/ProductDetails.asp?ProductCode=HRC32985S&click=2

There is an internal servo gearing mod that can be done to increase the speed of the servo movement, but torque will suffer. Not sure how good the servo position control will be due to overshoot on a servo not hacked for continous rotation.

http://www.youtube.com/watch?v=wCx52hT4pu8

@ PaulS

So the code you gave basically works except your def of LastVal as -1; does not reference the previous value. The servo shuts off when reading is 1 from the pot since potval-lastval < 2 here’s the code I’m rolling with. I need a way to store the last value in the void loop… except it’s a void loop. So voids stuff
Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int PotVal; // variable to read the value from the analog pin
int OutVal;
int LastVal = -1;
int Diff;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}

void loop()
{
PotVal = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Diff = (PotVal-LastVal);
OutVal = map(PotVal, 0, 1023, 0, 119); // scale it to use it with the servo (value between 0 and 180)
// print the results to the serial monitor:
Serial.print(“sensor = " );
Serial.print(PotVal);
Serial.print(”\t output = ");
Serial.println(OutVal);
if(Diff > 2)
{
myservo.attach(9);
myservo.write(OutVal); // sets the servo position according to the scaled value
}
if(Diff <= 2)
{
myservo.detach();
}
delay(15); // waits for the servo to get there
}

So the code you gave basically works except your def of LastVal as -1; does not reference the previous value.

Of course not. -1 is not a possible value to read from an analog pin, so the first reading is guaranteed to not equal the last value. The first value read should position the servo to the initial condition.

I’m rolling with. I need a way to store the last value in the void loop… except it’s a void loop. So voids stuff

void is a return type. Suppose, instead, that loop returned an int. Reread your sentence, substituting int everywhere where there is currently void. See why that sentence grates on the ears of anyone that understands variable types, functions, and return values?

There is a button up top (#) that puts code in a nice box, with scroll bars. By now, you should know how to post code properly.

OutVal = map(PotVal, 0, 1023, 0, 119);     // scale it to use it with the servo (value between 0 and 180)

119 does not equal 180. Not on this planet, anyway.

  if(Diff > 2)
   {
 myservo.attach(9);
 myservo.write(OutVal);    // sets the servo position according to the scaled value
   }
   if(Diff <= 2)
   {
 myservo.detach();
   }

Suppose LastVal is less than PotVal. Diff will be less than 2, so you detach the servo. Oops.

Good point there. I'll have to enter an absolute value statement. As far as the other stuff goes I guess it is over my head. I don't know how to get the previous OutVal or PotVal to return to the current loop. There must be an easy way to store it, recall it and overwrite it with the new one. If you already answered this in your last post... I didn't get it. Also the 119 degrees was a tweak I made for my specific application. I don't need the full 180. Thanks for pointing out the code post button. I looked around for it before but didn't see one that was obvious.

Thanks for your help.

Sincerely, Rich

Once you read the current PotVal, store it in LastVal, somewhere in loop(). The, next time through loop, read PotVal, and compare it to LastVal. If they are the same, detach the servo. Otherwise, attach the servo, and move to PotVal (or to whatever you map it to).

I set LastVal to -1 initially, so that the very first reading from the sensor (PotVal), after a reset, would not possibly equal LastVal, and an attach and move would be required.

I kind of asked this question in a related posting recently. What is the advantage of detaching and later reattaching a servo in a running sketch? If a servo is at the commanded position it should not be bothered with the command continuously being updated, that is how servos are designed to work.

I've never seem a servo application out in the real world that needed to have it's control signal turned off but power still applied to it. I could possible see some minimum power application where one would remove DC power from a servo, but detaching is not doing that?

Lefty

HooRay!

That worked... I actually had it right (conceptually) before I posted the last post but it wasn't working because I defined LastVal as the mapped 0-180 OutVal but Diff was POTVal-OutVal. Where PotVal was 0-1023. Figured it out when I printed diff to serial and saw the weird numbers. Now just setting the delays correctly. By just having the delay of 15 the servo can only move a little before it is detached. I want it to be responsive but able to make its full range of motion before detaching. I'm putting some if statement delays in front of the detach command. ie if Diff is > 5 (large motion) delay(200) before detach. Hope that will work. If you have a better idea let me know.

Thanks Paul

retrolefty: I kind of asked this question in a related posting recently. What is the advantage of detaching and later reattaching a servo in a running sketch? If a servo is at the commanded position it should not be bothered with the command continuously being updated, that is how servos are designed to work.

I've never seem a servo application out in the real world that needed to have it's control signal turned off but power still applied to it. I could possible see some minimum power application where one would remove DC power from a servo, but detaching is not doing that?

Lefty

I have 3 advantages I think I will like.

1) don't know why but my servo is constantly clicking. Sounds like 60Hz. By all account it shouldn't really be doing that but that stops when detached. 2) I think this will be an advantage for my unique case that between sending command changes I will be able to manipulate the servo. Impossible while a servo is holding position. 3) Another annoying thing this stops is servo jitter. I don't know if that is causes by lame voltage but it happens and it is not because of the read Potentiometer. Those values are solid in serial reader.

One more is my idea to perhaps feed the motor a little more voltage than spec'd. If the motor had to hold position constantly at a higher voltage it might cause excess heat buildup. By shutting it off it allows me to 'push the envelope'. So to speak.