Just not sure what to be looking for or to modify to drive more servo's.
#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer
#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
The R-Pi struggles with one USB camera (it does fine with its dedicated R-Pi camera, but you can have only one per R-Pi).
> 2 to 3 USB cams for 3D Depth tracking.
As far as I know, there are no small-light-cheap computers that can handle 2 or 3 USB cameras at once. The R-Pi struggles with one USB camera (it does fine with its dedicated R-Pi camera, but you can have only one per R-Pi). Even the quad-core ODROID/U2 can do only very low resolution with 2 USB webcams, from what I have read.
Look for this in Servo.h
Code:#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
Prehaps review the prior messages I wrote too?
Used 1 servo to test each pin assigned 0 to 23.
servo sweeps on pin 0 to 15 = 16 pins
17 to 23 were not outputting.
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
// modified by luenardi De Polo
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
Servo myservo3; // create servo object to control a servo
Servo myservo4; // create servo object to control a servo
Servo myservo5; // create servo object to control a servo
Servo myservo6; // create servo object to control a servo
Servo myservo7; // create servo object to control a servo
Servo myservo8; // create servo object to control a servo
Servo myservo9; // create servo object to control a servo
Servo myservo10; // create servo object to control a servo
Servo myservo11; // create servo object to control a servo
Servo myservo12; // create servo object to control a servo
Servo myservo13; // create servo object to control a servo
Servo myservo14; // create servo object to control a servo
Servo myservo15; // create servo object to control a servo
Servo myservo16; // create servo object to control a servo
Servo myservo17; // create servo object to control a servo
Servo myservo18; // create servo object to control a servo
Servo myservo19; // create servo object to control a servo
Servo myservo20; // create servo object to control a servo
Servo myservo21; // create servo object to control a servo
Servo myservo22; // create servo object to control a servo
Servo myservo23; // create servo object to control a servo
Servo myservo24; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo1.attach(0); // attaches the servo on pin 9 to the servo object
myservo2.attach(1); // attaches the servo on pin 9 to the servo object
myservo3.attach(2); // attaches the servo on pin 9 to the servo object
myservo4.attach(3); // attaches the servo on pin 9 to the servo object
myservo5.attach(4); // attaches the servo on pin 9 to the servo object
myservo6.attach(5); // attaches the servo on pin 9 to the servo object
myservo7.attach(6); // attaches the servo on pin 9 to the servo object
myservo8.attach(7); // attaches the servo on pin 9 to the servo object
myservo9.attach(8); // attaches the servo on pin 9 to the servo object
myservo10.attach(9); // attaches the servo on pin 9 to the servo object
myservo11.attach(10); // attaches the servo on pin 9 to the servo object
myservo12.attach(11); // attaches the servo on pin 9 to the servo object
myservo13.attach(12); // attaches the servo on pin 9 to the servo object
myservo14.attach(13); // attaches the servo on pin 9 to the servo object
myservo15.attach(14); // attaches the servo on pin 9 to the servo object
myservo16.attach(15); // attaches the servo on pin 9 to the servo object
myservo17.attach(16); // attaches the servo on pin 9 to the servo object
myservo18.attach(17); // attaches the servo on pin 9 to the servo object
myservo19.attach(18); // attaches the servo on pin 9 to the servo object
myservo20.attach(19); // attaches the servo on pin 9 to the servo object
myservo21.attach(20); // attaches the servo on pin 9 to the servo object
myservo22.attach(21); // attaches the servo on pin 9 to the servo object
myservo23.attach(22); // attaches the servo on pin 9 to the servo object
myservo24.attach(23); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
myservo3.write(pos); // tell servo to go to position in variable 'pos'
myservo4.write(pos); // tell servo to go to position in variable 'pos'
myservo5.write(pos); // tell servo to go to position in variable 'pos'
myservo6.write(pos); // tell servo to go to position in variable 'pos'
myservo7.write(pos); // tell servo to go to position in variable 'pos'
myservo8.write(pos); // tell servo to go to position in variable 'pos'
myservo9.write(pos); // tell servo to go to position in variable 'pos'
myservo10.write(pos); // tell servo to go to position in variable 'pos'
myservo11.write(pos); // tell servo to go to position in variable 'pos'
myservo12.write(pos); // tell servo to go to position in variable 'pos'
myservo13.write(pos); // tell servo to go to position in variable 'pos'
myservo14.write(pos); // tell servo to go to position in variable 'pos'
myservo15.write(pos); // tell servo to go to position in variable 'pos'
myservo16.write(pos); // tell servo to go to position in variable 'pos'
myservo17.write(pos); // tell servo to go to position in variable 'pos'
myservo18.write(pos); // tell servo to go to position in variable 'pos'
myservo19.write(pos); // tell servo to go to position in variable 'pos'
myservo20.write(pos); // tell servo to go to position in variable 'pos'
myservo21.write(pos); // tell servo to go to position in variable 'pos'
myservo22.write(pos); // tell servo to go to position in variable 'pos'
myservo23.write(pos); // tell servo to go to position in variable 'pos'
myservo24.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
myservo3.write(pos); // tell servo to go to position in variable 'pos'
myservo4.write(pos); // tell servo to go to position in variable 'pos'
myservo5.write(pos); // tell servo to go to position in variable 'pos'
myservo6.write(pos); // tell servo to go to position in variable 'pos'
myservo7.write(pos); // tell servo to go to position in variable 'pos'
myservo8.write(pos); // tell servo to go to position in variable 'pos'
myservo9.write(pos); // tell servo to go to position in variable 'pos'
myservo10.write(pos); // tell servo to go to position in variable 'pos'
myservo11.write(pos); // tell servo to go to position in variable 'pos'
myservo12.write(pos); // tell servo to go to position in variable 'pos'
myservo13.write(pos); // tell servo to go to position in variable 'pos'
myservo14.write(pos); // tell servo to go to position in variable 'pos'
myservo15.write(pos); // tell servo to go to position in variable 'pos'
myservo16.write(pos); // tell servo to go to position in variable 'pos'
myservo17.write(pos); // tell servo to go to position in variable 'pos'
myservo18.write(pos); // tell servo to go to position in variable 'pos'
myservo19.write(pos); // tell servo to go to position in variable 'pos'
myservo20.write(pos);
myservo21.write(pos); // tell servo to go to position in variable 'pos'
myservo22.write(pos); // tell servo to go to position in variable 'pos'
myservo23.write(pos); // tell servo to go to position in variable 'pos'
myservo24.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
/*
Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
Copyright (c) 2009 Michael Margolis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
The servos are pulsed in the background using the value most recently written using the write() method
Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.
Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four.
The sequence used to sieze timers is defined in timers.h
The methods are:
Servo - Class for manipulating servo motors connected to Arduino pins.
attach(pin ) - Attaches a servo motor to an i/o pin.
attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds
default min is 544, max is 2400
write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
writeMicroseconds() - Sets the servo pulse width in microseconds
read() - Gets the last written servo pulse width as an angle between 0 and 180.
readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release)
attached() - Returns true if there is a servo attached.
detach() - Stops an attached servos from pulsing its i/o pin.
*/
#ifndef Servo_h
#define Servo_h
#include <inttypes.h>
/*
* Defines for 16 bit timers used with Servo library
*
* If _useTimerX is defined then TimerX is a 16 bit timer on the curent board
* timer16_Sequence_t enumerates the sequence that the timers should be allocated
* _Nbr_16timers indicates how many 16 bit timers are available.
*
*/
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1
#define _useTimer3
#define _useTimer4
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega32U4__)
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#else // everything else
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
#endif
#define Servo_VERSION 2 // software version of this library
#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
#define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds
#define SERVOS_PER_TIMER 24 // the maximum number of servos controlled by one timer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! changed this to 24
#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
#define INVALID_SERVO 255 // flag indicating an invalid servo index
typedef struct {
uint8_t nbr :6 ; // a pin number from 0 to 63
uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false
} ServoPin_t ;
typedef struct {
ServoPin_t Pin;
unsigned int ticks;
} servo_t;
class Servo
{
public:
Servo();
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
void detach();
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
void writeMicroseconds(int value); // Write pulse width in microseconds
int read(); // returns current pulse width as an angle between 0 and 180 degrees
int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release)
bool attached(); // return true if this servo is attached, otherwise false
private:
#if defined(__arm__)
uint16_t min_ticks;
uint16_t max_ticks;
#else
int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH
int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH
#endif
uint8_t servoIndex; // index into the channel data for this servo
};
#endif
static uint16_t servo_active_mask = 0;
static uint16_t servo_allocated_mask = 0;
static uint32_t servo_active_mask = 0;
static uint32_t servo_allocated_mask = 0;
Oh, I think I see what might be the trouble...
In Servo.cpp, find these 2 lines:
Code:static uint16_t servo_active_mask = 0; static uint16_t servo_allocated_mask = 0;
Try changing them to this:
Code:static uint32_t servo_active_mask = 0; static uint32_t servo_allocated_mask = 0;
Edit: you'll also need the change "mask" to uint32_t in Servo::Servo(), on line 364.
Can I control both teensy's independently each with it's own serial port on the PI?