Hey all, I have read through lots of posts on this subject, so I am pretty sure my issue is unique, please bear with me while you read. Thanks.
I am trying to control 12 servos. The code is posted below. For simplicity of reading, I kept everything in the setup loop. Here is what I am trying to do:
I have built a snake robot with 12 servos. I want it to change shape into an oval. It does that just fine. Then I want to change the angle of each servo so that the oval can roll. That is the problem, it won't move, it just sort of opens fast, and changes one of the servo angle in step 2, from 70 to 90.
Any thoughts on how to fix this? Thanks in advance for your help. I don't want to write it line by line, that is why I am using for loops. Note: The Const Byte Pos_F1 through Pos_F12, the angles are different so it will complete a full revolution. Here is the code.
#include <Servo.h>
// Define servo objects for the snake segments
Servo s[12]; // create servo object to control a servo
int servos[12];
const byte servoPins[] = {2,3,4,5,6,7,8,9,10,11,12,13};
// Define variables
int servo_speed = 1;
int pos = 0;
int test_pos = 90; // Loop counter
int servo_count = 13;
int servo_start_num = 0;
int servo_num = 0;
int roll_start_pos = 90;
int serpentine_start_pos = 90;
int rect_start_pos = 90;
int servo_delay = 150;
// Roll Motion 2.0 Variables
// {0 ,1 ,2 ,3 , 4, 5, 6 ,7 ,8 , 9 ,10, 11};
//const byte pos_f0[]={90,90,90,90,90,90,90,90,90,90,90,90};
const byte pos_f1[] = {90,90,155,35,155,90,90,90,155,35,155,90};//odd=35, even=150
const byte pos_f2[] = {90,90,90,35,150,35,90,90,90,35,150,70};//offset 1
const byte pos_f3[] = {150,90,90,90,150,35,150,90,90,90,150,35};//offset 2
const byte pos_f4[] = {150,35,90,90,90,35,150,35,90,90,90,35};//offset 3
const byte pos_f5[] = {150,35,150,90,90,90,150,35,150,90,90,90};//offset 4
const byte pos_f6[] = {90,35,150,35,90,90,90,35,150,35,90,90};//offset 5
const byte pos_f7[] = {90,90,150,35,150,90,90,90,150,35,150,90};//offset 6
const byte pos_f8[] = {90,90,90,35,150,35,90,90,90,35,150,35};//offset 7
const byte pos_f9[] = {150,90,90,90,150,35,150,90,90,90,150,35};//offset 8
const byte pos_f10[] = {150,35,90,90,90,35,150,35,90,90,90,35};//offset 9
const byte pos_f11[] = {150,35,150,90,90,90,150,35,150,90,90,90};//offset 10
const byte pos_f12[] = {90,35,150,35,90,90,90,35,150,35,90,90};//offset 11<--
void setup() {
Serial.begin(115200);
for(servo_num = servo_start_num; servo_num < servo_count; servo_num++){
s[servo_num].attach(servoPins[servo_num]);
Serial.println(servoPins[servo_num]);
delay (servo_delay);
}
delay(500);
servo_num = 0;
for(servo_num = 0; servo_num < 13; servo_num++){
delay (servo_delay);
s[servo_num].write(pos_f1[servo_num]);
Serial.println(pos_f1[servo_num]);
}
delay(500);
servo_num = 0;
for(servo_num = 0; servo_num < 13; servo_num++){
delay (servo_delay);
s[servo_num].write(pos_f2[servo_num]);
Serial.println(pos_f2[servo_num]);
}
}
void loop() {
}