Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/LocalSettings.php on line 193

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/LocalSettings.php on line 197

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/includes/parser/Parser.php on line 2338

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/includes/parser/Parser.php on line 2338

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/includes/parser/Parser.php on line 2338

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/includes/parser/Parser.php on line 2338

Warning: putenv() has been disabled for security reasons in /home/users4/d/debrouilloweb/www/wikidebrouillard/includes/parser/Parser.php on line 2338
[ Wikidébrouillard ] Contrôle de Google Earth avec l'Arduino

Contrôle de Google Earth avec l'Arduino

De Wikidebrouillard.

Article incomplet en cours de rédaction
Modèle:Vidéo

Sommaire

Présentation du projet Arduino

On souhaite pouvoir commander le simulateur de vol de Google Earth avec un Nunchuk de Wii grâce à l'Arduino.

Ce projet permet une interaction plus intuitive avec le simulateur de vol de Google Earth, nous permettant de "voler" n'importe où sur la terre afin de consulter des images satellites, des cartes et des bâtiments 3D.

On pourra ainsi, en se rendant sur le logiciel de navigation, choisir son avion (le SR22 est plus facile à piloter que le F16) et un aéroport pour ensuite démarrer le vol en utilisant le nunchuk.

Liste du matériel

réalisation du projet

Explication

Afin de raccorder le nunchuk de wii à l'arduino, il est nécessaire de disposer d'une plaque labdec sur laquelle on relira les deux. Pour ce faire, il faut utiliser un adaptateur que l'on fixe au Nunchuk et de souder des fils de couleurs (pour mieux se repérer) cet adaptateur.

Il faut ensuite à partir d'un ordinateur paramétrer le code de l'arduino avec le code donné sur cette page.

Code


/*
 * WiichuckSerial
 *
 * Uses Nunchuck Library discussed in Recipe 16.5
 * sends comma-separated values for data
 * Label string separated by commas can be used by receiving program 
 * to identify fields
 */


#include <Wire.h>
#include "Nunchuck.h"

// values to add to the sensor to get zero reading when centered
int offsetX, offsetY, offsetZ; 

#include <Wire.h>
#include "Nunchuck.h"
void setup()
{
    Serial.begin(57600);
    nunchuckSetPowerpins();
    nunchuckInit(); // send the initialization handshake
    nunchuckRead(); // ignore the first time
    delay(50);
}
void loop()
{
  nunchuckRead();
  delay(6);
  boolean btnC = nunchuckGetValue(wii_btnC);
  boolean btnZ = nunchuckGetValue(wii_btnZ);
  
  if(btnC) {
    offsetX = 127 - nunchuckGetValue(wii_accelX) ; 
    offsetY = 127 - nunchuckGetValue(wii_accelY) ;         
  }
  Serial.print("Data,");
  printAccel(nunchuckGetValue(wii_accelX),offsetX) ; 
  printAccel(nunchuckGetValue(wii_accelY),offsetY) ; 
  printButton(nunchuckGetValue(wii_btnZ));      

  Serial.println();
}
     
void printAccel(int value, int offset)
{
  Serial.print(adjReading(value, 127-50, 127+50, offset));
  Serial.print(",");
}

void printJoy(int value)
{
  Serial.print(adjReading(value,0, 255, 0));
  Serial.print(",");
}

void printButton(int value)
{
  if( value != 0)
     value = 127;
  Serial.print(value,DEC);
  Serial.print(",");
}

int adjReading( int value, int min, int max, int offset)
{
   value = constrain(value + offset, min, max);
   value = map(value, min, max, -127, 127);
   return value;  
}

You can send nunchuck joystick values instead of the accelerometer values by replacing the two lines that begin printAccel with the following lines:
printJoy(nunchuckGetValue(wii_joyX));
printJoy(nunchuckGetValue(wii_joyY));

You can use the Processing sketch from Recipe 4.10, but this enhanced version displays the control position in the Processing window and activates the flight simulator using the nunchuck ‘z’ button:

/**
 * GoogleEarth_FS.pde 
 * 
 * Drives Google Flight Sim using CSV sensor data
 */

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.Dimension;
import processing.serial.*;
Serial myPort;  // Create object from Serial class

arduMouse myMouse;

String message = null;
int maxDataFields = 7; // 3 axis accel, 2 buttons, 2 joystick axis
boolean isStarted = false;
int accelX, accelY, btnZ; // data from msg fields will be stored here          


void setup() {
  size(260, 260);
  PFont fontA = createFont("Arial.normal", 12);  
  textFont(fontA);

  short portIndex = 1;  // select the com port, 0 is the first port
  String portName = Serial.list()[portIndex];
  println(Serial.list());
  println(" Connecting to -> " + portName) ;
  myPort = new Serial(this, portName, 57600);
  myMouse = new arduMouse();

  fill(0); 
  text("Start Google FS in the center of your screen", 5, 40);
  text("Center the mouse pointer in Google earth", 10, 60);
  text("Press and release Nunchuck Z button to play", 10, 80);  
  text("Press Z button again to pause mouse", 20, 100);
}

void draw() {
  processMessages();
  if (isStarted == false) {
    if ( btnZ != 0) {      
      println("Release button to start");
      do{ processMessages();}
         while(btnZ != 0);
      myMouse.mousePress(InputEvent.BUTTON1_MASK); // start the SIM
      isStarted = true;
    }
  }
  else 
  {
    if ( btnZ != 0) { 
      isStarted = false;
      background(204);
      text("Release Z button to play", 20, 100);
      print("Stopped, ");
    }      
    else{
      myMouse.move(accelX, accelY); // move mouse to received x and y position
      fill(0); 
      stroke(255, 0, 0);
      background(#8CE7FC);
      ellipse(127+accelX, 127+accelY, 4, 4);
    }
  }
}

void processMessages() {
  while (myPort.available () > 0) {
    message = myPort.readStringUntil(10); 
    if (message != null) {
      //print(message);  
      String [] data  = message.split(","); // Split the CSV message       
      if ( data[0].equals("Data"))// check for data header    
      {
        try {
          accelX = Integer.parseInt(data[1]);  
          accelY = Integer.parseInt(data[2]); 
          btnZ = Integer.parseInt(data[3]);
        }
        catch (Throwable t) {
          println("."); // parse error
        }
      }
    }
  }
}

class arduMouse {
  Robot myRobot;     // create object from Robot class;
  static final short rate = 4; // pixels to move
  int centerX, centerY;
  arduMouse() {
    try {
      myRobot = new Robot();
    }
    catch (AWTException e) {
      e.printStackTrace();
    }
    Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    centerY =  (int)screen.getHeight() / 2 ;
    centerX =  (int)screen.getWidth() / 2;
  }
  // method to move mouse from center of screen by given offset
  void move(int offsetX, int offsetY) {
    myRobot.mouseMove(centerX + (rate* offsetX), centerY - (rate * offsetY));
  }
  // method to simulate pressing mouse button
  void mousePress( int button) {
    myRobot.mousePress(button) ; 
  }
}

Liens avec d'autres projets arduino

Expériences sur Wikidébrouillard

D'autres expériences utilisant l'Arduino sont disponible dans ce wiki. Vous pouvez les retrouver ici : Catégorie : Arduino.

Autres expériences

Vous pouvez retrouver une multitude d'expériences sur l'arduino sur Arduino forum.

Pour aller plus loin

Liens avec le quotidien

quelles peuvent être les applications technologique de ce montage, ou est-ce qu'on retrouve des programme qui y ressemble ?
Portail des ExplorateursWikidébrouillardLéon DitFLOGPhoto mystèreJ'ai FaitPortraits
AR
CO

Contrôle de Google Earth avec l'Arduino

Rechercher

Page Discussion Historique
Powered by MediaWiki
Creative Commons - Paternite Partage a l

© Graphisme : Les Petits Débrouillards Grand Ouest (Patrice Guinche - Jessica Romero) | Développement web : Libre Informatique