Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int motorPin[4] = {6, 8, 10, 12};
- int ccw[8][4] =
- {
- {HIGH, LOW, LOW, HIGH},
- {LOW , LOW, LOW, HIGH},
- {LOW , LOW, HIGH, HIGH},
- {LOW , LOW, HIGH, LOW},
- {LOW , LOW, HIGH, LOW},
- {LOW , HIGH, HIGH, LOW},
- {HIGH, HIGH, LOW , LOW},
- {HIGH, LOW, LOW , LOW}
- };
- long unsigned T1, T2;
- long unsigned ip, np, npMin;
- double dt, t, phi, phinow, dphi;
- void setup() {
- // constantes
- double inch2cm = 2.54; // 1 pouce = 2.54 cm
- // moteur
- int ppr = 4096; // inpulsions par revolution (reduction = 64)
- // geometrie
- double tpi; // pas par pouce
- double beam; // charnière - vis
- double y0; // depassement de vis initial en cm
- double y1; // depassement de vis final en cm
- tpi = 25.4;
- beam = 17.75;
- y0 = 19.5;
- y1 = 1.0;
- phi = atan2(195, 177.5)*180/3.14159265; //angle 0 en deg
- np = ((y0-y1)/inch2cm)*tpi*ppr; // impulsions de y0 à y1
- ip = 0; // conpteur d'impulsions
- // pin moteur en sortie
- for (int j = 0; j < 4; j++)
- pinMode(motorPin[j], OUTPUT);
- analogReference(DEFAULT);
- T1 = millis(); // temps en µs, ms
- T2 = micros();
- }
- void loop(){ //--------------------------------------------------------------------------------
- Serial.begin(9600);
- Serial.println(np);
- while (ip <= np) {
- int ic = ip % 8; // utilise une ligne de la matrice a chaque pas, modulo 8 / We use one matrix line per step
- // stepping
- t = 1000000*dt;
- Serial.println("zone 1 pass"); //----- ZONE 1
- while (micros() > T2+t){
- T2 = micros();
- Serial.println("zone 2 pass"); //----- ZONE 2
- for (int j = 0; j < 4; j++) {
- digitalWrite(motorPin[3-j], ccw[ic][j]);
- }
- }
- ip = ip + 1;
- // Determine phinow et delta phi
- phinow = atan2(195-(ip/512), 177.5)*180/3.14159265; // phi apres phasage en deg
- dphi = phi-phinow;
- // Determine dt
- dt = dphi*86164.1/360; //temps que met la terre pour effectuer dphi / Time the earth take to rotate dphi
- //affichage
- while (millis() > T1+500){
- T1 = millis();
- Serial.print("ip = ");
- Serial.println(ip);
- Serial.print("dphi = ");
- Serial.println(dphi);
- Serial.print("dt= ");
- Serial.println(dt);
- Serial.print("phinow= ");
- Serial.println(phinow);
- Serial.print("phi= ");
- Serial.println(phi);
- Serial.println(" ");
- }
- phinow = phi;
- }
- }
Add Comment
Please, Sign In to add comment