How to control servo motor

Hi,

I am working on a project at work, I am completely new this stuff and need help trying to create a pivot simulator. I have a Arduino Mega 2560, a servo motor and a bunch of LED's. The servo motor I am using is on this link:

http://core-electronics.com.au/servo-generic-high-torque-full-rotation-standard-size.html

The main objective is I want the servo motor to spin 360 degrees or less and then back to 0 and I want it to do it slowly.

I have been playing around with it and noticed I cant get it to do 360 exactly, the 0 position seems to move.

Any help is much appreciated.

The unit's datasheet mentions nothing to do with the PWM range...

What periods are you sending it ? i.e. *post your code *(remember to use code tags)

That seems to be a continuous rotation servo. With them you cannot get exact position control - only speed and direction

If you need position control and 360deg movement you could try a sail-winch servo. They can usually do 3 rotations with position control.

...R

this is the code i have to end up using, but dont know which bits of code to change to control it the way i want.
code is attached

SIMAv2.ino (15.9 KB)

Robin2: That seems to be a continuous rotation servo. With them you cannot get exact position control - only speed and direction

They call continuous rotation 'full' rotation? No wonder there is so much confusion ... It's 'high torque' as well - which actually means: of the models they provide it the one with the highest torque - which may or not be high enough for your application. And here's me thinking that a servo was a torque (current) controlled motor with feedback from which you can design a controller if you like. They are 'continuous' - but why do I even have to qualify that? Why on earth wouldn't it be? The hobby/model car industry sometime in the 70's (?) decides that a 'servo' is now position controlled, has internal feedback (i.e. is open loop from the users perspective), and it cant spin much past 180deg (if it can even make that). Good times...

BMS_LaserSat: this is the code i have to end up using, but dont know which bits of code to change to control it the way i want. code is attached

Personally, I cant be arsed reading around all that LED stuff Isolate the issue - give us the problem in a nice and succinct simple case. In doing so you might just find the issue yourself - you'll have the 'why the heck does it work now?' moment - compare the code, then all going well you'll have the 'ohhhhh' moment soon after. That's how I do it - I have the main app plugging away and a scratch pad open at the same time to give little bits on non-trivial code a bit of isolation for prototyping.

int led_array [180] [16] =

5760 bytes of RAM to hold 1080 bytes of information? :o

BMS_LaserSat: this is the code i have to end up using, but dont know which bits of code to change to control it the way i want. code is attached

Based on @1:1's comment about irrelevant LEDs I have not looked at the code.

But I seem to have given your stuff more consideration than you gave to my Reply #2 - which you did not even acknowledge even though it seems to be at the heart of your problem.

...R

Simple servo test code. If you send a value like 45 and the servo keeps going around and not stopping, you have a “continuous rotation” servo that probably won’t work for your project.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

zoomkat: Simple servo test code. If you send a value like 45 and the servo keeps going around and not stopping, you have a "continuous rotation" servo that probably won't work for your project.

Well, you could integrate ... but it would be open loop/ effective dead reckoning - not so trustworthy So they call 'continuous' rotation 'servos' 'full' rotation now? As opposed to just 'motor' ?