Go Down

Topic: incorporating GPS in a pan/tilt mount (Read 1 time) previous topic - next topic

PeterH


that automatically would move the camera to a preset GPS location, and altitude above sea level.


So you want to have the Arduino find its own position using GPS and orientation using a gyro and compass, then calculate the relative bearing and elevation to your target position? That's a pretty neat idea. Just compensating for changes in the vehicle orientation will be quite tricky, I suspect. In effect you'd be making a steadycam. Then you need to do a bit of trigonometry to calculate the direction of your target point. GPS does not give you very good resolution so it will be a bit notchy. If that's important to you you could probably use interpolation to smooth that out, and if you have a gyro that would give you an even better solution.
I only provide help via the forum - please do not contact me for private consultancy.

ThatNinthGuy

@PeterH

I was planning on using a gyro and a compass to calculate the angles... Most likely buying them at Sparkfun, but not the 150$ compass, of course ;)

Simon
Kind regards
Simon Madsen

ThatNinthGuy

Quote

// GPScam
// Created by Simon Madsen
// 06-10-2012
// dd-mm-yyyy
// Beer ware-licenced

// Compatible with hardware versions:
// 1.0


// Revision 1
// By Simon Madsen
// 
// dd-mm-yyyy

#include <Servo.h>

float localLatitude = 0;     // System latitude
float localLongtitude = 0;   // System longtitude
float localAltitude = 0;     // System altitude

float targetLatitude = 0;    // Target latitude
float targetLongtitude = 0;  // Target longitude
float targetAltitude = 0;    // Target altitude

Servo panServo;              // Servo used for panning
Servo tiltServo;             // Servo used for tilting
int panServoPos = 0;
int tiltServoPos = 0;

float gyroInX = 0;           // Xaxis data from the gyro
float gyroInY = 0;           // Yaxis data from the gyro
float gyroInZ = 0;           // Zaxis data from the gyro
float compassIn = 0;         // Tilt-compensated heading data from the compass
float altimeterIn = 0;       // Pressure data from the barometric pressure sensor

int XbeeSerial = 0;

void setup() {
  panServo.attach(9);
  tiltServo.attach(10);
  
  Serial.begin(9600);        // Communications with computer
  Serial1.begin(115200);     // Communications with Xbee
  
  panServo.write(panServoPos);
  tiltServo.write(tiltServoPos);
  
}


void loop() {
  XbeeSerial = Serial1.read;
  switch (XbeeSerial) {
    case "1":
      Serial.print("Remote Control");
      panServo.write(Serial1.read);
      Serial.print("panServo: "
      Serial.print(Serial1.read);
      delay(5);
      tiltServo.write(Serial1.read);
      Serial.print("tiltServo: "
      Serial.print(Serial1.read);
      break;
      
    case "2":
      delay(5);
      targetLatitude = Serial1.read();
      Serial.print(targetLatitude);
      Serial.print();
      delay(5);
      targetLongtitude = Serial1.read();
      Serial.print(targetLongtitude);
      Serial.print();
      delay(5);
      targetAltitude = Serial1.read();
      Serial.print(targetAltitude);
      Serial.print();
      break;
  }
}
  
    
    // This is where I cant choose between "switch case" or "if"
    
    
  if (Serial.available()) {
    if (Serial1.available()) {
      if (Serial1.read = ("Remote Control")) {
        panServo.write(Serial1.read);
        delay(5);
        tiltServo.write(Serial1.read);
      }
      
      if (Serial1.read = ("Target Location")) {
        delay(5);
        targetLatitude = Serial1.read();
        Serial.print(targetLatitude);
        Serial.print();
        delay(5);
        targetLongtitude = Serial1.read();
        Serial.print(targetLongtitude);
        Serial.print();
        delay(5);
        targetAltitude = Serial1.read();
        Serial.print(targetAltitude);
        Serial.print();
      }
    }
  }
}




I can't decide whether to use "if"-sentences or "switch cases"... Do you have any suggestions?
Kind regards
Simon Madsen

wizdum




I can't decide whether to use "if"-sentences or "switch cases"... Do you have any suggestions?


Switch cases are generally used when you would have "a lot of" if statements. I wouldn't use a switch case unless there would be more than 2 cases.
"Anyone who isn't confused really doesn't understand the situation."

Electronic props for Airsoft, paintball, and laser tag -> www.nightscapetech.com

PeterH

You handling of serial input looks distinctly dodgy. Serial.read() returns a byte, which will contain a character if that is what is being sent over the serial stream. If you receive a single character and want to see which character it is you need to compare it with a character constant '1', '2' etc not a string literal "1", "2" etc. If you want to receive a sequence of characters containing a string such as "Remote Control" then you need to read the characters one by one and store them in a buffer and then compare the contents of the buffer with your expected strings to see whether it matches any of them. To do the comparison, you'd need to use a function such as strcmp(), you can't simply use an == operator to compare string values.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up