Pages: [1]   Go Down
Author Topic: Incremental control of servo motor  (Read 420 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 26, 2014, 06:03:29 am by atorpred » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26314
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  smiley-grin

Thanks!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Would you be kind and explain me how to write code to store and read from ram in my case?
Code:
int oldPos = 30;
int incPos = 90;
int newPos = oldPos + incPos;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, thats how change it. And it works!

Thanks
Code:
#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);
}

Logged

Pages: [1]   Go Up
Jump to: