ServoTimer2 modificacion para Arduino 1.0.X [SOLUCIONADO]

Hola a todos

Estoy haciendo un robot que por ahora funciona correctamente. El problema que tengo es que necesito usar dos servomotores a la vez que uso virtual wire y controlo un driver de motroresdoble puente en h.
Para ello uso la librería ServoTimer2. Tras googlear mucho he visto que no soy capaz de que funcione, de hecho ya no solo con el codigo de mi robot si no con un codigo de ejemplo cogido de internet.

Con mi codigo da este error(la unica diferencia entre el codigo que funciona y el que no es esta linea: #include <ServoTimer2.h>):

C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:5:26: error: WConstants.h: No such file or directory
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp: In function 'void __vector_15()':
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:35: error: 'LOW' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:35: error: 'digitalWrite' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:42: error: 'HIGH' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:42: error: 'digitalWrite' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp: In member function 'uint8_t ServoTimer2::attach(int)':
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:65: error: 'OUTPUT' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:65: error: 'pinMode' was not declared in this scope

Y aqui mi codigo:

 #include <VirtualWire.h>
#include <ServoTimer2.h>

// This code have extracts from differents tutorials on the web that I used long time ago, so I can remmeber the authors 
#define MOTOR1_CTL1  4  // I1  
#define MOTOR1_CTL2  3  // I2  
#define MOTOR1_PWM   2 // EA  
  
#define MOTOR2_CTL1  7  // I3  
#define MOTOR2_CTL2  6// I4  
#define MOTOR2_PWM   5 // EB  
  
#define MOTOR_DIR_FORWARD  0  
#define MOTOR_DIR_BACKWARD   1






// Sensors 
int Sensor1Data;
int Sensor2Data;
int Servo1;
int Servo2;
// RF Transmission container
char Sensor1CharMsg[17]; 
//ServoTimer2 one;
//ServoTimer2 two;


void setup() {
  Serial.begin(9600);
  
   pinMode(MOTOR1_CTL1,OUTPUT);  
   pinMode(MOTOR1_CTL2,OUTPUT);  
   pinMode(MOTOR1_PWM,OUTPUT);  
     
  // Setup pins for motor 2  
   pinMode(MOTOR2_CTL1,OUTPUT);  
   pinMode(MOTOR2_CTL2,OUTPUT);  
   pinMode(MOTOR2_PWM,OUTPUT);
  // sets the digital pin as output
  pinMode(13, OUTPUT);
  
one.attach(9);
two.attach(10);
    
    // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100

    // Bits per sec
    vw_setup(2000);
    vw_set_rx_pin(11);	 
    
    // Start the receiver PLL running
    vw_rx_start();       

} // END void setup

void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
//Taking the data from the control base
    if (vw_get_message(buf, &buflen)) 
    {
	int i;
        // Turn on a light to show received good message 
        digitalWrite(13, true); 
	
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
	{            
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
          Sensor1CharMsg[i] = char(buf[i]);
	}

      sscanf(Sensor1CharMsg, "%d,%d,%d,%d",&Sensor2Data, &Sensor1Data,&Servo1,&Servo2); // Convierte un string en un array
        
        // Turn off light to and await next message 
        digitalWrite(13, false);
    }

// Control the motors 
 if (Sensor1Data > 700){
   int v1 = 255;//map(Sensor1Data,700,1024,150,250);
  motorStart(1, MOTOR_DIR_FORWARD);    
  setSpeed(1, v1);  
  motorStart(2, MOTOR_DIR_FORWARD);        
  setSpeed(2, v1);  
  delay(2); 
  }
  
 if (Sensor1Data < 300){ 
   int v2 = 255;//
   map(Sensor1Data,0,300,250,150); 
   motorStart(1, MOTOR_DIR_BACKWARD);    
   setSpeed(1, v2);  
   motorStart(2, MOTOR_DIR_BACKWARD);        
   setSpeed(2, v2);  
   delay(2); 
    }
 if(300<Sensor1Data<700 && 300 < Sensor2Data < 700){
    motorStop(1);
    motorStop(2);
    }

if(300<Sensor1Data<700){
    if (Sensor2Data > 700){
       int v1 = map(Sensor1Data,700,1024,150,250);
       motorStart(2, MOTOR_DIR_FORWARD);    
       setSpeed(1, 255);  
       motorStart(1, MOTOR_DIR_BACKWARD);        
       setSpeed(2, 255);  
       delay(2);
       }
  
    if (Sensor2Data < 300){ 
       int v2 = map(Sensor1Data,0,300,250,150); 
       motorStart(2, MOTOR_DIR_BACKWARD);     
       setSpeed(1, 255);  
       motorStart(1, MOTOR_DIR_FORWARD);        
       setSpeed(2, 255);
       delay(2); 
       }
     }
//End controling the motors 
//cabezamovil();
 memset( Sensor1CharMsg, 0, sizeof( Sensor1CharMsg));// This line is for reset the Sensor1CharMsg
}

Son dos paginas

void setSpeed(char motor_num, char motor_speed)  
{  
   if (motor_num == 1)  
   {  
      analogWrite(MOTOR1_PWM, motor_speed);  
   }     
   else  
   {  
      analogWrite(MOTOR2_PWM, motor_speed);  
   }  
}  
  
void motorStart(char motor_num, byte direction)  
{  
    
   char pin_ctl1;  
   char pin_ctl2;  
     
   if (motor_num == 1)  
   {  
      pin_ctl1 = MOTOR1_CTL1;  
      pin_ctl2 = MOTOR1_CTL2;  
   }     
   else  
   {  
      pin_ctl1 = MOTOR2_CTL1;  
      pin_ctl2 = MOTOR2_CTL2;       
   }  
    
   switch (direction)  
   {  
     case MOTOR_DIR_FORWARD:  
     {  
       digitalWrite(pin_ctl1,LOW);  
       digitalWrite(pin_ctl2,HIGH);            
     }  
     break;   
            
     case MOTOR_DIR_BACKWARD:  
     {  
        digitalWrite(pin_ctl1,HIGH);  
        digitalWrite(pin_ctl2,LOW);            
     }  
     break;           
   }  
}  
  
void motorStop(char motor_num)  
{  
   setSpeed(motor_num, 0);  
   if (motor_num == 1)  
   {  
     digitalWrite(MOTOR1_CTL1,HIGH);  
     digitalWrite(MOTOR1_CTL2,HIGH);       
   }  
   else  
   {  
     digitalWrite(MOTOR2_CTL1,HIGH);  
     digitalWrite(MOTOR2_CTL2,HIGH);       
   }  
}  ]

Espero que me podais ayudar, creo que he incluido toda la información posible si necesitáis mas pedirla

He cambiado una linea de codigo en la libreria y he reducido el error ha esto:

C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp: In function 'void __vector_15()':
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:35: error: 'LOW' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:35: error: 'digitalWrite' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:42: error: 'HIGH' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:42: error: 'digitalWrite' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp: In member function 'uint8_t ServoTimer2::attach(int)':
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:65: error: 'OUTPUT' was not declared in this scope
C:\Archivos de programa\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:65: error: 'pinMode' was not declared in this scope

Linea original:

#include "WConstants.h"

Linea modificada:

#include <WConstants.h>

Como parece que todos lso errores estan relacionados con ServoTimer2.ccp añado el archivo aqui por si sirve de ayuda

extern "C" {
  // AVR LibC Includes
  #include <inttypes.h>
  #include <avr/interrupt.h>
  #include <WConstants.h>
}
#include <wiring.h>
#include <ServoTimer2.h>
static void initISR();   
static void writeChan(uint8_t chan, int pulsewidth);

#define FRAME_SYNC_INDEX   0		 // frame sync delay is the first entry in the channel array
#define FRAME_SYNC_PERIOD  20000	   // total frame duration in microseconds 
#define FRAME_SYNC_DELAY   ((FRAME_SYNC_PERIOD - ( NBR_CHANNELS * DEFAULT_PULSE_WIDTH))/ 128) // number of iterations of the ISR to get the desired frame rate
#define DELAY_ADJUST	 8		 // number of microseconds of calculation overhead to be subtracted from pulse timings   

static servo_t servos[NBR_CHANNELS+1];    // static array holding servo data for all channels

static volatile uint8_t Channel;   // counter holding the channel being pulsed
static volatile uint8_t ISRCount;  // iteration counter used in the interrupt routines;
uint8_t ChannelCount = 0;	    // counter holding the number of attached channels
static boolean isStarted = false;  // flag to indicate if the ISR has been initialised

ISR (TIMER2_OVF_vect)
{ 
  ++ISRCount; // increment the overlflow counter
  if (ISRCount ==  servos[Channel].counter ) // are we on the final iteration for this channel
  {
	TCNT2 =  servos[Channel].remainder;   // yes, set count for overflow after remainder ticks
  }  
  else if(ISRCount >  servos[Channel].counter)  
  {
	// we have finished timing the channel so pulse it low and move on
	if(servos[Channel].Pin.isActive == true)	     // check if activated
	    digitalWrite( servos[Channel].Pin.nbr,LOW); // pulse this channel low if active   

	  Channel++;    // increment to the next channel
	ISRCount = 0; // reset the isr iteration counter 
	TCNT2 = 0;    // reset the clock counter register
	if( (Channel != FRAME_SYNC_INDEX) && (Channel <= NBR_CHANNELS) ){	     // check if we need to pulse this channel    
	    if(servos[Channel].Pin.isActive == true)	   // check if activated
		 digitalWrite( servos[Channel].Pin.nbr,HIGH); // its an active channel so pulse it high   
	}
	else if(Channel > NBR_CHANNELS){ 
	   Channel = 0; // all done so start over		   
	} 
   }  
}

ServoTimer2::ServoTimer2()
{
   if( ChannelCount < NBR_CHANNELS)  
	this->chanIndex = ++ChannelCount;  // assign a channel number to this instance
   else
	this->chanIndex = 0;  // todo	// too many channels, assigning 0 inhibits this instance from functioning 
}

uint8_t ServoTimer2::attach(int pin)
{
	if( isStarted == false)
	 initISR();    
	if(this->chanIndex > 0)  
	{
	 //debug("attaching chan = ", chanIndex);
	 pinMode( pin, OUTPUT) ;  // set servo pin to output
	 servos[this->chanIndex].Pin.nbr = pin;  
	 servos[this->chanIndex].Pin.isActive = true;  
	} 
	return this->chanIndex ;
}

void ServoTimer2::detach()  
{
    servos[this->chanIndex].Pin.isActive = false;  
}

void ServoTimer2::write(int pulsewidth)
{	
   writeChan(this->chanIndex, pulsewidth); // call the static function to store the data for this servo	    
}

int ServoTimer2::read()
{
  unsigned int pulsewidth;
   if( this->chanIndex > 0)
	pulsewidth =  servos[this->chanIndex].counter * 128 + ((255 - servos[this->chanIndex].remainder) / 2) + DELAY_ADJUST ;
   else 
	 pulsewidth  = 0;
   return pulsewidth;   
}
 
boolean ServoTimer2::attached()
{
    return servos[this->chanIndex].Pin.isActive ;
}

static void writeChan(uint8_t chan, int pulsewidth)
{
   // calculate and store the values for the given channel
   if( (chan > 0) && (chan <= NBR_CHANNELS) )   // ensure channel is valid
   { 
	if( pulsewidth < MIN_PULSE_WIDTH )		    // ensure pulse width is valid
	    pulsewidth = MIN_PULSE_WIDTH;
	else if( pulsewidth > MAX_PULSE_WIDTH )
	    pulsewidth = MAX_PULSE_WIDTH;	 
	
	  pulsewidth -=DELAY_ADJUST;			 // subtract the time it takes to process the start and end pulses (mostly from digitalWrite) 
	servos[chan].counter = pulsewidth / 128;	
	servos[chan].remainder = 255 - (2 * (pulsewidth - ( servos[chan].counter * 128)));  // the number of 0.5us ticks for timer overflow	   
   }
}

static void initISR()
{   
	for(uint8_t i=1; i <= NBR_CHANNELS; i++) {  // channels start from 1    
	   writeChan(i, DEFAULT_PULSE_WIDTH);  // store default values	    
	}
	servos[FRAME_SYNC_INDEX].counter = FRAME_SYNC_DELAY;   // store the frame sync period	 

	Channel = 0;  // clear the channel index  
	ISRCount = 0;  // clear the value of the ISR counter;
	
	/* setup for timer 2 */
	TIMSK2 = 0;  // disable interrupts 
	TCCR2A = 0;  // normal counting mode 
	TCCR2B = _BV(CS21); // set prescaler of 8 
	TCNT2 = 0;     // clear the timer2 count 
	TIFR2 = _BV(TOV2);  // clear pending interrupts; 
	TIMSK2 =  _BV(TOIE2) ; // enable the overflow interrupt	  
	  
	isStarted = true;  // flag to indicate this initialisation code has been executed
}

Ya lo he solucionado, no solo tenia que cambiar wconstant por arduino.h si no quitar todo el apartado

extern "C" {
  // AVR LibC Includes
  #include <inttypes.h>
  #include <avr/interrupt.h>
  #include <WConstants.h>
}

y sustiturlo por # include <arduino.h>