ServoTimer2.h boolean deceleration error

Hi guys,
I’m a newbie in this field.
I’m using ServoTimer.h library to control servo motors(I cannot use Standard Servo.h for some reason).
I made a plane sketch included ServoTimer2.h which looks like this.

#include <ServoTimer2.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

It gives me this error.

Arduino: 1.6.3 (Windows 7), Board: “Arduino Uno”

In file included from sketch_apr10a.ino:3:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: conflicting declaration ‘typedef bool boolean’

typedef bool boolean;

^

In file included from sketch_apr10a.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\ServoTimer2/ServoTimer2.h:41:17: error: ‘boolean’ has a previous declaration as ‘typedef uint8_t boolean’

typedef uint8_t boolean;

^

Error compiling.

Here is the ServoTimer2.h code.

/*
 ServoTimer2.h - Interrupt driven Servo library for Arduino using 
/* 
 This library uses Timer2 to drive up to 8 servos using interrupts so no refresh activity is required from within the sketch. 
 The usage and method naming is similar to the Arduino software servo library http://www.arduino.cc/playground/ComponentLib/Servo
 except that pulse widths are in microseconds.

 
 A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
 The servo is pulsed in the background to the value most recently written using the write() method

 Note that analogWrite of PWM on pins 3 and 11 is disabled when the first servo is attached

 The methods are:

  ServoTimer2 - 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 pulse width in microseconds.

  read()      - Gets the last written servo pulse width in microseconds. 

  attached()  - Returns true if there is a servo attached. 

  detach()    - Stops an attached servos from pulsing its i/o pin. 
 

The library takes about 824 bytes of program memory and 32+(1*servos) bytes of SRAM. 
The pulse width timing is accurate to within 1%

*/

// ensure this library description is only included once
#ifndef ServoTimer2_h
#define ServoTimer2_h

#include <inttypes.h>
typedef uint8_t boolean;
typedef uint8_t byte;

#define MIN_PULSE_WIDTH       750        // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2250        // the longest pulse sent to a servo 
#define DEFAULT_PULSE_WIDTH  1500        // default pulse width when servo is attached
#define FRAME_SYNC_PERIOD   20000        // total frame duration in microseconds 
#define NBR_CHANNELS 8                   // the maximum number of channels, don't change this 

typedef struct  {
     uint8_t nbr        :5 ;  // a pin number from 0 to 31
     uint8_t isActive   :1 ;  // false if this channel not enabled, pin only pulsed if true 
  } ServoPin_t   ;  

typedef struct {
 ServoPin_t Pin;
 byte counter;
 byte remainder;
}  servo_t;

class ServoTimer2
{
 public:
     // constructor:
     ServoTimer2();

     uint8_t attach(int);     // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
                              // the attached servo is pulsed with the current pulse width value, (see the write method) 
     uint8_t attach(int, int, int); // as above but also sets min and max values for writes. 
   void detach();
   void write(int);         // store the pulse width in microseconds (between MIN_PULSE_WIDTH and MAX_PULSE_WIDTH)for this channel
   int read();                    // returns current pulse width in microseconds for this servo
     boolean attached();      // return true if this servo is attached 
private:
      uint8_t chanIndex;      // index into the channel data for this servo

};


// the following ServoArrayT2 class is not implemented in the first version of this library
class ServoArrayT2
{
 public:
     // constructor:
     ServoArrayT2();

     uint8_t attach(int);     // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
                              // channels are assigned consecutively starting from 1
                              // the attached servo is pulsed with the current pulse width value, (see the write method) 
   void detach(int);        // detach the servo on the given channel
     void write(int,int);     // store the pulse width in microseconds (between MIN_PULSE_WIDTH and MAX_PULSE_WIDTH)for the given channel
   int read(int);                    // returns current pulse width in microseconds for the given channel
     boolean attached(int);   // return true if the servo on the given channel is attached 
private:
      uint8_t chanIndex;      // index into the channel data for this servo

};

#endif

Please help.
Thanks

This seems to an "improvement" included in IDE 1.6.3.

I don't know what the solution is, apart from using an earlier version of the IDE. I'm still using 1.5.6

...R

Just take the offending typedef out of ServoTimer2.h for now - if you understand conditional compilation with #ifdefs then you can do a proper job and make the typedef conditional on the Arduino version.

Mark T, I don't know how to do that. I'm fresh and new in this feild :disappointed_relieved: :disappointed_relieved: :disappointed_relieved:

You can edit a sketch?

Then you do the same, but to the library source.

You know where you put the library, so go there and edit it... Just comment out the typedef line with leading "//"

You know where you put the library, so go there and edit it... Just comment out the typedef line with leading "//"

Done..

now these error

Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

In file included from sketch_apr12a.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\ServoTimer2/ServoTimer2.h:73:6: error: 'boolean' does not name a type

      boolean attached();      // return true if this servo is attached 

      ^

C:\Program Files (x86)\Arduino\libraries\ServoTimer2/ServoTimer2.h:93:6: error: 'boolean' does not name a type

      boolean attached(int);   // return true if the servo on the given channel is attached 

      ^

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Read through this for the solution: http://forum.arduino.cc/index.php?topic=303063.new#new

Found a easy solution for this Problem. I will post it within 4 days. Because I have to present my project in a exhibition nest 3 days.

No rush. You are already over 12 months late for this party :)

...R

I’m having the same problem here and commenting out that boolean only made the code compile but it does not work. The program ends up sending a constant servo signal even varying the variable for the pulse lenght.

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

int Sensor1Data;  // Pots
int Sensor2Data;  // Pots
char StringReceived[10];
byte val;
#define rollPin  7

ServoTimer2 servoRoll;

void setup() {
  Serial.begin(9600); //Debuging
  vw_setup(2000);  // Bits per sec
  vw_set_rx_pin(11);
  vw_rx_start();
  servoRoll.attach(rollPin); 
  delay(15);
} // END 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;
    for (i = 0; i < buflen; i++) // Message with a good checksum received, dump it.
    {
      StringReceived[i] = char(buf[i]); // Fill Sensor1CharMsg Char array with corresponding chars from buffer.
    }
    sscanf(StringReceived, "%d,%d", &Sensor1Data, &Sensor2Data); // Converts a string to an array
    Serial.print(Sensor2Data);
    Serial.println(Sensor1Data);
    val = map(Sensor1Data, 0, 1023, 0, 180);
    servoRoll.write(val);
    Serial.println(val);
  }
  memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}

In file included from C:\Users\CAIOPO~1\AppData\Local\Temp\arduino_modified_sketch_442735\RC_receiver.ino:3:0:

C:\Users\Caio Poit\Documents\Arduino\libraries\ServoTimer2-master/ServoTimer2.h:76:17: error: conflicting declaration ‘typedef uint8_t boolean’

typedef uint8_t boolean; // I COMMENTED OUT TO MAKE IT COMPILE YOLO
^

In file included from sketch\RC_receiver.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:125:14: note: previous declaration as ‘typedef bool boolean’

typedef bool boolean;

^

exit status 1
Error compiling for board Arduino Nano.

caiopoit: I'm having the same problem here and commenting out that boolean only made the code compile but it does not work

Write a short program that just uses the ServoTimer2 library and makes your servo move with (say) myServo.write(1500); and if it does not work post the program. Don't have any other stuff in the program.

...R

short program that just uses the ServoTimer2 library and makes your servo move with (say) myServo.write(1500)

It is working this way, thanks.

#include <ServoTimer2.h>  // the servo library

// define the pins for the servos
#define rollPin  2


ServoTimer2 servoRoll;    // declare variables for up to eight servos

 
void setup() {
  servoRoll.attach(rollPin);     // attach a pin to the servos and they will start pulsing
}


// this function just increments a value until it reaches a maximum 
int incPulse(int val, int inc){
   if( val + inc  > 2000 )
      return 1000 ;
   else
       return val + inc;  
}

void loop()
{ 
 int val;
  
   val = incPulse( servoRoll.read(), 1);
   servoRoll.write(val);
   
   delay(10);   
}

Hello.
I have this problem too.
Sorry, but reading this I could not figure out what the solution is, nor do I apply it to my case.
My goal is to use a Rf433Mhz to control 2 servo from a distance (preferably using only 2 arduinos)

I found this Simonexc code that seems to be what I need, but I can not compile it !!!

//"

/*
This code receive data from the transmitter and control
all servos and ESC in your RC plane.

Author: Simon “Simonexc” Trochimiak
10 May 2016
*/
#include <ServoTimer2.h> // the servo library

// define the pins for the servos
#define rollPin 2

ServoTimer2 servoRoll; // declare variables for up to eight servos

void setup() {
servoRoll.attach(rollPin); // attach a pin to the servos and they will start pulsing
}

// this function just increments a value until it reaches a maximum
int incPulse(int val, int inc){
if( val + inc > 2000 )
return 1000 ;
else
return val + inc;
}

void loop()
{
int val;

val = incPulse( servoRoll.read(), 1);
servoRoll.write(val);

delay(10);
}

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

// create servo objects
ServoTimer2 leftAileron;
ServoTimer2 rightAileron;
ServoTimer2 rudder;
ServoTimer2 elevator;

// create servo object to control ESC
ServoTimer2 ESC;

// servo pins
#define LEFT_AILERON_PIN 11
#define RIGHT_AILERON_PIN 10
#define RUDDER_PIN 9
#define ELEVATOR_PIN 6
// ESC pin
#define ESC_PIN 5

// receiver pin
#define RECEIVE_PIN 12

// variables to control servos
#define ACCURACY 21
#define MAX_TIME_WITHOUT_CONTACT 500 // in ms
#define DELAY 150

// pulse to ESC
#define LOWEST_PULSE_FOR_MOTOR 1000
#define HIGHEST_PULSE_FOR_MOTOR 2000

// variable which stores power of motor
int power = 0;
// variable which stores moves in each direction
int yaw = ACCURACY/2;
int pitch = ACCURACY/2;
int roll = ACCURACY/2;

// when was the last contact with the transmitter
unsigned long last_contact = 0;

// changes degrees to microseconds
int degToMic(int deg) {
return map(deg, 0, 180, 544, 2400);
}

// changes microseconds to degrees
int micToDeg(int mic) {
return map(mic, 544, 2400, 0, 180);
}

void moveServo() { // moves all servos

int act; // actual position of servo
int deg = {0, 0, 0, 0};
boolean change = false; // if there was any change

act = micToDeg(leftAileron.read()); // read servo position
deg[0] = map(roll, 0, ACCURACY-1, 60, 110);

if (act > deg[0] && act-deg[0] > 2) {
leftAileron.write(degToMic(deg[0]-5));
change = true;
}
else if (act < deg[0] && deg[0]-act > 2) {
leftAileron.write(degToMic(deg[0]+5));
change = true;
}

act = micToDeg(rightAileron.read()); // read servo position
deg[1] = map(roll, 0, ACCURACY-1, 60, 110);

if (act > deg[1] && act-deg[1] > 2) {
rightAileron.write(degToMic(deg[1]-5));
change = true;
}
else if (act < deg[1] && deg[1]-act > 2) {
rightAileron.write(degToMic(deg[1]+5));
change = true;
}

act = micToDeg(rudder.read()); // read servo position
deg[2] = map(yaw, 0, ACCURACY-1, 60, 140);

if (act > deg[2] && act-deg[2] > 2) {
rudder.write(degToMic(deg[2]-5));
change = true;
}
else if (act < deg[2] && deg[2]-act > 2) {
rudder.write(degToMic(deg[2]+5));
change = true;
}

act = micToDeg(elevator.read()); // read servo position
deg[3] = map(pitch, 0, ACCURACY-1, 70, 110);

if (act > deg[3] && act-deg[3] > 2) {
elevator.write(degToMic(deg[3]-5));
change = true;
}
else if (act < deg[3] && deg[3]-act > 2) {
elevator.write(degToMic(deg[3]+5));
change = true;
}

if (change) { // if there was change
delay(DELAY);
// move each servo to their right position
leftAileron.write(degToMic(deg[0]));
rightAileron.write(degToMic(deg[1]));
rudder.write(degToMic(deg[2]));
elevator.write(degToMic(deg[3]));
}
// set power of the motor
ESC.write(map(power, 0, ACCURACY-1, LOWEST_PULSE_FOR_MOTOR, HIGHEST_PULSE_FOR_MOTOR));

}

void setup() {

// attach servo and ESC to proper pins
leftAileron.attach(LEFT_AILERON_PIN);
rightAileron.attach(RIGHT_AILERON_PIN);
rudder.attach(RUDDER_PIN);
elevator.attach(ELEVATOR_PIN);
ESC.attach(ESC_PIN);

// setting receiver
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(RECEIVE_PIN);
vw_setup(7000); // Bits per sec

vw_rx_start(); // Start the receiver PLL running

//Serial.begin(9600);

moveServo();

}

void loop() {

// read message from transmitter
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) { // if receiver received data

if (buf[0] < ACCURACY) {
power = buf[0];
}
else if (buf[0] < 2ACCURACY) {
yaw = buf[0] - ACCURACY;
}
else if (buf[0] < 3
ACCURACY) {
pitch = char(buf[0]) - 2ACCURACY;
}
else {
roll = char(buf[0]) - 3
ACCURACY;
}

last_contact = millis();

moveServo();

}

// if there was no contact with transmitter for a long time turn off motor and set servos to their neutral positons
else if (millis() - last_contact > MAX_TIME_WITHOUT_CONTACT) {
power = 0;
yaw = ACCURACY/2;
pitch = ACCURACY/2;
roll = ACCURACY/2;

moveServo();
}

}
//"

Can you please help me to repair this code?
What should I do?
Alternatively, if I got a code that would do the same and work it was great.
Basically: I just need to transmit via Rf 433Mhz to 2 servo, I do not need some things from that code.

CDIcomics:
Can you please help me to repair this code?

First you need to modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

Alternatively, if I got a code that would do the same and work it was great.
Basically: I just need to transmit via Rf 433Mhz to 2 servo, I do not need some things from that code.

We will help you if you have problems writing your own program. If you want someone to write code for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

Assuming you want to do it yourself, break your learning into two parts. Write a short program to learn how to move servos. And write another short program (or pair of programs) to learn how to send and receive data by wireless. You will find dozens of online examples for both.

…R