0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.