View unanswered posts | View active topics It is currently Tue May 03, 2016 8:59 pm






Reply to topic  [ 3 posts ] 
servo help 
Author Message
Rookie

Joined: Fri May 01, 2015 3:26 pm
Posts: 1
Post servo help
Hi

I was wondering if anyone can help me. I am looking for code that will allow me to operate two servos.



I would like to have it operated by a reed switch.

Basic it would go like this.

reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per position

any help welcomed :)

ps I have an UNO


Fri May 01, 2015 3:29 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: servo help
steammad wrote:
reed switch activated, servo 1 would turn 90 degrees & stop, then after the first servo has finished, servo 2 would then turn 90 degrees & stop. When the reed switch is activated again. Servo 2 would rotate back 90 degrees & stop, then servo 1 would rotate back 90 degrees & stop. I would also need the servos to rotate at say 150ms per position


You actually have most of what you need right here: all you need to do is put it in a psuedocode format, then fill in the psuedocode with actual code.

Code:
bool hasTurned90 = 0;

   while(1==1)
   {
      if(reed switch is activated AND hasTurned90 is 0)
      {
         turn servo1 90 degrees
         wait1Msec(amount of time to complete movement);
         turn servo2 90 degrees
         wait1Msec(amount of time to complete movement);
         hasTurned90 = 1;
      }
      else if(reed switch is activated AND hasTurned90 is 0)
      {
         turn servo1 90 degrees (back)
         wait1Msec(amount of time to complete movement);
         turn servo2 90 degrees (back)
         wait1Msec(amount of time to complete movement);
         hasTurned90 = 1;
      }
   }


This is one way to do this code, and you may need to tweak it to fit what you want to do. There is a variable known as a state counter to see if the servos have turned already, and each if/else if statement checks to see if the variable is at a zero value (the servos are currently at a 0 degree position) or 1 (servos are at a 90 degree position).

Each servo will be turned to the correct position, with a wait1MSec command giving each time to reach their target value(s). You will need to determine the amount of time you want to give each servo to ensure that it reaches the target value before the next servo starts moving.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon May 11, 2015 2:21 pm
Profile
Rookie

Joined: Wed Nov 18, 2015 10:34 pm
Posts: 3
Post Re: servo help
you should read this one out http://www.theengineeringprojects.com/2 ... oteus.html


Wed Nov 18, 2015 10:39 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron



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