Implementing code with ServoEasing

Hello to all.

I would like to insert in my code for the management of two servos the library servoeasing.h . What changes do I have to make to the code to make the library work?

//---- Included Libraries ----//  
#include <Wire.h>                           // I²C library
#include <math.h>                           // trig functions
#include <Adafruit_Sensor.h>                // Base library for sensors
#include <Adafruit_BNO055.h>                // BNO055 specific library
#include <utility/imumaths.h>               // Vector, Matrix, and IMUMath library
#include <servo.h>                          // Standard Servo library

#define BNO055_SAMPLERATE_DELAY_MS (20)     // Set pause between samples

//---- Variable Declaration ----//

boolean debug = true;                       // true/false = extra/no information over serial

int rollPin  = 9;                           // Digital pin for roll
int pitchPin = 10;                          // Digital pin for pitch

float roll, pitch;                     // Variable to hold roll, pitch information

Adafruit_BNO055 bno = Adafruit_BNO055();    // Use object bno to hold information

Servo rollServo;                            // Create servo rollServo
Servo pitchServo;                           // Create servo pitchServo

void setup(void) {

  rollServo.attach(rollPin);                // The rollServo is connected at rollPin
  pitchServo.attach(pitchPin);              // The pitchServo is connected at pitchPin

  Serial.begin(2000000);                     // Create serial connection at 115,000 Baud

  if (!bno.begin())                         // Attempt communication with sensor
  /*{
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
  }*/

  delay(1000);                               // Wait 1 seconds to allow it to initialize
  bno.setExtCrystalUse(true);               // Tell sensor to use external crystal
}

//---- Main Program Loop ----//
void loop() {

  //---- Request Euler Angles from Sensor ----//
  sensors_event_t event;
  bno.getEvent(&event);

 /* if (debug) {                             // If debug is true, send information over serial
    Serial.print("Measured Euler Roll-Pitch");
    Serial.print("\t pitch: "); Serial.print(event.orientation.y, 4); Serial.print("\t");
    Serial.print("\t  roll: "); Serial.print(event.orientation.z, 4); Serial.println();
  }
  */
  /* Remap information from the sensor over the 0° - 180° range of the servo
     The Roll values are between -90° and +90°
     The Pitch values are between -180° and +180°
  */
  int servoRoll =  map(event.orientation.z,  -90, 90, 180, 0);
  int servoPitch = map(event.orientation.y, -90, 90, 0, 180);

  servoRoll = constrain(servoRoll, 45, 135);  //limits roll angle range
  servoPitch = constrain(servoPitch, 70, 115);//limits pitch angle range


 /* if (debug) {                             // If debug is true, send information over serial
    Serial.print("Measured Euler Roll-Pitch");
    Serial.print("\t Pitch Servo: "); Serial.print(servoPitch); Serial.print("\t");
    Serial.print("\t  Roll Servo: "); Serial.print(servoRoll);  Serial.println();
  }
  // If debug is true, send information over serial
  if (debug) {
    Serial.println("Calculated Servo Roll-Pitch");
    Serial.print("\t roll:");  Serial.print(servoRoll, DEC);  Serial.print("\t");
    Serial.print("\t pitch:"); Serial.print(servoPitch, DEC); Serial.print("\t");
  }
  */

  rollServo.write(servoRoll);              // Send mapped value to rollServo
  pitchServo.write(servoPitch);            // Send mapped value to pitchServo

  delay(BNO055_SAMPLERATE_DELAY_MS);       // Wait before rerunning loop
}

Thanks to those who will dedicate a moment of their time to me :wink:

I would start by downloading the library and looking at the examples that come with it.

I've never used it but it looks like you just need to follow the instructions at GitHub - ArminJo/ServoEasing: Arduino library to enable smooth servo movement. That and the examples cover it pretty well.

Give it a try and let us know if you have any problems.

Steve

  if (!bno.begin())                         // Attempt communication with sensor
  /*{
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
  }*/

Welp, that looks like a bug. You might want to append a “;” at the end of “if (!bno.begin())” since you commented out the if statement’s content.

Also, curious, what is your main goal with this project?

blh64:
I would start by downloading the library and looking at the examples that come with it.

Thanks. The examples helped me figure out where I was wrong.

slipstick:
I've never used it but it looks like you just need to follow the instructions at GitHub - ArminJo/ServoEasing: Arduino library to enable smooth servo movement. That and the examples cover it pretty well.

Give it a try and let us know if you have any problems.

Steve

Thank you, the explanation was helpful. I had a compilation problem that I solved by looking at the examples.
The idea was to solve a jitter problem with this library, but the problem is still there.

Servo jitter problems are most often caused by insufficient power or sometimes by servos not powerful enough for the load they're expected to move/hold in place.

What is the project, what servos and how are you powering them?

Steve

slipstick:
Servo jitter problems are most often caused by insufficient power or sometimes by servos not powerful enough for the load they're expected to move/hold in place.

What is the project, what servos and how are you powering them?

Steve

I'm powering them with a dc power supply that can give up to 5 Amps. I've the same problem with a car battery and linear tension regulators (that can give 1,5 amp to each servo).

I've posted the problem in this topic :

Power_Broker:

  if (!bno.begin())                         // Attempt communication with sensor

/{
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
  }
/




Welp, that looks like a bug. You might want to append a ";" at the end of "if (!bno.begin())" since you commented out the if statement's content.

Also, curious, what is your main goal with this project?

I commented out the serial print because I have a problem of jittering on the servos. I have read in a topic, that the problem can be a communication problem due to the timer and interrupts and a possible solution was to comment out the serial print.

I want to stabilize a camera to mount on a motorcycle.

The topic where I posted the problem is this: Jitter problem with the servos managed by Arduino UNO and IMU sensor (BNO055) - Programming Questions - Arduino Forum

Hello, everyone! I wanted to tell you that I managed to solve the problem of jitter. To do this I replaced the servo.h library with the "Adafruit_TiCoServo.h" library found on the "The TiCoServo Library | Using NeoPixels and Servos Together | Adafruit Learning System" page. This library controls servos (only on certain pins) without being influenced by an i2c bus (I tested it out and it works perfectly).

Thank you very much to all for your advice, greetings from Switzerland :wink:

Just for interest where did you get your original library? The standard Arduino library for servos is Servo.h (note the capital S). I can't compile your code because of that.

Steve