Voici le code pour faire fonctionner les vérins.

3 actuators code (bêta):

// Stepper microstepping settings :  ????
// M1 is at the front right, M2 at the rear and M3 at the front left
// v1.0 bêta

// WIRING
#define StepPin1  2 //Step or pulse pin, check how DirectionManager is written.
#define DirPin1   3
#define StepPin2  4
#define DirPin2   5
#define StepPin3  6
#define DirPin3   7


#define outPutRange 15
#define microStepping 3200
#define precision  32767  //set 15 in "bitouput" in FlyPT
#define totalStep 36500   //number of pulse to go from 0 to max travel put 9060
#define refreshRate 300      //500

#define  numAccelSteps  14 // 100 is a half turn of a 200 step mmotor
#define  slowMicrosBetweenSteps  17 //20 microseconds
#define  fastMicrosBetweenSteps  3 //5
#define directionDelay 5  //10
unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long stepIntervalMicros;
unsigned long stepAdjustmentMicros;
unsigned long int x=0, y=0, z=0;
byte buffer           =  0 ;    // It takes the value of the serial data
int buffercount      = -1 ;    // To count where we are in the serial datas
byte commandbuffer[6] = {0};     // To count where we are in the serial datas





  // To stock the serial datas in the good order.

unsigned long int m1Target=0, m2Target=0, m3Target = 0; // The pitch and roll positions we want to reach
unsigned long int m1Position = 0, m2Position = 0, m3Position = 0;
int long m1stepsToGo=0;
int long m2stepsToGo=0;
int long m3stepsToGo=0;


int  dir1 = 1, dir2 = 1, dir3 = 1;         //Will be used to set the motors direction
byte dirChange = 0;
int c=0;

void setup() {
  Serial.begin(115200);    //To communicate with FlyPT
  
  pinMode(StepPin1, OUTPUT);
  pinMode(DirPin1, OUTPUT);
  digitalWrite(DirPin1,HIGH);
  
  pinMode(StepPin2, OUTPUT);
  pinMode(DirPin2, OUTPUT);
  digitalWrite(DirPin2,HIGH);
  
  pinMode(StepPin3, OUTPUT);
  pinMode(DirPin3, OUTPUT);
  digitalWrite(DirPin3,HIGH);
  
  stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
  stepIntervalMicros = slowMicrosBetweenSteps;
}

void loop() {
  SerialReader();                     //Get the datas from Simtools
  CommandWorker();                      //Convert the targets into pulse number
  moveMotor();
}

void CommandWorker() {
m1stepsToGo = m1Target - m1Position; 
m2stepsToGo = m2Target - m2Position;
m3stepsToGo = m3Target - m3Position;
  }

void SerialReader() {       // This function is the work of Sirnoname. Simtools output : P<Axis1a><Axis2a>, Data bits : 10 bits, Parity : None, stop bits : 1
  while (Serial.available())
    {
      if (buffercount == -1)
      {
        buffer = Serial.read();
        if (buffer != 'P') {
          buffercount = -1; // "P" is the marquer. If we read P, the next data is pitch
        } else {
          buffercount = 0;
        }
      }
      else   //  if(buffercount>=0)
      {
        buffer = Serial.read();
        commandbuffer[buffercount] = buffer; // The first value next to "P" is saved in commandbuffer in the place "buffercount"
        buffercount++;
        if (buffercount > 5){
            m1Target = map((commandbuffer[0]) * 256 + commandbuffer[1], 0, precision, 0, totalStep);
            m2Target = map((commandbuffer[2]) * 256 + commandbuffer[3], 0, precision, 0, totalStep);
            m3Target = map((commandbuffer[4]) * 256 + commandbuffer[5], 0, precision, 0, totalStep);
            buffercount = -1;
           break;
        }
      }
    }
  }
  
void directionManager() {
  if ((m1stepsToGo < 0) && (dir1 == 1)) {
    digitalWrite(DirPin1, LOW);
    dir1 = -1;
    dirChange = 1;
  }

  if ((m1stepsToGo > 0) && (dir1 == -1)) {
    digitalWrite(DirPin1, HIGH);
    dir1 = 1;
    dirChange = 1;
  }

  if ((m2stepsToGo < 0) && (dir2 == 1)) {
    digitalWrite(DirPin2, LOW);
    dir2 = -1;
    dirChange = 1;

  }

  if ((m2stepsToGo > 0) && (dir2 == -1)) {
    digitalWrite(DirPin2, HIGH);
    dir2 = 1;
    dirChange = 1;
  }
  
    if ((m3stepsToGo < 0) && (dir3 == 1)) {
    digitalWrite(DirPin3, LOW);
    dir3 = -1;
    dirChange = 1;

  }

  if ((m3stepsToGo > 0) && (dir3 == -1)) {
    digitalWrite(DirPin3, HIGH);
    dir3 = 1;
    dirChange = 1;
  }

  if (dirChange == 1) {
    delayMicroseconds(directionDelay);
    dirChange = 0;
  }

}

void moveMotor() {
  x = abs(m1stepsToGo);
  y = abs(m2stepsToGo);
  z = abs(m3stepsToGo);
  directionManager();
  prevStepMicros = micros();
  while ((max(x,max(y,z)) > 0) && (c<refreshRate)) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
      prevStepMicros += stepIntervalMicros;
      singleStep();
      
      if (max(x,max(y,z)) <= numAccelSteps) {
        if (stepIntervalMicros < slowMicrosBetweenSteps) {
          stepIntervalMicros += stepAdjustmentMicros;
        }
      }
      else {
        if (stepIntervalMicros > fastMicrosBetweenSteps) {
          stepIntervalMicros -= stepAdjustmentMicros;
        }
      }
    }
  }
  c=0;
}

void singleStep() {
  if ((x > 0) && (y>0) && (z>0)) {
    digitalWrite(StepPin1, HIGH);
    digitalWrite(StepPin2, HIGH);
    digitalWrite(StepPin3, HIGH);
    digitalWrite(StepPin1, LOW);
    digitalWrite(StepPin2, LOW);
    digitalWrite(StepPin3, LOW);
    m1Position += dir1;
    m2Position += dir2;
    m3Position += dir3;
    x--;
    y--;
    z--;
    c++;
  }
  else{
    if(x>0){
      digitalWrite(StepPin1, HIGH);
      digitalWrite(StepPin1, LOW);
      m1Position += dir1;
      x--;
      c++;
    }
    if(y>0){
      digitalWrite(StepPin2, HIGH);
      digitalWrite(StepPin2, LOW);
      m2Position += dir2;
      y--;
      c++;
    }
    if(z>0){
      digitalWrite(StepPin3, HIGH);
      digitalWrite(StepPin3, LOW);
      m3Position += dir3;
      z--;
      c++;
    }
  }
}