Skip to content

Latest commit

 

History

History
78 lines (68 loc) · 11.1 KB

EXAMPLES.md

File metadata and controls

78 lines (68 loc) · 11.1 KB

Initializing the Wifi Module and Updating the Location

See the example "SimpleTest.ino" by opening the Arduino editor with the library installed. Then click File->Examples-> Enes100->SimpleTest

Setting up an Ultrasonic Sensor

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}

Note: The below code is pseudocode. Its purpose is to help you understand how to do certain actions. There are multiple ways to do this.

Drive forward until you reach a certain x and y coordinate.

This code uses the old style of updateLocation and Enes100.location.x

//Setting a target of x = 2.5, y = 1.5
while (!Enes100.updateLocation()); //will keep running until succesfully update location
while(Enes100.location.x < 2.5) {  //move to x = 2.5
    Enes100.updateLocation();
    moveForward();
}
stop();
if(Enes100.locaiton.y > 1.5) { //if we are above the target, move down, otherwise move up.
   Enes100.updateLocation();
   moveDown();
} else {
    Enes100.updateLocaiton();
    moveUp();
}

Rotate to a certain theta coordinate

// This function will make the OTV turn to a certain location.
void setAngle(target) {
    print("Targeting angle: "); println(target);
    // The following line runs our targeting code WHILE the DIFFERENCE (subtraction is taking the difference) is between -thresh and thresh. 
    // We take the absolute value of the difference in order to compare it to a single threshold.
    while (abs(target - currentTheta) > threshold) {
        turnValue = someConstant * (target - currentTheta);
        turnValue = constrain(turnValue, -MAX_TURN_SPEED, MAX_TURN_SPEED); //Constrain your turn speed.
        setMotors(turnValue, -turnValue); // You will need to implement this yourself. 
    }
    print("Got to angle!");
    setMotors(0, 0);
}