Is there a way to control servo position and speed at the same time? ex: you want to build a biped but you don't want the movements to be jerky.
I've played with this a bit with multiple servo operated joints.
I found the best way to get smooth movement is to use nextmove assigned times.
This is just an example of what I'm talking about. (not actual code)
int MoveDelay; ' the number of milliseconds between each step, smaller steps = faster movement
int Step; ' the amount the servo moves with each loop, keep this number small
int TargetPosition; ' this controls where the joint is moving to, you just change the targetposition to make it move
if millis() >= NextMove and JointPosition <> TargetPosition then MoveJoint;
Int NewPosition = CurrentPosition + Step;
rem the next two lines make sure you don't overshoot the target
If CurrentPosition < TargetPosition and NewPosition > TargetPosition then NewPosition = TargetPosition;
if CurrentPosition > TargetPosition and NewPosition < TargetPosition then NewPosition = TargetPosition;
CurrentPosition = NewPosition;
NextMove = millis() + MoveDelay;
There are servos available that can have their speed programmed into them. That is what they usually use with humanoid robots and it makes them more expensive.
In my code I do something similar to what Patrick suggest except I use a polling method. Instead of just using a delay and having nothing else being done I write my code so the servo is incremented then continue through my program loop checking sensors etc.
You need to use more variables and sometimes arrays as you need to keep track of the start position, stop position, speed (change your increment value), direction.
some command such as pulsin have a timeout variable. If you are using pulsin to read an IR signal from a TV remote then you can set it's timeout value to work like a delay function except that it can also look for incomming commands.
i have tried what you said and seems i can get it.. here is the code and would like to remove that delay function please help
#include <Servo.h> //include Servo library
const int irPin = A1; //Sharp infrared sensor pin
const int dangerThresh = 276; //threshold for obstacles
const int ledPinstop = 3; // the pin that the LED is attached to
const int ledPingo = 12; // the pin that the LED is attached to
int rightDistance; //distance away from obstacles on the right
int centerDistance; //distance away from obstacles in the center
int leftDistance; //distance away from obstacles on the left
int averaging; // Stores average of distance
int val = 0;
int dist = 0;
Servo servoleft; //Left wheel
Servo servoright; //Right wheel
myservo.attach(9); // head to pin D9
myservo.write(93); // set IR sensor pan to center
servoleft.attach(10); // Left servo to pin D10
servoright.attach(11); // Right servo to pin D11
servoright.write(180); //move forward
rightDistance = analogRead(irPin); //scan to the left
myservo.write(93); //return to center
centerDistance = analogRead(irPin); //scan center
leftDistance = analogRead(irPin); //scan to the right
int get_avg(int IRpin) //Gets 3 readings from the sensors and averages them to get rid of spikes
int total = 0;
for(int x = 0; x <=3; x++)
int val = analogRead(irPin); //read IR sensor
if (val<dangerThresh) //if path is clear
else //if path is blocked
if (leftDistance<rightDistance && leftDistance<centerDistance) //if left is less obstructed
servoright.write(180); //turn right
else if (rightDistance<leftDistance && rightDistance<centerDistance) //if right is less obstructed
servoright.write(0); //turn left
else //if they are equally obstructed
servoright.write(0); //move back
servoright.write(0); //turn left
i'm new in arduino,so can u teach me about servo control direction and speed ??just one simple example....because i no so good in english.....thanks a lot...
To ask, 'please teach me' is very challenging. Everyone has their own life to live and limited time to spend on the things they want and have to do. Many people on this site have contributed knowledge. There are also many sources on the Internet to learn about Arduino.
Take a look at some of the links under Programming on the LMR Primer page. The examples and knowledge you are looking for are there. You just need to use them. After you have studied and tried on your own, come back with specific questions or help to clarify something you didn't understand.
Post your questions as their own forum topic when you are ready.
Look through the LetsMakeRobots pages. There are hundreds or maybe thousands of examples.
There are also a couple Malaysians on here who may be able to help more, since they speak your native language.
Aaronsuper1 is a 13-year-old in Puchong. He may be able to help some, at least with the language problem.
Anyway, there are a LOT of examples here at letsmakerobots.com with programming, designing, and building all sorts of different robots. To search for things, Click on "Search page" above the Shout Box ===>>>
Increment or decrement the servo value with a small delay between each iteration.
So instead of going from 0 to 90
you go from 0 to 1 to 2.... 90 with small delays in between each. Use a for loop.