Stewart platform programming

Hello,
I am working on putting together a Stewart Platform for a school project but am having trouble with the programming. I have a platform with six mini linear actuators. Each has its own motor controller that takes in a servo signal from an arduino. I would like to be able to record up to one minute of movements from a second platform I have outfitted with six slide potentiometers.(think custom joystick) I then would like to replay these movements on demand on the motorized platform. I have found this sketch, that I have attached below, by Adi Soffer that works for one servo but I would like to expand this to work for all six actuators and have a longer record time. I unfortunately have not experience programming and no clue where to start. Any pointers or links to software that would do this would be appreciated.

Servo_REC_PLYBK.ino (3.47 KB)

Look at the record function, it gets a value from one pot and stores it’s value in an array, what you need to do is add in 5 more pots and use a 2D array like servoPos[6][300]. 6 elements total (pots), with 300 indexes each. If your stuck on how arrays work then look at the example provided in the arduino software. Examples → 05.Control → Arrays

void recordFunction ( )
{
Serial.println (“Record function”); // if so - prints record
delay(15);
for (int i=0;i<299;i++) //for loop to store 300 values of pot
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 44, 134); // scale it to use it with the servo (value between 0 and 180) ??? this statement is false
myservo.write(val); // sets the servo position according to the scaled value
servoPos [ i ]=val; // stores val in array "servoPos
delay(15); // waits for the servo to get there
Serial.println(val); // print values for checking
}
}

You have issues with storage if you are going to store all that data in RAM. This will affect your choice of board, or perhaps mean finding a different way to store the data (CSV file on an SDcard perhaps?

External EEPROM I2C chips might be another way. You need to consider ease of interfacing, speed of writes.

@MarkT Well if he wants he can change the code to record say 60 movements (1 move per second), instead of 300. This will decrease the amount of ram used, significantly! He'll just need a timer and for that can use the millis function.

@HazardsMind-
I took a stab at arrays with no luck. I have stepped back to just trying to write a script to get the servos to move when the corresponding pot is moved just to help get my head around arrays. (see attached script) I have a feeling I am missing the boat.

@MarkT &HazardsMind
I am going to want smooth continuous motion. I am planning on using a SD Sheild to store the data but for know I think 1 move per second would work. I am trying to take baby steps so that I understand each step of the process and not deal with writing code to write/read from SD card right know. I will get there soon though, fingers crossed.

Six_Axis_Array.ino (830 Bytes)

This is how to post code (use the # button):

#include <Servo.h>  // the servo library

#define SERVOS 6 // the number of servos
int servoPins[SERVOS] = {2, 3, 4, 5, 6, 7}; // servos on pins 2 through 7
int potpin[6] = {0, 1, 2, 3, 4, 5};  // six pots on pins 0 through 5
int val[6] = {0, 1, 2, 3, 4, 5};  // six variable to read the value from analog pins 0 through 5
Servo myservo[SERVOS];

void setup()
{
  Serial.begin(9600); // start serial communication
  for(int i=0; i < SERVOS; i++)
    myservo[i].attach(servoPins[i]); // attach servo to pin
}
 void loop()
 {
   val[6]= analogRead(potpin[6]); // reads the value of the potentiometer (value between 0 and 1023)
   val[6] = map(val[6], 0, 1023, 44, 135); // scale it to use it with the servo (value between 44 and 134)
   myservo[SERVOS].write(val[6]); // sets the servo position according to the scaled value 
 }

You’re getting there - the code in loop needs a for-loop to iterate over the 6 channels,
and all the arrays should declare their size in terms of the SERVOS #define, so its consistent
and self-documenting.

@MarkT - Thanks for the posting tip.

I am assuming this is what you mean about the loop.

void loop()
 {
   for(potpin[6] = 0; potpin[6] < 8; potpin[6]++) {
   val[6]= analogRead(potpin[6]); // reads the value of the potentiometer (value between 0 and 1023)
   val[6] = map(val[6], 0, 1023, 44, 135); // scale it to use it with the servo (value between 44 and 134)
   myservo[SERVOS].write(val[6]); // sets the servo position according to the scaled value 
   }
 }

However, I am not sure what you mean about

all the arrays should declare their size in terms of the SERVOS #define, so its consistent
and self-documenting.

Are you saying that the size has already been declared and I don’t need the " [6] " statements after potpin and val, or are you saying that I need to write something after the SERVO 6?