twhi2525
Published © GPL3+

Head Tracking for Wireless 3D First Person Vision

A remote controlled vehicle with stereo cameras on a head-tracked pan-tilt unit and wireless 3D first person control via an Oculus Rift.

AdvancedShowcase (no instructions)7,945
Head Tracking for Wireless 3D First Person Vision

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
SparkFun XBee Explorer USB
SparkFun XBee Explorer USB
×1
SparkFun XBee Shield
SparkFun XBee Shield
×1
Xbee Pro S1
×1
Corona DS238 MG Digital Servos
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

Arduino Servo Control from XBee serial receive

Arduino
Flashed to Arduino Uno
#include <Servo.h>
Servo yawservo;  // create servo object to control a servo
Servo pitchservo;  // create servo object to control a servo

String inputString = "";         // a string to hold incoming data
boolean yawComplete = false;  // whether the string is complete
boolean pitchComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600); // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  yawservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pitchservo.attach(10);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  serialEvent(); //call the function // print the string when a newline arrives:
  if (pitchComplete) {
    pitchservo.write(inputString.toInt());                  // sets the servo position according to the scaled value 
    delay(1); 
    inputString = "";
    pitchComplete = false;
  }

    if (yawComplete) {
    yawservo.write(inputString.toInt());                  // sets the servo position according to the scaled value 
    delay(1); 
    inputString = "";
    yawComplete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == 'x')
    {
      pitchComplete = true;
      break;
    }
        if (inChar == 'y')
    {
      yawComplete = true;
      break;
    }
    inputString += inChar;
  }
}

Credits

twhi2525

twhi2525

1 project • 12 followers
Contact

Comments