Hey everyone, really new to Arduino here and I've been trying to do this project linked here:
I've made it to Step 10 but it's not working properly. I have 2 problems: 1. the motors are not spinning to 90 degrees and instead go a full 4 rotations before stopping and then continuing again. 2. The code seems to be looping every second. See code below:
#include "Quadruped.h"
Quadruped robot(48.302, 91, 15.151, 40, 40);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
robot.init_initialise(); // 8th line.
// robot.initialise();
// delay(100);
// robot.translate_cog_on_support_polygon("rf");
// // delay(1000);
// robot.IK_one_leg("rf", 0,20,10);
// delay(100);
// robot.IK_one_leg("rf", 0,-20,5);
// delay(100);
// robot.translate_cog_on_support_polygon("lb");
// // delay(1000);
// robot.IK_one_leg("lb", 0,20,10);
// delay(100);
// robot.IK_one_leg("lb", 0,-20,5);
// delay(100);
// robot.translate_cog_on_support_polygon("lf");
// // delay(1000);
// robot.IK_one_leg("lf", 0,20,20);
// delay(100);
// robot.IK_one_leg("lf", 0,-20,10);
// delay(100);
// robot.translate_cog_on_support_polygon("rb");
// // delay(1000);
// robot.IK_one_leg("rb", 0,20,20);
// delay(100);
// robot.IK_one_leg("rb", 0,-20,10);
}
void loop() {
// // put your main code here, to run repeatedly:
// delay(100);
// robot.translate_cog_on_support_polygon("rf");
// // delay(1000);
// robot.IK_one_leg("rf", 0,20,20);
// delay(100);
// robot.IK_one_leg("rf", 0,-20,10);
// delay(100);
// robot.translate_cog_on_support_polygon("lb");
// // delay(1000);
// robot.IK_one_leg("lb", 0,20,20);
// delay(100);
// robot.IK_one_leg("lb", 0,-20,10);
// delay(100);
// robot.translate_cog_on_support_polygon("lf");
// // delay(1000);
// robot.IK_one_leg("lf", 0,20,20);
// delay(100);
// robot.IK_one_leg("lf", 0,-20,10);
// delay(100);
// robot.translate_cog_on_support_polygon("rb");
// // delay(1000);
// robot.IK_one_leg("rb", 0,20,20);
// delay(100);
// robot.IK_one_leg("rb", 0,-20,10);
}
the function init_initialize is seen below:
void Quadruped::init_initialise(){
attach_servos();
rfh1.write(zero_positions[0]);
rfh2.write(zero_positions[1]);
rfk.write(zero_positions[2]);
lfh1.write(zero_positions[3]);
lfh2.write(zero_positions[4]);
lfk.write(zero_positions[5]);
rbh1.write(zero_positions[6]);
rbh2.write(zero_positions[7]);
rbk.write(zero_positions[8]);
lbh1.write(zero_positions[9]);
lbh2.write(zero_positions[10]);
lbk.write(zero_positions[11]);
delay(1000); // miliseconds
}
any ideas what might go wrong?
Using Arduino Mega 256, MEGA Sensor Shield V1.3, and MG90S microservos as per instructions on website link.
Any help is greatly appreciated!