Go Down

Topic: Incremental control of servo motor (Read 486 times) previous topic - next topic

atorpred

Mar 26, 2014, 12:01 pm Last Edit: Mar 26, 2014, 12:03 pm by atorpred Reason: 1
Hello all!

I'm looking for way to control servo motor incrementaly. With that i mean, that if i want to move servo, then i specify just change of angle, instead absolute position.

In my particular case:
When loop starts frst time servo position needs to be, lets say 90 degrees. Then is required change for +30 degrees, so : 90+30= 110, and then position 110 degrees must be send to servo and stored. When loop repeats it takes 110 degrees for current angle, and if next required change is 50 degrees, then calc 110+50=160 and write pos= 160 deg.

I may try eeprom, but as far as i know, that type of memory is for more temporary data...
So, i would really appreceate every opinion!

best regards

AWOL

Quote
so : 90+30= 110

What number base are you working in there?

Why EEPROM?
What's wrong with RAM, or does this system have to hold position across a reset?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

atorpred

Oh, i'm sorry, i meant 90+ 30=120  :smiley-roll-sweat:
No permanent storing is not needed.

Would you be kind and explain me how to write code to store and read from ram in my case?  :D

Thanks!

PaulS

Quote
Would you be kind and explain me how to write code to store and read from ram in my case?

Code: [Select]
int oldPos = 30;
int incPos = 90;
int newPos = oldPos + incPos;

atorpred

Ok, thats how change it. And it works!

Thanks
Code: [Select]

#include <Servo.h>
Servo servo1;

int newPos;
int oldPos = 90;
int incPos;

void setup()
{
 servo1.attach(9);
 Serial.begin(9600);
}

void loop()
{
incPos = Serial.read();
incPos++;
Serial.println(incPos);
newPos = oldPos + incPos;
servo1.write(newPos);
oldPos = newPos;
delay (100);
}


Go Up