<commit_before>// SCOUT Navigation and Logic

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
 
/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);

// Pass data to USB serial via digital 3,2
SoftwareSerial mySerial(3, 2);

// Assign names to analog 0-3 for relay
int POS1 = A0;
int NEG1 = A1;
int POS2 = A2;
int NEG2 = A3;
int delayValue = 5000;

Adafruit_GPS GPS(&mySerial);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{

  // Initialise compass
  if(!mag.begin())
  {
    // Verify compass / accel configured 
    Serial.println("No Accelerometer Detected");
    while(1);
  }
  
  // connect at 115200 baud to read GPS quickly
  // also spit it out
  Serial.begin(115200);
  Serial.println("GPS Initializing");

  // Initialize analog pins
  pinMode(POS1, OUTPUT);
  pinMode(NEG1, OUTPUT);
  pinMode(POS2, OUTPUT);
  pinMode(NEG2, OUTPUT);

  // With this relay, HIGH is OFF
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  Serial.println("Initialized With High.");

  Serial.println("Turning Clockwise");
  digitalWrite(POS1, LOW);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, LOW);

  delay(delayValue);

  Serial.println("Turning OFF");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  Serial.println("Turning Counter Clockwise");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, LOW);
  digitalWrite(POS2, LOW);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  Serial.println("Turning OFF");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  
  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // 1 ms interrupt
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  //mySerial.println(PMTK_Q_RELEASE);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     
{
  sensors_event_t event; 
  mag.getEvent(&event);
  float Pi = 3.14159;
  // Calculate the angle of the vector y,x
  float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
  
  // Normalize to 0-360
  if (heading < 0)
  {
    heading = 360 + heading;
  }

  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
      
  }
  
  // Determine if new statement received, if so, check the checksum, parse
  if (GPS.newNMEAreceived()) {
    
    if (!GPS.parse(GPS.lastNMEA()))   // this sets the newNMEAreceived() flag to false
      return;  // if miss statement, wait for
  }

  // if millis() or timer wraps around, reset it
  if (timer > millis())  timer = millis();

  //  Every 2 seconds, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer<commit_msg>Clean up / add comments<commit_after>// SCOUT Navigation and Logic

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
 
// Assign a unique ID to compass / accelerometer
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);

// Pass data to USB serial via digital 3,2
SoftwareSerial mySerial(3, 2);

// Assign names to analog 0-3 for relay control
int POS1 = A0;
int NEG1 = A1;
int POS2 = A2;
int NEG2 = A3;
int delayValue = 5000;

Adafruit_GPS GPS(&mySerial);

// Listen to the raw GPS sentences. 
#define GPSECHO  true

// Using interrupt between statements
boolean usingInterrupt = false;

void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{

  // Initialise compass
  if(!mag.begin())
  {
    // Verify compass / accel configured 
    Serial.println("No Accelerometer Detected");
    while(1);
  }
  
  // connect at 115200 baud to read GPS quickly
  Serial.begin(115200);
  Serial.println("GPS Initializing");

  // Initialize analog pins
  pinMode(POS1, OUTPUT);
  pinMode(NEG1, OUTPUT);
  pinMode(POS2, OUTPUT);
  pinMode(NEG2, OUTPUT);

  // With this relay, HIGH is OFF
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  Serial.println("Initialized With High.");

  // Turn Clockwise
  Serial.println("Turning Clockwise");
  digitalWrite(POS1, LOW);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, LOW);

  delay(delayValue);

  // Turn Off Power to Steering Motor
  Serial.println("Turning OFF");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  // Turn Counter Clockwise
  Serial.println("Turning Counter Clockwise");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, LOW);
  digitalWrite(POS2, LOW);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  // Turn Off Power to Steering Motor
  Serial.println("Turning OFF");
  digitalWrite(POS1, HIGH);
  digitalWrite(NEG1, HIGH);
  digitalWrite(POS2, HIGH);
  digitalWrite(NEG2, HIGH);

  delay(delayValue);

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's
  GPS.begin(9600);
  
  // Read RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  
  // Request updates on antenna status
  GPS.sendCommand(PGCMD_ANTENNA);

  // 1 ms interrupt
  useInterrupt(true);

  delay(1000);
  
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();

#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 
#endif
}

void useInterrupt(boolean v) {
  if (v) {  
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     
{
  sensors_event_t event; 
  mag.getEvent(&event);
  float Pi = 3.14159;
  // Calculate the angle of the vector y,x
  float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
  
  // Normalize to 0-360
  if (heading < 0)
  {
    heading = 360 + heading;
  }

  if (! usingInterrupt) {
    // read data from the GPS 
    char c = GPS.read();
      
  }
  
  // Determine if new statement received, if so, check the checksum, parse
  if (GPS.newNMEAreceived()) {
    
    if (!GPS.parse(GPS.lastNMEA()))   // this sets the newNMEAreceived() flag to false
      return;  // if miss statement, wait for
  }

  // if millis() or timer wraps around, reset it
  if (timer > millis())  timer = millis();

  //  Every 2 seconds, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
{'fraction_non_alphanumeric': 0.11450381679389313, 'fraction_numerical': 0.02993797709923664, 'mean_word_length': 3.3132716049382718, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5744552', 'n_tokens_mistral': 3191, 'n_tokens_neox': 2921, 'n_words': 875}