FlexiTimer giving errors in servo motion

I am working on a quadruped bot, spiderbot and I am trying to make a creep gait using Forward kinematics however, for some reason my code stops working after the execution of the line -

[pwm.setPWM(ffr,0,angleToPulse(30));]

Please help me out here.

#include<Adafruit_PWMServoDriver.h>
#include<Wire.h>
#include <FlexiTimer2.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN 125
#define SERVOMAX 575
int i=1,a,angle;



#define cfr 0
#define ffr 1
#define tfr 2
#define cfl 4
#define ffl 5
#define tfl 6
#define cbr 8
#define fbr 9
#define tbr 10
#define cbl 12
#define fbl 13
#define tbl 14
#define delayc 500
#define delayc1 20
#define delayc2 100


void setup()
{
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);


  FlexiTimer2::set(20, servo_timer);
  FlexiTimer2::start();

  **pwm.setPWM(ffr,0,angleToPulse(30));**
  delay(delayc2);

  pwm.setPWM(tfr,0,angleToPulse(150));
  delay(delayc2);

  pwm.setPWM(cfr,0,angleToPulse(170));
  delay(delayc2);

  pwm.setPWM(tfr,0,angleToPulse(90));
  delay(delayc2);

  pwm.setPWM(ffr,0,angleToPulse(90));
  delay(delayc2);


}

void loop()
{
  Serial.print("hi");

}

int angleToPulse(int ang)
{
   int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);// map angle of 0 to 180 to Servo min and Servo max 
   return pulse;
}

void servo_timer()
{  
  pwm.setPWM(cbl,0,angleToPulse(150));


  pwm.setPWM(tbl,0,angleToPulse(90));


  pwm.setPWM(fbl,0,angleToPulse(100));


  pwm.setPWM(cfl,0,angleToPulse(60));


  pwm.setPWM(tfl,0,angleToPulse(100));


  pwm.setPWM(ffl,0,angleToPulse(100));


  pwm.setPWM(tbr,0,angleToPulse(100));


  pwm.setPWM(fbr,0,angleToPulse(90));


  pwm.setPWM(cbr,0,angleToPulse(115));


}
  1. The reason I am using the flexitimer function is to update all the other servos,give them a nearly continuous pulse, to make them stay in position while on of the leg moves to execute forward motion.Otherwise they tend to not stay rigid.

2.Please ignore the Serial.print(“hi”); in the loop, I just put that to not leave the loop empty.

#define cfr 0
#define ffr 1

Have you got servos attached to pins 0 and 1 ?

I think those will be servo positions 0 and 1 on the Adafruit PCA9685 driver that, from the code, it looks like he may be using in which case that would be fine. But we really do need a lot more information since we know nothing at all about the hardware being used.

But what makes you think the code stops working rather than say the servos aren't working? I can't see any Serial.prints that would tell you where it's getting to in the code.

Steve

Sorry for the common reply, I dont know how to reply to individual messages here.

@UKHeliBOB

No I am using an adafruit PCA 9685

@slipstick

1.<error> line 1 word 23 : The user happens to be a she :slight_smile:

2.So the hardware, there are 12 servos attached to a PCA9685 Board, the PCA9685 is connected to an Arduino Nano, All the connections are proper, i have individually checked them. And all the servos as well as this code works when I remove the Flexitimer line. I also used serial prints to check, removed them from this code before posting.

The reason i am using Flexitimer is, when one of the legs of the bot is moving (each leg would have three servos)
I want the other servos to get continuous pulse so that they stay rigid and the bot stays upright.