Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
projets:hyperstatic:accueil [2017/06/09 17:46] moritzfuehrer Créé depuis le formulaire projets:creer |
projets:hyperstatic:accueil [2017/06/09 18:21] (Version actuelle) resonance [Matériaux et outils] |
||
---|---|---|---|
Ligne 7: | Ligne 7: | ||
* Lien : //mettre un lien// | * Lien : //mettre un lien// | ||
- | {{tag> | + | {{tag> |
===== Note d' | ===== Note d' | ||
Ligne 17: | Ligne 17: | ||
Guide pas à pas et conseil pour la réalisation du projet. | Guide pas à pas et conseil pour la réalisation du projet. | ||
- | ===== Matériaux et outils | + | ===== Mécanique |
- | Liste de matériel et outils nécessaires. | + | {{: |
+ | ===== Codes ===== | ||
+ | ++++ Code Arduino | | ||
+ | <code cpp> | ||
+ | // A COMMENTER ! | ||
+ | // ....... | ||
+ | // page wiki + photos : http:// | ||
+ | // organiser son dossier . dessins, electronic (connexions), | ||
+ | |||
+ | // source . https:// | ||
+ | |||
+ | #define DURATION_SAMPLING 5 // temps entre chaque valeur du capteur et changement de vitesse | ||
+ | |||
+ | // Seauence de vitesses pour le moteur | ||
+ | const int NB_SEQUENCE = 8; // nombre de sequence | ||
+ | int speedSequence [][2] = { // tableau de couples de valeurs (pwm entre 0 et 255, ms) | ||
+ | {50, 1000}, // speed = 50, ms = 1000 | ||
+ | {200, 5000}, | ||
+ | {100, 2000}, | ||
+ | {100, 10000}, | ||
+ | {255, 3000}, | ||
+ | {255, 4000}, | ||
+ | {50, 5000}, | ||
+ | {50, 10000}, // finir avec la meme vitesse | ||
+ | }; | ||
+ | |||
+ | float currentSpeed = 0; | ||
+ | | ||
+ | // Effect Hall sensor | ||
+ | const int hallPin = 10; // the pin that the pushhall is attached to | ||
+ | int hallPushCounter = 0; // counter for the number of hall presses | ||
+ | int hallState = 0; // current state of the hall | ||
+ | int lasthallState = 0; // previous state of the hall | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | // Communication | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | // Sensor setup | ||
+ | pinMode(hallPin, | ||
+ | |||
+ | // Motor Setup | ||
+ | pinMode(6, OUTPUT); // motor 2 PWM | ||
+ | pinMode(4, OUTPUT); // motor 2 INA: Clockwise input | ||
+ | pinMode(9, OUTPUT); // motor 2 INB: Counter-clockwise input | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(9, | ||
+ | |||
+ | // Motor direction | ||
+ | digitalWrite(9, | ||
+ | |||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // Launch seauence of speed variations | ||
+ | readMotorSequence(); | ||
+ | } | ||
+ | | ||
+ | // Speed variations | ||
+ | void readMotorSequence(){ | ||
+ | int destSpeed = 0; | ||
+ | int destDuration = 0; | ||
+ | float deltaSpeed; | ||
+ | |||
+ | // boucle sur la seauence globale | ||
+ | for (int i = 0; i < NB_SEQUENCE; | ||
+ | { | ||
+ | destSpeed = speedSequence[i][0]; | ||
+ | destDuration = speedSequence[i][1]; | ||
+ | deltaSpeed = (destSpeed - currentSpeed ) / (destDuration / DURATION_SAMPLING) ; // calcul du delta de la vitesse | ||
+ | | ||
+ | /* | ||
+ | // DEBUG | ||
+ | Serial.println(" | ||
+ | Serial.print(destSpeed); | ||
+ | Serial.print(" | ||
+ | Serial.println(destDuration); | ||
+ | Serial.print(" | ||
+ | Serial.println(deltaSpeed); | ||
+ | */ | ||
+ | |||
+ | // interpolation de la vitesse vers la vitesse de destination destSpeed | ||
+ | for (int t = 0 ; t < destDuration ; t = t + DURATION_SAMPLING) { | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | // Motor speed | ||
+ | analogWrite(6, | ||
+ | | ||
+ | currentSpeed = currentSpeed + deltaSpeed; | ||
+ | |||
+ | // Get and send sensor value at the same time | ||
+ | getHallSensor(); | ||
+ | |||
+ | delay(DURATION_SAMPLING); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Get value of hall sensor and send it through Serial communication | ||
+ | void getHallSensor() { | ||
+ | hallState = digitalRead(hallPin); | ||
+ | if (hallState != lasthallState) { | ||
+ | if (hallState == HIGH) { | ||
+ | Serial.write(hallPushCounter); | ||
+ | hallPushCounter++; | ||
+ | } | ||
+ | } | ||
+ | lasthallState = hallState; | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++ Code Processing | | ||
+ | <code java> | ||
+ | // A COMMENTER ! | ||
+ | // ....... | ||
+ | |||
+ | // Libs | ||
+ | import processing.video.*; | ||
+ | import processing.serial.*; | ||
+ | |||
+ | Capture videocam; | ||
+ | Serial myserial; | ||
+ | |||
+ | // Setup | ||
+ | int W = 1280; //1920x1080 ou 1280x720 ou 1024x768 | ||
+ | int H = 720; | ||
+ | int R = 30; // 15 ou 30 | ||
+ | String CAM_NAME = "/ | ||
+ | String ARDUINO_NAME = "/ | ||
+ | boolean DEBUG = false; // afficher la liste des ports série et résolutions de caméra | ||
+ | |||
+ | // Other variables | ||
+ | int sensorValue; | ||
+ | int lastSensorValue = 0; | ||
+ | int sensorTime; | ||
+ | int lastSensorTime =0; | ||
+ | PFont f; | ||
+ | String val; | ||
+ | float rpm; | ||
+ | |||
+ | void setup () { | ||
+ | | ||
+ | fullScreen(); | ||
+ | background(0); | ||
+ | |||
+ | // Affichage des résolutions et des ports séries disponibles | ||
+ | if (DEBUG) { | ||
+ | printArray(Serial.list()); | ||
+ | printArray(Capture.list()); | ||
+ | } | ||
+ | | ||
+ | // Arduino | ||
+ | myserial = new Serial(this, | ||
+ | | ||
+ | // Webcam | ||
+ | videocam = new Capture(this, | ||
+ | videocam.start(); | ||
+ | | ||
+ | // Font | ||
+ | f = createFont(" | ||
+ | textFont(f); | ||
+ | textAlign(CENTER, | ||
+ | } | ||
+ | |||
+ | void draw () { | ||
+ | // Read Webcam | ||
+ | if (videocam.available ()) { | ||
+ | videocam.read (); | ||
+ | } | ||
+ | |||
+ | // Choose : "image (videocam, 0, 0)" ou " | ||
+ | set(0, 0, videocam); | ||
+ | | ||
+ | // Display text | ||
+ | String t = str((int)rpm) + " T/m"; | ||
+ | text(t, W/2, H/2); | ||
+ | } | ||
+ | |||
+ | // Read serial value (from Serial.write() in the Arduino program) | ||
+ | void serialEvent (Serial myPort) { | ||
+ | sensorValue = myPort.read(); | ||
+ | | ||
+ | // Find the RPM | ||
+ | if (sensorValue != lastSensorValue) { | ||
+ | sensorTime = millis() - lastSensorTime ; | ||
+ | rpm = 60000 / sensorTime; | ||
+ | } | ||
+ | | ||
+ | lastSensorTime = millis(); | ||
+ | lastSensorValue = sensorValue; | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | * Télécharger aussi la police pour le sketch Processing, à placer dans le répertoire " | ||
+ | |||
+ | {{: | ||
===== Photos ===== | ===== Photos ===== | ||
Code pour afficher les images du projet : | Code pour afficher les images du projet : |