About a strange ERROR

i have a program about 6dof motor simulator and now its display some error when compile .

via my check step by step,i can focus on two lines,

it will be pass the compile when i comment one of them;

Two lines code is follow:

r[0][i] =  re[0][i] * cos(pe[4]) * cos(pe[5]) + re[1][i] * (sin(pe[3]) * sin(pe[4]) * cos(pe[5]) - cos(pe[3]) * sin(pe[5])) + re[2][i] * ((cos(pe[3]) * sin(pe[4]) * cos(pe[5])) + sin(pe[3]) * sin(pe[5])) + pe[0];
r[1][i] =  re[0][i] * cos(pe[4]) * sin(pe[5]) + re[1][i] * (cos(pe[3]) * cos(pe[5]) + sin(pe[3]) * sin(pe[4]) * sin(pe[5])) + re[2][i] * ((cos(pe[3]) * sin(pe[4]) * cos(pe[5])) - sin(pe[3]) * cos(pe[5])) + pe[1];

Error report is follow:

_6DOF.ino: In function 'void loop()':
_6DOF:176: error: unable to find a register to spill in class 'POINTER_REGS'
_6DOF:176: error: this is the insn:
(insn 342 341 344 6 (set (reg:SF 139 [ D.4257 ])
(mem:SF (post_inc:HI (reg:HI 233 [ ivtmp.72 ])) [3 MEM[base: _257, offset: 0B]+0 S4 A8])) _6DOF.ino:134 99 {*movsf}
(expr_list:REG_INC (reg:HI 233 [ ivtmp.72 ])
(nil)))
_6DOF.ino:176: confused by earlier errors, bailing out
unable to find a register to spill in class 'POINTER_REGS'

Fully Code :

#include <Servo.h>

const float pi = radians(180), theta_s[] = {  pi, pi, pi / 3, pi / 3, -pi / 3, -pi / 3},
            L1 = 16, L2 = 98.3, z_home = 110.0,
            YPR_max = radians(20), servo_min = radians(-60), servo_max = radians(60), feedback = (1 / 50),
            servo_mult = (1800 / pi), ADC_mult = (YPR_max / 512),

p[2][6] = {{ -52.3993, 50.8007, 90.3895, 39.5875, -38.2649, -90.3679},
  {74.8623, 74.8623, 6.2712, -80.5588, -80.4696, 5.8204}
},

re[3][6] = {{ -12.0000,  12.0000,  70.2820,  58.2820,  -58.2820,  -70.2820},
  {74.2260,  74.2260,  -26.7210,  -47.5060,  -47.5060,  -26.7210},
  { -21.075,  -21.075,  -21.075,   -21.075,   -21.075,   -21.075}
};

const int servo_pin[] = {9, 3, 5, 11, 6, 10},

                        servo_zero[6] = {1500, 1500, 1500, 1500, 1500, 1500};

Servo servo[6];

void setup()
{
  //Serial.begin(9600);
  for (int i = 0; i < 6; i++)
  {
    servo[i].attach(servo_pin[i]);
    servo[i].writeMicroseconds(servo_zero[i]);
  }
  delay(1000);
}

void loop()
{

  static float pe[6] = {0, 0, 0, radians(0), radians(0), radians(0)  }, theta_a[6], servo_pos[6], q[3][6], r[3][6], dl[3][6], dl2[6];

  pe[0] = (analogRead(0) - 512) / 51.2;
  pe[1] = (analogRead(1) - 512) / 51.2;
  pe[2] = (analogRead(2) - 512) / 51.2;
  pe[3] = (analogRead(3) - 512) * ADC_mult;
  pe[4] = (analogRead(4) - 512) * ADC_mult;
  pe[5] = (analogRead(5) - 512) * ADC_mult;

  for (int i = 0; i < 6; i++)
  {
    if (i % 2 == 0)
    { q[0][i] = L1 * cos(-theta_a[i]) * cos(theta_s[i]) + p[0][i]; //EVEN [0,2,4]
      q[1][i] = L1 * cos(-theta_a[i]) * sin(theta_s[i]) + p[1][i];
      q[2][i] = -L1 * sin(-theta_a[i]);
    }
    else
    { q[0][i] = -L1 * cos(theta_a[i]) * cos(theta_s[i]) + p[0][i]; //ODD  [1,3,5]
      q[1][i] = -L1 * cos(theta_a[i]) * sin(theta_s[i]) + p[1][i];
      q[2][i] = L1 * sin(theta_a[i]);
    }

    r[0][i] =  re[0][i] * cos(pe[4]) * cos(pe[5]) + re[1][i] * (sin(pe[3]) * sin(pe[4]) * cos(pe[5]) - cos(pe[3]) * sin(pe[5])) + re[2][i] * ((cos(pe[3]) * sin(pe[4]) * cos(pe[5])) + sin(pe[3]) * sin(pe[5])) + pe[0];
    r[1][i] =  re[0][i] * cos(pe[4]) * sin(pe[5]) + re[1][i] * (cos(pe[3]) * cos(pe[5]) + sin(pe[3]) * sin(pe[4]) * sin(pe[5])) + re[2][i] * ((cos(pe[3]) * sin(pe[4]) * cos(pe[5])) - sin(pe[3]) * cos(pe[5])) + pe[1];
    r[2][i] = -re[0][i] * sin(pe[4]) + re[1][i] * sin(pe[3]) * cos(pe[4]) + re[2][i] * (cos(pe[3]) * cos(pe[4])) + z_home + pe[2];

    dl[0][i] = q[0][i] - r[0][i];
    dl[1][i] = q[1][i] - r[1][i];
    dl[2][i] = q[2][i] - r[2][i];

    dl2[i] = sqrt(dl[0][i] * dl[0][i] + dl[1][i] * dl[1][i] + dl[2][i] * dl[2][i]) - L2;

    theta_a[i] += (dl2[i] * feedback);

    theta_a[i] = constrain(theta_a[i], servo_min, servo_max);

    if (i % 2 == 0) servo_pos[i] = servo_zero[i] + theta_a[i] * servo_mult;

    else servo_pos[i] = servo_zero[i] - theta_a[i] * servo_mult;
  }

  for (int i = 0; i < 6; i++)
  {
    servo[i].writeMicroseconds(servo_pos[i]);
  }
}

i check the code many times, but no progress;

i am very appreciate for helping.

Welcome to the Forum. Please read Nick Gammon's two posts at the top of this Forum for guidelines on posting here. In most cases, we need to see all of your program code. Use Ctrl-T in the IDE to format your code in a standard manner and then use the code tags (i.e., the "</>" symbol) to properly post the code. It will help us help you.

econjack:
Welcome to the Forum. Please read Nick Gammon's two posts at the top of this Forum for guidelines on posting here. In most cases, we need to see all of your program code. Use Ctrl-T in the IDE to format your code in a standard manner and then use the code tags (i.e., the "</>" symbol) to properly post the code. It will help us help you.

Sorry for that.

i had updated.

:smiley:

Remove the static keyword from your array declarations in loop().

thanks, my code is works.

:slight_smile: