View unanswered posts | View active topics It is currently Thu Dec 18, 2014 5:03 pm






Reply to topic  [ 2 posts ] 
servo speed 
Author Message
Rookie

Joined: Sun Feb 06, 2011 11:22 pm
Posts: 3
Post servo speed
Can the speed of a servo motor be controlled through robot c programming?


Tue Mar 01, 2011 12:11 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: servo speed
I don't know if you can directly control the change rate of the servo, but here is a simple piece of code you can write to control the speed of the servo:
Code:
void moveServo(tMotor servoName, int  endPos, int timeToTake){
  int currPos = motor[servoName];
  int period = timeToTake / abs(currPos - endPos);//time to wait between each movement
  if(endPos > currPos){
    for(int i = currPos; i < endPos; i++){
      motor[servoName] = i;
      wait1Msec(period);
    }
  }
  else if(currPos > endPos){
    for(int i = currPos; i > endPos; i--){
      motor[servoName] = i;
      wait1Msec(period);
    }
  }
}

I'm not sure if I have made an error in the syntax as I do not have ROBOTC in front of me right now, but that is the general idea.

_________________
sudo rm -rf /


Tue Mar 01, 2011 5:27 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.