Arduino Forum

Topics => Robotics => Topic started by: evolion on Dec 26, 2012, 11:04 am

Title: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 26, 2012, 11:04 am
Hello Everyone,

I have an UNO R3 with an Ardumoto shield (just got a seeed MotorShield v1.2 but haven't hooked it up yet) and am working on a prototype for an autonomous hexapod.  I'm trying to get at least two servos (eventually 5-8) to operate at the same time, executing different parameters for one 'smooth' leg movement.  In other words, pedal movement that traces a path more like an arch than a jerky rectangle.  I'm fairly new to programming and totally new to arduino and micro-controllers.  So far none of the code I've written will control two servos simultaneously, I'm thinking I probably need to incorporate an IC into the circuit and coding to accomplish this, but so far I haven't found much info on this particular problem.  
Any input would be great!
**********************************************************************************
1/5/13                                                     I need help!

      Here's what I'm trying to do:
1) Store strings to PROGMEM
2) Retrieve strings from PROGMEM using Serial()
3) Write strings to multiple servos in sequence/s

     Purpose:
Mainly to have simultaneous operation of multiple servos and sensors, the other would be to conserve memory for functions.

I've made too many changes, additions, omissions to the code to remember everything I've tried.  I can't really go much further with my project without solving this problem.
 The code I'm working on is post #27.

                            Any suggestions or additional info will be greatly appreciated!
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Dec 26, 2012, 12:05 pm
Quote
So far none of the code I've written will control two servos simultaneously
What code?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Dec 26, 2012, 04:22 pm
A place to start would be to look at hex projects others are working on like below.

http://www.lynxmotion.net/viewtopic.php?f=8&t=8409
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 27, 2012, 07:10 am
                   Here is some of the code I've used so far:

Code: [Select]
//I have rewritten the 'sweep' example from the 'getting started' section of the site.
//My arduino is mounted on a robot kit and I am using the 'bumper' sensors (whiskers) as switches
//to start/stop the servo functions mounted on another stationary platform.

#include <Wire.h>
#include <Servo.h>

Servo myservo;   //create servo object to control a servo
int pos = 0;              
Servo myservo2;                
int pos2 = 0;     //variable to store the servo position

const int bumperPinR = 2;   // the number of the bumper pin
const int bumperPinL = 4;   // the number of the bumper pin

int bumperStateR = 0;       // variable for reading the bumper status
int bumperStateL = 0;       // variable for reading the bumper status

void setup()
{
 myservo.attach(9);   //attaches the servo on pin 9 to the servo object
 myservo2.attach(8);

 pinMode(bumperPinR, INPUT);  //sets the bumper pins as an inputs
 pinMode(bumperPinL, INPUT);

Wire.begin();        //initializes/activates voltage sensing from bumper?
}

void loop()
{
 bumperStateR = digitalRead(bumperPinR);  //read state of the bumper values
 bumperStateL = digitalRead(bumperPinL);

while (bumperStateR == LOW)        // begin a loop within 'void loop'
{
  for(pos = 31; pos < 168; pos += 3)  // goes from 31 degrees to 168 degrees
  {                                   // in steps of 3 degrees (faster)
    myservo.write(pos);               // tell servo to go to position in variable 'pos'
    delay(15);                        // waits 15ms for the servo to reach the position
  }
  for(pos2 = 6; pos2 < 171; pos2 += 3)  // goes from 6 degrees to 171 degrees
  {                                     // in steps of 3 degrees (faster)
    myservo2.write(pos2);          
    delay(15);                      
  }    
  for(pos = 167; pos >= 32; pos -= 3)   // goes from 167 degrees to 32 degrees (keeping servo from
  {                                     // ends of range seems to fix its jerking)
    myservo.write(pos);              
    delay(15);                        
  }
  for(pos2 = 170; pos2 >= 5; pos2 -= 3)  // goes from 170 degrees to 5 degrees
  {                                  
    myservo2.write(pos2);            
    delay(15);                        
  }  
//   if (bumperStateL == LOW)        // condition that breaks out of loop
//   { pos = 3 || 177;                      
//      break;
//   }
}
 if (bumperStateL == LOW)   //this doesn't seem to do anything, supposed to stop the
 {                          //the code above from running - this part can be ignored for now
   int pos = 90;
   {
     myservo.write(pos);              
      delay(15);
   }
   int pos2 = 90;
   {
     myservo2.write(pos2);              
      delay(15);
   }    
 }
}


~Thank you for the link, I'll check it out.

I guess my specific project here may be beside the point, in that, it probably doesn't matter what the functions are, but just how to make any two (or more) of them run at the same time, not one after the other. ~2 servos moving at the same time using completely different parameters.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: JimboZA on Dec 27, 2012, 07:31 am
To make the code look like code, just highlight it and hit the # button above the smilies
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Dec 27, 2012, 08:36 am
OP, have you looked at the blink without delay example sketch?
You should.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 27, 2012, 10:17 am
Thank you for the tip,

Upon examining 'blink wo delay', it appears that every time the defined interval is reached and the led blinks, the previousmillis is redefined to be currentmillis so that the iteration gets continually restarted, thus creating a kind of loop that apparently runs in the background.  (if that makes any sense)

So I gather that any function that can be set up without a delay won't interrupt other functions.  I'll have to think about this a bit.

I found a routine here  <http://scolton.blogspot.com/2010/07/arduino-interrupt-driven-servo-routine.html>  that uses PWM, resets one of the board's timers, and uses interrupts to control the servos.  The concept seems to make sense but I don't really understand the code so I'll have to experiment to see what it does.

I also want the servos to operate in sync with each other so as to produce what appears a 'single' movement of the leg.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Dec 27, 2012, 10:19 am
Quote
I found a routine here  <http://scolton.blogspot.com/2010/07/arduino-interrupt-driven-servo-routine.html>  that uses PWM, resets one of the board's timers, and uses interrupts to control the servos

That's exactly what the Servo library does.
No need to reinvent that particular wheel.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 27, 2012, 11:25 am
So, is it that i need to map the variable values (degrees) of one servo to the other so that the position of one is dependent on the position of the other ~one would basically 'follow' the other using a conversion between ranges?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: rgallant on Dec 27, 2012, 06:21 pm
What are you using to control the servo's ?  If you are running a full 18 or more you may want to look at a dedicated Servo controller which will give you much more flexibility in managing your servos.  The Lynxmotion one allows for group moves others have servo speed control etc.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: retrolefty on Dec 27, 2012, 06:33 pm
Quote
I also want the servos to operate in sync with each other so as to produce what appears a 'single' movement of the leg.


I think you fail to understand that any 'coordination' between the servos motion will always strictly be a task your software has to perform. Servos move fairly slow relative to program execution and any 'simultaneous movement' will be the result of your the 'step size' you issue each servo to move and how quick you issue the next step size movement to each servo. The smaller your servo step size commands are the more smooth the apparent 'coordinated movement' will be. Any coordination between your servos movement is a software burden on you, there is no hardware assistance you can use.

Lefty
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Dec 27, 2012, 06:54 pm
Quote
I guess my specific project here may be beside the point, in that, it probably doesn't matter what the functions are, but just how to make any two (or more) of them run at the same time, not one after the other. ~2 servos moving at the same time using completely different parameters.


Code: [Select]

//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added

String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    } 
    else {     
      readString += c; //makes the string readString
    }
  }
}
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 28, 2012, 07:15 am
rgallant:
I'm using an UNO r3 with an ardumoto shield (just using 2 pinouts for 2 servos on a homegrown proto leg ~very simplistic).  I just got a seeed studio motor sheild but haven't tried to hook it up yet.  I have a couple of different plans to use a total of only 6 to 8 servos to control 6 legs.  I don't really know what I'm doing but I'm determined to figure it out.

retrolefty:
I'm beginning to understand that the arduino only runs one command at a time.  But it's the speed at which it sends incremental pulses to the motors, switching back and forth between them that will produce an impression of simultaneous operation.  The coordinated 'x' and 'y' motor movements, which are basically linear, will appear as a diagonal or curved path ~sort of like a digital representation of an analog wave.

zoomkat:
Thank you for the code example, although I'm not sure that I understand what it's doing.  Please correct me if I'm wrong, but it appears that the serial function is being used to produce the bit information that gets redefined and sent out to the servos.  And the serial function is quick enough to supply the info in time for each pulse to a servo which is happening within microsecond intervals.
   Does this particular routine only control 4 servos?  Can more servos be added?
   Does the 'n' variable need to be defined as an integer value?  or is the code doing this on its own as it continually loops? 
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Dec 28, 2012, 09:11 am
Quote
Does this particular routine only control 4 servos?

Yes.

Quote
Can more servos be added?

Yes, though I'd advise using an array of Servos, rather than individual named instances.
With a regular Arduino, you ought to be able to control up to twelve, more with a Mega.

Quote
Does the 'n' variable need to be defined as an integer value?

It needs to be an integer datatype, because that is what the Servo write methods expect.

Quote
or is the code doing this on its own as it continually loops? 

Sorry, don't understand the question
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 28, 2012, 09:56 am
Quote
Quote
or is the code doing this on its own as it continually loops?
Sorry, don't understand the question

I'm not sure if I understand it either.

So the integers n are the microsecond values given by the readString.index?

I am working now to adapt this routine to my prototype setup and see if it works.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 28, 2012, 10:17 pm
zoomkat:

I'm having some trouble understanding what/how I need to input parameter values into the code to produce a desired result.
For the 'expect single strings' example, I assume the lettered values represent microseconds and then degrees per each defined servo.

  Do these get input to 'if (c == ','), or after any of the comparison operators (>,<, etc.), or manually replace 'n' anywhere? and should they look the same, with a value (100a) followed by a letter?   Or, where do motor position parameters get input?
  How many changes of direction will this routine handle as is without repeating any of the 'if' statements?(maybe I shouldn't try to ask this last question yet, until I see a result)

Thank you for posting this example, at least I have a direction to work in.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Dec 29, 2012, 01:55 am
Quote
I'm having some trouble understanding what/how I need to input parameter values into the code to produce a desired result. For the 'expect single strings' example, I assume the lettered values represent microseconds and then degrees per each defined servo.


You should be testing the code to see the results. Using the posted code, sending the first line below from the serial monitor to the arduino will position myservoc at 30 deg., myservob at 180 deg., myservoa at 70 deg., and myservod at 120 deg. The second line will send 700us to myservoa, 1500us to myservoc, and 2000us to myservod.

Code: [Select]
30c,180b,70a,120d,
700a,1500c,2000d,
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 29, 2012, 04:51 am
Sweet, I have some movement of the motors although I'm still not clear on how to input the values correctly.
I'll keep experimenting and see what happens.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 29, 2012, 10:39 am
Cool, it works.  this is a whole new level of programming for me, it's hard to describe how I feel about it.   I had some problems with my com ports that I don't understand, I've never had a problem with them before but it seems to have sorted itself out. 

So now I need to figure out how to run a few short, looped series of strings (walking patterns for each leg ~they should all be the same, half with an opposite order of operation)  in a function similar to 'Serial.printIn(readString)' that will be stored on the arduino so that the 'string loops' can be incorporated into sensor iterations that will determine travel direction.  I think I have most of my sensor iteration figured out, except for the directional radio signal receiver, but that'll come later.

Thanks for the guidance everyone, I will gladly accept more help with my project. 
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 30, 2012, 12:10 pm
I just started working on this and have a 'ways to go'  ~gotta sleep at some point, though.  I've decided to drop the idea of a smooth gait until more important things are taken care of first.  I haven't gone all the way through it or compiled it to see where the disjunctions are yet.  For the time being this will only be for one leg with 2 servos,  it will gradually expand from there.  I will edit this post as I work on it and ask for advice accordingly - unless anyone is able to see any obvious, needed restructuring.

Code: [Select]
/*
'zoomkat 11-22-12 simple delimited ',' string parse' is combined with 'PROGMEM string demo'
inside of a while loop that gets started with a bumper sensor used as a manual switch.
Moves one leg prototyped for a hexapod ~to be further expanded...
                             ********************************
        *Testing this gave me alphabet characters in the serial monitor instead
         of the indexed numbers I defined (degree values for servos), this tells me
          I must be close.  A simple change of datatypes only gives disassembler messages
          I don't understand(strcpy_P). Some help with this would be great.*  
                             ********************************
zoomkat 11-22-12 simple delimited ',' string parse
        from serial port input (via serial monitor)
        and print result out serial port
        multi servos added
       
PROGMEM string demo
       -How to store a table of strings in program memory (flash), and retrieve them.
          Information summarized from:
       http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
              -Here is a good template to follow for setting up a
               table (array) of strings in program memory.
       -Setting up the strings is a two-step process.               */

 //define strings
#include <avr/pgmspace.h>
prog_char string_0[] PROGMEM = {'60a, 90b'};   //positions leg at ready(may have no use)
prog_char string_1[] PROGMEM = {'25a, 170b'};  //gait for one leg (2 motors(a,b))
prog_char string_2[] PROGMEM = {'160a'};       //
prog_char string_3[] PROGMEM = {'5b'};         //
prog_char string_4[] PROGMEM = {'25a'};        //
//prog_uint16_t string_5[] PROGMEM = ;
//prog_uint16_t string_6[] PROGMEM = ;
//prog_uint16_t string_7[] PROGMEM = ;
//prog_uint16_t string_8[] PROGMEM = ;
//prog_uint16_t string_9[] PROGMEM = ;

 // Then set up a table to refer to strings.
PROGMEM const char *string_table[] =  //change "string_table" name to suit
{  
 string_0,
 string_1,
 string_2,
 string_3,
 string_4,
//  string_5
//  string_6,
//  string_7,
//  string_8,
//  string_9,
};
char buffer[32];  //needs to be large enough for the largest string it must hold
                 //may eventually hold up to 240 characters for all servos  
String readString;
//int string[] = {1,2,3,4,5,6,7,8,9};

#include <Servo.h>
Servo myservoa, myservob;  // create servo object to control a servo

#include <Wire.h>
const int bumperPinR = 2;   // the number of the bumper pin
const int bumperPinL = 4;   //
 int bumperStateR = 0;      // variable for reading the bumper status
 int bumperStateL = 0;      //

void setup()
{
 Serial.begin(9600);
         //wrong idea but want to save the values temporarily  
//String('60a, 90b');  //positions leg at ready(may have no use)
//String('25a, 170b');  //gait for one leg (2 motors(a,b))
//String('160a');       //
//String('5b');         //
//String('25a');        //
//String('125a, 140b');  //smoothed motion not in use
//String('80a, 150b');   //
//String('45a, 160b');   //
//String('30a, 170b');   //

 //myservoa.writeMicroseconds(1500);   //set initial servo position if desired?
 //myservob.writeMicroseconds(1500);   //
myservob.attach(8);   //the pin for the servob control
myservoa.attach(9);   //
 //Serial.println("");  //keep track of what is loaded

pinMode(bumperPinR, INPUT);  //sets the bumper pins as an inputs
pinMode(bumperPinL, INPUT);  //

Wire.begin();      //initializes/activates voltage sensing for bumperpins?  
}

void loop()
{
 bumperStateR = digitalRead(bumperPinR);   //read state of bumper sensors
 //bumperStateL = digitalRead(bumperPinL);   //

while (bumperStateR == LOW)      //begin a loop(one leg walking) with bumper sensor
{
  for (unsigned int i = 1; i < 8; i++)   //prints successive strings in table?
  {                                                    //'strcpy_P' copies strings from program memory to buffer,
    strcpy_P(buffer, (PGM_P)pgm_read_word(&(string_table[i]))); //necessary casts and dereferencing
    Serial.println(buffer);                                           //required to gather data from table above.
    delay(500);                  //~line:'strcpy_P' seems to be the problem...~        
  }
  if (Serial.available())  
  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',')            //where/what is 'char c'?  
    {
      if (readString.length() >1)  //greater than 1 char?
      {
        Serial.println(readString);  //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

         // auto select appropriate value, my servos use 0-180 so 181 should work
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
        }
        else
        {  
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
        }
        readString="";  //clears variable for new input
      }
    }  
    else
    {    
      readString += c;  //makes the string readString
    }
  }
}
}


Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Dec 30, 2012, 12:13 pm
Code: [Select]
String string1 =  String('25a, 170b');   
You haven't even tried to compile this, have you?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Dec 31, 2012, 09:30 am
AWOL:

No, I didn't try to compile it, I just threw it together after some research and wanted to see what initial responses it would conjure.

I just replaced/modified it (above) with a version that survived the compiler but hasn't yet been tested.  I'm gonna do that now and see what happens.


HMMM....  I'm having 'com port' problems again, not sure what's happening with my ports, so the code (above) remains untested until I figure this out.


  1-2-13.   Upon testing, alphabet characters printed to the serial monitor instead of the indexed number values.  I changed datatypes to 'unsigned int' and 'uint16_t', used '#define' for the first line, and tried quite a few combinations of changes with no results.  There must be more to it than simply changing  datatypes, I don't know.   I could use some help with it if anyone has any ideas.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 02, 2013, 08:36 pm
I need help
                setting up strings in PROGMEM as 'int' or 'unsigned int' instead of 'char' datatypes.  I think the routine is really close to doing what I want except it prints alphabet characters only instead of the indexed numbers I have defined in the first few lines of code (refer to my last couple of posts and the code above)

Any suggestions or info about this would be greatly appreciated.  Thanx
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Jan 02, 2013, 09:09 pm
Quote
I think the routine is really close to doing what I want
What routine would that be?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 02, 2013, 09:23 pm
Maybe I'm not using the word 'routine' correctly, but the code I'm referring to is in reply #19 (above).  I refined and replaced what I had first posted there but the new code gives me the wrong results.  There are a few comments in the code and in subsequent posts.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Jan 02, 2013, 09:27 pm
The code in reply #19 needs to have the single quotes replaced with double quotes where necessary, otherwise chances of success are slim.
When you've done that and compiled it, repost your code, and tell us how it behaves.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 02, 2013, 09:55 pm
Sweet, I'll try that.  I thought that might possibly be part of the problem ~hopefully it's the whole problem. 
It will probably be several hours before I can get back online with results.
Thanx
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 03, 2013, 07:28 am
AWOL:  The use of double quotes for defining the strings was definitely part of, if not the entire, problem.

RESULTS:   The code below prints the defined strings {","}; line by line in sequence to the serial monitor and timed according to the delay.  This is only partially what I wanted because Serial.read either is not reading them as they are being printed or they are not being converted to integers and/or not being written to the servos.  The 'Serial.read/write' section [from zoomkat] of the loop (everything at the bottom after 'if(Serial.available())' ) works fine on its own with manual input into the serial monitor but apparently doesn't do anything in combination with the PROGMEM section/s.  I'm not sure what needs to happen now for the strings to get written to the servos, I don't know what the disconnect is.  It may only be one or two lines away from working, or may need an entirely new approach.   :|
I did rearrange a few things several times, notably: PROGMEM, so I'll try repositioning a few things, before continuing to research.

Code: [Select]
/*
'zoomkat 11-22-12 simple delimited ',' string parse' is combined with 'PROGMEM string demo'
inside of a while loop that gets started with a bumper sensor used as a manual switch.
Intended to control one leg prototyped for a hexapod ~will be further expanded as the bugs
get worked out...

zoomkat 11-22-12 simple delimited ',' string parse
        from serial port input (via serial monitor)
        and print result out serial port
        multi servos added
       
PROGMEM string demo
       -How to store a table of strings in program memory (flash), and retrieve them.
          Information summarized from:
       http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
              -Here is a good template to follow for setting up a
               table (array) of strings in program memory.               */

#include <avr/pgmspace.h>
PROGMEM prog_char string_0[] = {"60a, 90b"};   //positions leg at ready (may have no use)
PROGMEM prog_char string_1[] = {"25a, 170b"};  //gait for one leg (2 motors(a,b))
PROGMEM prog_char string_2[] = {"160a"};       //
PROGMEM prog_char string_3[] = {"5b"};         //
PROGMEM prog_char string_4[] = {"25a"};        //

 // Then set up a table to refer to strings.
PROGMEM const char *string_table[] =   //change "string_table" name to suit
{  
 string_0,
 string_1,
 string_2,
 string_3,
 string_4,
};
char buffer[4];  //needs to be large enough for the largest string it must hold
                     //may eventually hold up to 30 indexed variables for all servo/sensor functions  
String readString;

#include <Servo.h>
Servo myservoa, myservob;   //create servo object to control a servo

#include <Wire.h>
const int bumperPinR = 2;    // the number of the bumper (whisker) pin
 int bumperStateR = 0;       // variable for reading the bumper status

void setup()
{
 Serial.begin(9600);

 //myservoa.writeMicroseconds(1500);   //set initial servo position if desired?
 //myservob.writeMicroseconds(1500);   //
myservob.attach(8);     //the pin for the servob control
myservoa.attach(9);     //
 //Serial.println("");     //keep track of what is loaded

pinMode(bumperPinR, INPUT);     //sets the bumper pins as an inputs

Wire.begin();      //initializes/activates voltage sensing for bumperpins?  
}
void loop()
{
 bumperStateR = digitalRead(bumperPinR);    //read state of bumper sensors

while (bumperStateR == LOW)      //begin a loop(one leg walking) with bumper sensor
{
  for (int i = 1; i < 4; i++)    //prints successive strings in table?
  {
        //'strcpy_P' copies strings from program memory to buffer,
        //necessary casts and dereferencing required to gather data from table.
    strcpy_P(buffer, (char*) pgm_read_word(&(string_table[i])));
    Serial.println(buffer);                                          
    //delay(500);                 //delay will certainly need adjustment    

//everything beyond this point does not seem to correlate with that above, although
 //it does control the servos when values are manually entered into the serial monitor
   if (Serial.available())  
   {
     char c = Serial.read();   //gets one byte from serial buffer
     if (c == ',')              //where/what is 'char c'??  
     {
       if (readString.length() >1)   //greater than 1 char??
       {
         Serial.println(readString);  //prints string to serial port out
         int n = readString.toInt();   //convert readString into a number
            // auto select appropriate value ~my servos use 0-180, so 181 should work
         if(n >= 500)                  //don't know if I'm interpreting this correctly
         {
           Serial.print("writing Microseconds: ");       //header for input 'n >= 500' in monitor
           Serial.println(n);
           if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
           if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
         }
         else
         {  
           Serial.print("writing Angle: ");                 //header for input 'n < 500'
           Serial.println(n);
           if(readString.indexOf('a') >0) myservoa.write(n);
           if(readString.indexOf('b') >0) myservob.write(n);
         }
         readString="";    //clears variable for new input
       }
     }  
     else
     {    
       readString += c;    //makes the string readString
     }
     }
  }
}
}

********************************************************************************
1/5/13
                                                       I need help!
      Here's what I'm trying to do:
1) Store strings to PROGMEM
2) Retrieve strings from PROGMEM using Serial()
3) Write strings to multiple servos in sequence/s
      Purpose:
Mainly to have simultaneous operation of multiple servos and sensors, the other would be to conserve memory for functions.
   
  The 'disjunction' appears to be between 'strcpy_P' and 'if (Serial.available())'.
  I've made too many changes, additions, omissions to the code to remember everything I've tried.  I  can't really go much further with my project without solving this problem.

                              Any suggestions or additional info will be greatly appreciated!
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Jan 06, 2013, 08:54 am
You may need to look at just what PROGMEM does and how it works, and see if it supports the way you are trying to use it.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 11, 2013, 05:40 pm
zoomkat:

Yes, I have been trying to find as much info on it as possible.  I think I'm heading in the right direction and what I now understand or at least think I understand is that there is a conversion problem.  It is between the 'serial buffer' and the 'readString' variable which is then indexed to 'n' in 'servo.write()'.  Maybe, if possible, I should not do a conversion and try to work with only the buffer up to '.indexOf()'.  I'm still looking for applicable information on this subject. 
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: PaulS on Jan 12, 2013, 05:38 pm
Quote
I think I'm heading in the right direction and what I now understand or at least think I understand is that there is a conversion problem.

But, I'm not going to show you my code.

Quote
It is between the 'serial buffer' and the 'readString' variable which is then indexed to 'n' in 'servo.write()'.

Well, certainly. Fix it. Or not. Only you can see what you are talking about.

Quote
I'm still looking for applicable information on this subject. 

What subject would that be?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 25, 2013, 11:54 am
PaulS:

So are your comments serious?
                                       ...joking?
                                 or seriously joking?

the code I've been working on is on post #27
       are you saying you aren't going to post yours?

Well, if you look at post #27, you can see it too
if you were to run it, you can certainly see what it do
Unfixed. And so.

the subject is apparently in the form of a question as the title of the thread (see title)
      any more explanation of my problem would be ad nauseam

If you have any info that could possibly help me solve it, I'd love to know about it. 
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Jan 25, 2013, 12:33 pm
Quote
the code I've been working on is on post #27
       are you saying you aren't going to post yours?

If you've been working on the code in post #27, presumably it now doesn't look like the code in post #27, so you need to post it again.
Now.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Jan 25, 2013, 08:07 pm
Quote
the subject is apparently in the form of a question as the title of the thread (see title)
      any more explanation of my problem would be ad nauseam


Well, "2 servos (or any functions) operating simultaneously?" seems to have you stummped. The code only does one thing at a time, but the code itself performs actions so fast you will not be able to detect the individual actions (unless you add delays and such).

Quote
If you have any info that could possibly help me solve it, I'd love to know about it. 


Well, if the "it" problem is a knowledge deficit on your part, it is up to you to get up to speed.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 26, 2013, 04:51 am
AWOL:
I have probably made 100's of changes to the code in #27 by now, except none of them have have brought me any closer to my goal.  Each change has had either no effect, produces undesirable effects, nullifies the code altogether, or doesn't compile.  
I believe each half of the code (PROGMEM with table to Serial buffer) and (Serial.read to index. to .write) are doing things I want to see happen, I just can't seem to integrate them to work together.  Nothing I have done has furthered what is already there.
So, effectively, the code remains unchanged.
 
zoomkat:
I understand that it does one thing at a time and gives the impression of simultaneity, the code you presented to me (2nd half of the code in #27) definitely produces this effect.  I'm still trying to figure out what function/s will replace manually inputting parameters to serial.  

The "it" certainly results from my surplus of ignorance but I'm not sitting idle waiting for someone to bestow their esoteric knowledge unto me, although it would be sweet to be blessed with such an occurrence, not unlike you supplying much the code I'm working with now.  I'm doing my due diligence and have gone through the entire reference especially focused on 'string theory', investigated many of the links provided and their links also, as well as other forums and books.  I'm learning as much as I can as quickly as I can - I may have totally overlooked the exact solution because I didn't know what I was looking at, I don't know.
I'm not going to give up on the issue, I want to understand how it is done, but I'm reaching a threshold of having to re-prioritize in order to meet the deadline for the robotics challenge.  I've figured out a way for a hexapod to use 2 servos to do the work of the 12 originally planned and as long as I am able to get the parts printed it shouldn't be too difficult to make happen.  I won't need to have the servos operate simultaneously.  

I will continue to work on this simultaneous servo problem in my spare time.  In the meantime I built a different style of 'walking' robot prototype using 2 servos out of battery compartments and paperclips.  I've got a couple of other projects that I want to finish/get started after the challenge.  I'll go nuts if I only focus on this problem.

[img][img]
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Jan 26, 2013, 05:10 am
There are lots of three servo hexipods, and other simple walking bots. Below are some ideas.

http://www.google.com/search?num=100&hl=en&lr=&tbo=d&as_qdr=all&spell=1&q=three+servo+hexapod&sa=X&ei=DVYDUdKGAcbo0gGWlYFQ&ved=0CC8QBSgA&biw=1173&bih=642

http://davidbuckley.net/DB/Inspire.htm

(http://davidbuckley.net/DB/inspired/Joe'sShopBigFoot_files/joesbabe.jpg)
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Jan 26, 2013, 09:05 am
Ha Ha, she's one hot bot.

I thought I'd post my first project.  
I don't have much to offer the forum yet, but maybe someone can benefit from this.
I built this robot out of roof flashing, designed to stay on top of fine loose sand,  spike-paddles were cut into each wheel and a 'ski' was on a pivot in the rear
I wish I had a pic of it finished

here's the code I used with it:
  ~this has nothing to do with my hexapod idea
Code: [Select]
/* 10-5-10
 Pete Dokter
 SparkFun Electronics

This is an example sketch for Arduino that shows very basically how to control an Ardumoto
motor driver shield with a 5V Arduino controller board.

~~~ The variable values in this code have changed significantly from the (above) author's draft,
   I also incorporated bumper sensors (whiskers) with iterations and fixed the northward navigation
  */
#include <Wire.h>  
#include <LSM303.h>  //compass/accelerometer
LSM303 compass;

int pwm_a = 3;   //PWM control for motor outputs 1 and 2 is pin 3
int pwm_b = 11;  //                               outputs 3 and 4 is pin 11
int dir_a = 12;  //direction control for motor outputs 1 and 2 is pin 12
int dir_b = 13;  //                                      outputs 3 and 4 is pin 13

const int bumperPinR = 2;   //bumper pins
const int bumperPinL = 4;  

int bumperStateR = 0;      //variable for reading the bumper status
int bumperStateL = 0;    

int IRsensorPin = A0;     //input pin for IR sensor
int IRsensorValue = 0;    //variable to store value of IR sensor

int LEDPin = 13;          //On when backing up

void setup()
{
  Serial.begin(9600);
 pinMode(pwm_a, OUTPUT);   //Set control pins to be outputs (motors)
 pinMode(pwm_b, OUTPUT);
 pinMode(dir_a, OUTPUT);
 pinMode(dir_b, OUTPUT);

 //initialize bumper and IR pins
 pinMode(bumperPinR, INPUT);
 pinMode(bumperPinL, INPUT);
 pinMode(IRsensorPin, INPUT);

 pinMode(LEDPin, OUTPUT);

 digitalWrite(dir_a, LOW);    //Set motor direction, 1 low, 2 high
 digitalWrite(dir_b, LOW);    //Set motor direction, 3 high, 4 low
 analogWrite(pwm_a, 255);     //set both motors to 100% duty cycle
 analogWrite(pwm_b, 255);

 Wire.begin();            
 compass.init();
 compass.enableDefault();
 //Use Calibrate example program for compass values
            //(environment specific ~magnetics differ from place to place, recalibrate)  
    //M min X: -405 Y: -108 Z: -9 M max X: -382 Y: -86 Z:8
                  //values are copied from serial monitor, pause calibration to copy  
  compass.m_min.x = -405;
  compass.m_min.y = -108;
  compass.m_min.z = -9;
  compass.m_max.x = -382;
  compass.m_max.y = -86;
  compass.m_max.z = +8;
}
void loop()
{
   digitalWrite(LEDPin, LOW);
 digitalWrite(dir_a, LOW);   //motor direction, 1 low, 2 high (forward)
 digitalWrite(dir_b, LOW);   //                      3 high, 4 low

 analogWrite(pwm_a, 200);    //motors run at 80% duty cycle (slower)
 analogWrite(pwm_b, 200);
   
compass.read();
int heading = compass.heading((LSM303::vector) {1,0,0} );   //1,0,0 aligns North
   Serial.println("");
   Serial.print("Compass: ");
   Serial.print(heading);
   Serial.print("\t");

//IR reading
 IRsensorValue = analogRead(IRsensorPin);    
   Serial.print("IR Reading: ");
   Serial.print(IRsensorValue);
   Serial.print("\t");

//read state of bumper value
 bumperStateR = digitalRead(bumperPinR);
 bumperStateL = digitalRead(bumperPinL);

//Check IR Sensor
  if(IRsensorValue > 455)
   {
       Serial.println("");
       Serial.println("IR rev ");
 //reverse
    digitalWrite(dir_a, HIGH);  //motor direction, 1 low, 2 high
    digitalWrite(dir_b, HIGH);  //                     3 high, 4 low

    analogWrite(pwm_a, 225);    //motors run slower than 100% duty cycle =(255)
    analogWrite(pwm_b, 225);
     delay(450);

 //turn right
    digitalWrite(dir_a, HIGH);  //motor direction, 1 low, 2 high
    digitalWrite(dir_b, HIGH);  //                      3 high, 4 low

    analogWrite(pwm_a, 15);     //turns left in reverse
    analogWrite(pwm_b, 245);    //points further right in forward direction
     delay(520);
     
 //forward
    digitalWrite(dir_a, LOW);   //motor dir, 1 low, 2 high
    digitalWrite(dir_b, LOW);   //            3 high, 4 low

    analogWrite(pwm_a, 230);    //motors run at ()% duty cycle
    analogWrite(pwm_b, 230);
     delay(850);
   }
else
 {  
//check if bumper triggered
 if (bumperStateR == LOW)
  {    
     //back and turn L    
        Serial.println("");
        Serial.println("bumperR rev ");
  //reverse
    digitalWrite(dir_a, HIGH);  //motor dir, 1 low, 2 high
    digitalWrite(dir_b, HIGH);  //            3 high, 4 low

    analogWrite(pwm_a, 225);    //motors run slower than 100% duty cycle
    analogWrite(pwm_b, 225);
     delay(450);

  //turn left
    digitalWrite(dir_a, HIGH);  //motor dir, 1 low, 2 high
    digitalWrite(dir_b, HIGH);  //             3 high, 4 low

    analogWrite(pwm_a, 15);     //turns left in reverse
    analogWrite(pwm_b, 245);    //points further right in forward direction)
     delay(525);
     
  //forward
    digitalWrite(dir_a, LOW);   // 1 low, 2 high
    digitalWrite(dir_b, LOW);   // 3 high, 4 low

    analogWrite(pwm_a, 230);    //motors run at ()% duty cycle
    analogWrite(pwm_b, 230);
     delay(880);
   }
 if (bumperStateL == LOW)
  {    
     //back and turn R    
        Serial.println("");
        Serial.println("bumper L rev ");
  //reverse
    digitalWrite(dir_a, HIGH);   //1 low, 2 high
    digitalWrite(dir_b, HIGH);   //3 high, 4 low

    analogWrite(pwm_a, 225);     //motors slower than 100% duty cycle
    analogWrite(pwm_b, 225);
     delay(450);

  //turn right
    digitalWrite(dir_a, HIGH);   //1 low, 2 high
    digitalWrite(dir_b, HIGH);   //3 high, 4 low

    analogWrite(pwm_a, 245);     //turns left in reverse
    analogWrite(pwm_b, 15);      //points further right in forward direction)
     delay(525);
     
  //forward
    digitalWrite(dir_a, LOW);    //1 low, 2 high
    digitalWrite(dir_b, LOW);    //3 high, 4 low

    analogWrite(pwm_a, 230);     //motors at ()% duty cycle
    analogWrite(pwm_b, 230);
     delay(880);
   }  
//break out of iteration, start navigation
  else
   {
    if(heading < 255)     // (270) = north
     {
      //turn left
        Serial.print("left");
      digitalWrite(dir_a, LOW);   //1 low, 2 high
      digitalWrite(dir_b, LOW);   //3 high, 4 low

      analogWrite(pwm_a, 135);    //motor A (left) slower, B (right) faster
      analogWrite(pwm_b, 225);
       delay(40);
     }

    if(heading > 285)
     {
      //turn right
        Serial.print("right");
      digitalWrite(dir_a, LOW);   //1 l, 2 h
      digitalWrite(dir_b, LOW);   //3 h, 4 l

      analogWrite(pwm_a, 225);    //motor A faster, B slower
      analogWrite(pwm_b, 135);
       delay(40);
     }
   }
 }  
}


(http://)   How do I attach a normal size photo?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 07, 2013, 08:18 pm
Ok, so I found a new approach to my problem.  I'm a bit more hopeful but I can't get it to compile. 

Here is what I found (the list of compiler errors is huge):
Code: [Select]
//(this sketch is straight from the playground)
// test sketch for MegaServo library
// this will sweep all servos back and forth once, then position according to voltage on potPin

#include <MegaServo.h>

#define FIRST_SERVO_PIN  22 

MegaServo Servos[MAX_SERVOS] ; // max servos is 32 for mega, 8 for other boards

int pos = 0;      // variable to store the servo position
int potPin = 0;   // connect a pot to this pin.

void setup()
{
  for( int i =0; i < MAX_SERVOS; i++)
    Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);

  sweep(0,180,2); // sweep once   
}

void sweep(int min, int max, int step)
{
  for(pos = min; pos < max; pos += step)  // goes from 0 degrees to 180 degrees   
  {                                  // in steps of 1 degree
    for( int i =0; i < MAX_SERVOS; i++){
      Servos[i].write( pos);     // tell servo to go to position 
    }
    delay(15);                  // waits 15ms for the servo to move
  }
  for(pos = max; pos>=min; pos-=step)     // goes from 180 degrees to 0 degrees
  {                               
    for( int i =0; i < MAX_SERVOS; i++){
      Servos[i].write( pos);     // tell servo to go to position 
    }
    delay(15);                  // waits 15ms for the servo to move
  }   
}

void loop()
{
  pos = analogRead(potPin);   // read a value from 0 to 1023
  for( int i =0; i < MAX_SERVOS; i++)
    Servos[i].write( map(pos, 0,1023,0,180));   
  delay(15);   
}


I compared the above sketch to others I found (sorry they aren't cited, I didn't record where the other similar examples were from) and here are the changes I made:
Code: [Select]
#include <MegaServo.h>
#include <Wire.h>
#include <arduino.h>

#define NBR_SERVOS 12
#define FIRST_SERVO_PIN  2 
  MegaServo Servos[NBR_SERVOS] ; // max servos is 12
   MegaServo MegaServo;
int pos = 0;      // variable to store the servo position
int potPin = 0;   // connect a pot to this pin.
 
void setup()
{
   Serial.begin(9600);
  MegaServo.writeMicroseconds(1500);
  int i = 0;
  pinMode(i,OUTPUT);
}

void Servos digitalWrite.MegaServo( )
{
  for( int i =0; i < NBR_SERVOS; i++)
    Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);

  sweep(0,180,2); // sweep once   
}

void sweep(int min, int max, int step)
{
  for(pos = min; pos < max; pos += step)  // goes from 0 degrees to 180 degrees   
  {                                  // in steps of 1 degree
    for( int i =0; i < NBR_SERVOS; i++){
      Servos[i].write( pos);     // tell servo to go to position 
    }
    delay(15);                  // waits 15ms for the servo to move
  }
  for(pos = max; pos>=min; pos-=step)     // goes from 180 degrees to 0 degrees
  {                               
    for( int i =0; i < NBR_SERVOS; i++){
      Servos[i].write( pos);     // tell servo to go to position 
    }
    delay(15);                  // waits 15ms for the servo to move
  }   
}

void loop()
{
  pos = analogRead(potPin);   // read a value from 0 to 1023
  for( int i =0; i < NBR_SERVOS; i++)
    Servos[i].write( map(pos, 0,1023,0,180));   
  delay(15);   
}

compiler error:  MegaServo:23: error: expected initializer before 'digitalWrite'

This is the only error that this version produces.  I don't know that it's necessarily a good thing or not.  I guess I don't understand what an 'expected initializer' is, even after some research on it.  If this does end up compiling, I don't know that it will work correctly as I don't understand most of what is going on in it.  Please don't ask me WHY I made some of the changes were made in it as I don't really remember and probably couldn't tell you in the first place.  All I know is that this is the closest it has come to compiling.

Thanx for any input on this
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Feb 07, 2013, 09:00 pm
Code: [Select]
void Servos digitalWrite.MegaServo( ) what's that?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: PaulS on Feb 08, 2013, 01:40 am
Code: [Select]
   MegaServo MegaServo;
Having an instance name the same as the class name is not the brightest idea I've seen today.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 08, 2013, 09:30 am
AWOL:  
If I knew, I could tell you.  
At some point I had tried some random switching of terms, that's probably what that is a result of.
Correct me if I'm wrong.  Your comment would imply that you can easily see or even know for certain that something is not right with that particular line of code.  I'm fairly sure that's not the only error but if you would care to expand on your comment a bit and share some of the wisdom I am not privy to, I would more than appreciate being exposed to what you know about it. 

PaulS:
I was thinking the same thing when I saw something similar in another code but figured I would give it a shot anyway.
While we are on the subject of luminescence, would you like to shed some light on why the idea is so dim?  Maybe explain the conflict or possible conflicts?  Can instance and class written structures be/look exactly the same?  Could you suggest how it be done differently?  What would you do in such a case?  Does this even need to be done at all?


What I do know is that there is only one compiler error in the revision - an enormous improvement from the original in the playground where it is stated (in sum):  just copy and paste, no changes necessary.  I don't know who's smoking more of what on the playground but as you can see it clearly was not that simple.  Unless of course there is some obvious step omitted that every programmer knows to be common knowledge while overlooking the inexperienced newbie who's yet to be a programmer.  
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Feb 08, 2013, 10:10 am
Could you post a link to the Playground page where you found that please?
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 08, 2013, 10:42 am
http://playground.arduino.cc//Code/MegaServo
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Feb 08, 2013, 10:50 am
Quote
Your comment would imply that you can easily see or even know for certain that something is not right with that particular line of code.  

It isn't even like saying "My hovercraft is full of eels", a sentence that follows the rules of English syntax, but which makes very little sense.

Code: [Select]
void Servos digitalWrite.MegaServo( )
Here, we have the implication that we're looking at a function definition which doesn't return anything.
After that, my brain refuses to recognise what is going on.
I almost see a class name ("Servo"), a function name I recognise ("digitalWrite"), but with a structure field name ("MegaServo") I don't.

It's a bit like a Dali painting, expressed in C.

Afterthought Edit: In contrast, Duff's Device (http://en.wikipedia.org/wiki/Duff%27s_device) is more like an M.C. Escher (http://en.wikipedia.org/wiki/M._C._Escher) print
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: JimboZA on Feb 08, 2013, 10:55 am
Quote
"My hovercraft is full of eels", a sentence that follows the rules of English syntax, but which makes very little sense.



.....not true... makes perfect sense to Hungarians in tobacconists.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 10, 2013, 12:48 pm
AWOL:
I can't say it makes or had made much sense to me either.  That just happened to be my last fairly random guess at changing the statement before I posted the code.  But, that's why I posted it, because I don't understand what was wrong with it in the first place before I tried a number of different combinations in order to at least get it to compile.

You already made it clear it doesn't make sense and this is what I already know as well, so further describing how it is senseless using simile is redundantly saying it again with a nice touch of sarcasm.  Although it may help me realize how little I understand about programming in C++, it doesn't exactly help me get any closer to my goal of operating servos for a hexapod which is the reason for this thread.

I was hoping to gain insight into how this code could be corrected, rearranged or at least experimentally altered, or pointed in some useful direction that may lead towards a solution.  A suggestion for a different approach, or as to how it might be changed, or added to, or parts to be removed would probably benefit my situation.  If your brain refuses to recognize what is going on, it would seem that there is little motivating any investigation into the underlying issue/s with this code, and then I wonder, why bother.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: wildbill on Feb 10, 2013, 01:27 pm
Get rid of this:
Code: [Select]
   MegaServo MegaServo;

and the line that references it in setup.

Change this:
Code: [Select]
void Servos digitalWrite.MegaServo( )

to this:
Code: [Select]
void SetupServos( )

and call it from setup. That'll get you closer, though I didn't compile it, so it may be closer but with a new set of compiler error messages.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Feb 10, 2013, 03:42 pm

Quote
If your brain refuses to recognize what is going on, it would seem that there is little motivating any investigation into the underlying issue/s with this code, and then I wonder, why bother.

Because you asked me to.
Quote
if you would care to expand on your comment a bit and share some of the wisdom I am not privy to,
I would more than appreciate being exposed to what you know about it. 


There was no sarcasm.
You'll just have to trust me on that.
You wouldn't like me when I'm sarcastic.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 10, 2013, 08:45 pm
wildbill:

Thank you for your suggestions, I will try that and see what happens.

AWOL:

I can really only gather that you deem my attempts at composing a code I can use as hardly worth looking into.  On the other hand I would have to consider my query as worthy of attention seeing as how there are over 2000 views of this thread.  That would imply to me that there is a substantial number of people interested in the exact same information but who may be without the patience to be persistent in asking for help with it.
So when you get your dander up, do you shred your clothes and turn green? (just kidding) :smiley-mr-green:
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: PaulS on Feb 11, 2013, 12:31 pm
Quote
seeing as how there are over 2000 views of this thread.

Some of us tuned in just to laugh.
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: evolion on Feb 20, 2013, 08:23 am
PaulS:
What a knee slapper, glad I don't know what else you do for fun.  I always thought I was amusing, either that or funny looking. 
So when you're done wiping your chin, ya wanna post a USEFUL comment?  Interject some information that is actually demonstrative of your programming prowess?
Judging from the cocky remarks, the hassle involved is too great and it's much easier to leave snappy critiques that generate that satisfying feeling of self aggrandizement. 
Perhaps I was a bit presumptuous thinking I could come here, without any experience, for more than a spitting contest but to get help and learn a few things.
I wish I could say I appreciate all that you've offered here, Paul, my good buddy ;)
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: cengav4r on Jul 18, 2013, 11:31 am
Hi everbody,
I read posts but I couldnt figure out that can we run 2 servo (or multi function) at same time. (Note that; 2 servos (or more) will not work same degrees they will work different degrees simultaneously.) Does any body know anything?

Note:http://forum.arduino.cc/index.php/topic,118652.0.html
( I also checked above topic.Pauls says we cant.)

best regards
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Jul 18, 2013, 11:42 am
If you're asking "can I control two or more servos to the same or different positions simultaneously using the Servo library?" then the answer is "yes".
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: cengav4r on Jul 18, 2013, 12:15 pm
Thank you for reply. new questions
1.How?
2.Any example? (Pls note that: Servos will work whenever I want, (different positions, maybe different time...))
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: AWOL on Jul 18, 2013, 01:45 pm
Quote
1.How?
2.Any example?

Four servos, independently and simultaneously.
(Uncompiled, untested)
Code: [Select]
const byte N_SERVOS = 4;
const byte servoPin [N_SERVOS] = {2, 3, 4, 5}; //whatever
Servo servo [N_SERVOS]; //simplistic controls on A0, A1...A(n-1)
void setup ()
{
  for (int i = 0; i < N_SERVOS; i++) {
    servo [i].attach (servoPin [i]);
  }
}

void loop ()
{
  for (int i = 0; i < N_SERVOS; i++) {
    servo [i].write (map (analogRead (i), 0, 1024, 0, 180));
  }
}
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: zoomkat on Jul 18, 2013, 10:34 pm

Thank you for reply. new questions
1.How?
2.Any example? (Pls note that: Servos will work whenever I want, (different positions, maybe different time...))


http://forum.arduino.cc/index.php?topic=139121.msg1046613#msg1046613
Title: Re: 2 servos (or any functions) operating simultaneously?
Post by: cengav4r on Jul 23, 2013, 02:53 pm
AWOL and zoomkat thanks for reply.
To AWOL; Your codes works well,
To evolion; Your codes couldnt works fine at my system ( has 2 servos (even I entered serial to 30c,180b,70a,120d,)) , or I couldnt understand enough.(maybe it need different voltage sources)