Pages: [1] 2   Go Down
Author Topic: Servo Control  (Read 4074 times)
0 Members and 1 Guest are viewing this topic.
Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Should this work?
Code:
void camPan(int pos){
 
  servoPan.attach(panPin);
  servoPan.write(pos); 
  servoPan.detach();
}
void camTilt(int pos){
 
  servoTilt.attach(tiltPin);
  servoTilt.write(pos);
  servoTilt.detach();
   
}


Seems to only work if attach is in the setup() function.

I want to let go of the servo to save battery and stop any jitter or anything.

Thanks.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49003
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Should this work?
You have the hardware. Does it?

Quote
I want to let go of the servo to save battery and stop any jitter or anything.
Will the mechanism hold still with the servo turned off?
Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I mean code wise can you attach and detach whenever/wherever in the code?

Because the servos don't work unless i attach in setup() and leave it attached.


The servos stay put when they are off, so yes.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49003
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is nothing in the library that knows whether attach was called in setup(), in loop(), or in some other function. So, the code you posted should work. If it doesn't the problem seems to be elsewhere in the code.
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Servos generally need a continuous stream of pulses to keep them on position - so normally attach() in setup and don't detach().

If you want to power-down the servos you'll need to see if this works (they stay put on power down), and then arrange for the power to be switched somehow (as well as detaching immediately before).  But I'm guessing - someone will know more, but they might want to know which servos you're using.
Logged

[ I won't respond to messages, use the forum please ]

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

They do stay in position when they are off. So you are saying use transistor to turn them off and on?

This is for a pan/tilt camera on a robot.

The servo are from dfrobot.com

http://www.dfrobot.com/index.php?route=product/product&keyword=pan&category_id=0&product_id=146

DF05BB is the servo model.

If I don't attach till I need them, it still doesn't work.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17292
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
They do stay in position when they are off.

In the overall context of servo usage, a servo is designed to be powered continuously and have a continuous ppm control signal applied. If a servo is powered off by removing it's Vcc voltage, or by detaching in software thus removing command pulses, the servo loses all ability to respond to external mechanical forces that may be trying to move it from it's present position. As long as it has power and control signals it can generate maximum torque to overcome mechanical forces that might be trying to move the output wheel. So un-powered or detached it only offers mechanical torque resistance equal to it's internal gear train friction, higher then that and it will move to a un-commanded position.

Easy test, take a unpowered servo and grab and turn it's output wheel, does it turn? Now power the servo up and give it a fixed continuous position command. Now try and turn the output wheel. Different, no?

So in many applications where there is little mechanical force working against the servo then you can unpower when not needing a change of position. I think the average current draw of a servo a rest with no external mechanical forces is around 7ma, but that of course varies on size and design of your specific servo.

That make sense?

Lefty
« Last Edit: January 27, 2011, 09:33:41 pm by retrolefty » Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes it does but most of the time my robot will be idle, it won't matter where the camera is pointing when the camera is off. Either way shouldn't the software be able to attach as needed? I saw a example somewhere but doesn't work for me. There isn't much more to the code. I enter a command on the serial and it moves it that position.

I am using Arduino IDE 21.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17292
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Either way shouldn't the software be able to attach as needed? I saw a example somewhere but doesn't work for me. There isn't much more to the code.


Of course it would better if you posted your full sketch, my bet is that your is not allowing the servo time to reach it's new position before it performs the detach command. Servos don't move as fast as code does.  smiley

As an experiment, try adding a delay(2000) command just before you detach command and see if that doesn't tell you whats going on.
Lefty
Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tired 1000 delay after the attach, I should do that after the command to, didn't try that.

I will try thanks.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks! It was the detach that needed more time, doh! Makes sense. I didn't do it because I had the attach and set to default position in setup and that worked. I didn't think of the delay needs to be after pos is set.

Thanks, we all live and learn.

Hopefully someone else can benefit from this thread.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I thinking it might use less power if I actually turn off the power. I will have to do some current testing.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17292
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks! It was the detach that needed more time, doh!

Your welcome.

It's really not the detach command that needs the delay, but rather the servoPan.write(pos); command needs delay after starting, to allow the servo to actually reach the new postion commanded.


Lefty

Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that was what I meant, I needed more time before I detached.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Los Angeles, California
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am no expert on servo's, being a relative newbie, however my current project uses a fine little gear reduced motor sold by Pololu. My project is a marine Autopilot, moving the helm wheel by means of a gear reduced motor. The one I am using to test my program is a 131:1 reduction, and has a 64ppr encoder mounted on the motor shaft, with all the leads for the encoder brought out in a color coded bundle. In my testing, using several sketches copied from this forum, you can get the encoder count output, plus direction. With some clever coding, you could have a very precise, controllable axis motor position, and go back to it. The output shaft is 6mm, which is slightly less than 1/4", with a machined flat. They sell motor hubs, that mount to the shaft, as well as the motor mounts. You absolutely cannot turn the motor shaft by hand. Also, using their 18v25cs motor driver H-bridge, you can drive the motor with PWM, vary the speed, and brake to a hard stop, or freewheel stop.

Reading Richard's comments about servo's, and their flaky, jerky movement prompted me to add my two cents. I agree, a pan/tilt camera mechanism needs to be smooth, and solid as a starting point in the design. There will be enough problems solving all the unknowns, without fighting the fundamental mechanics of the system.

John
 
Logged

Pages: [1] 2   Go Up
Jump to: