digital-twin-aircraft — Arduino Mega simulation

An interactive Arduino Mega circuit simulation you can run free in your browser on Velxio, by sumaneg925.

Components

Sketch code

#include <Wire.h>

#define MPU 0x68
#define STRAIN_PIN A4

// Material properties
float E = 70e9;              // Young's modulus (Pa)
float yieldStress = 250e6;   // Yield stress (Pa)
float designLife = 10000;    // Flight hours

// Damage & Crack
float damage = 0.0;
float crackLength = 0.001;   // meters
float C = 1e-12;
float m = 3.0;

void setup() {
  Serial.begin(115200);
    Wire.begin();   // MEGA uses 20/21

      // Wake MPU6050
        Wire.beginTransmission(MPU);
          Wire.write(0x6B);
            Wire.write(0);
              Wire.endTransmission();

                Serial.println("Time,Strain_uE,Stress_MPa,GyroRMS,Damage,Health%,Crack_mm,RUL_hr,ALARM");
                }

                void loop() {

                  // ===== TIME =====
                    unsigned long timeSec = millis() / 1000;

                      // ===== STRAIN =====
                        int adcStrain = analogRead(STRAIN_PIN);
                          float microstrain = (adcStrain / 1023.0) * 2000.0;

                            // ===== STRESS =====
                              float stress = microstrain * E * 1e-6;
                                float stressMPa = stress / 1e6;

                                  // ===== MPU GYRO =====
                                    int16_t GyX, GyY, GyZ;

                                      Wire.beginTransmission(MPU);
                                        Wire.write(0x43);
                                          Wire.endTransmission(false);
                                            Wire.requestFrom(MPU, 6, true);

                                              GyX = Wire.read() << 8 | Wire.read();
                                                GyY = Wire.read() << 8 | Wire.read();
                                                  GyZ = Wire.read() << 8 | Wire.read();

                                                    float gx = GyX / 131.0;
                                                      float gy = GyY / 131.0;
                                                        float gz = GyZ / 131.0;

                                                          float vibrationRMS = sqrt(gx*gx + gy*gy + gz*gz);

                                                            // ===== DAMAGE MODEL =====
                                                              float damageIncrement = pow(stress / yieldStress, 3);
                                                                damage += damageIncrement * 0.01;   // visible growth

                                                                  if (damage > 1.0) damage = 1.0;

                                                                    float healthIndex = (1.0 - damage) * 100.0;

                                                                      // ===== PARIS LAW =====
                                                                        float deltaK = stressMPa * sqrt(3.14 * crackLength);

                                                   

More projects by sumaneg925