<commit_before>/*
 * slave1.cpp
 * Team Pi Slave 1 Code
 * 
 * The Slave 1 functions as the orientation/location processor by acquiring
 * data from the iNEMO LSM9DS0 IMU, and 16 light sensors. This data
 * is interpreted and returned to the master Teensy using Serial/UART
 * 
 * Dependencies:
 *  	SFE_LSM9DS0
 *  	EEPROMAnything
 * All other non core libraries are written by me.
 *
 * By <NAME>
 * Originally authored in November 2014
 * Copyright (c) 2015 Team PI
 */


#include <WProgram.h>

#include <EEPROM.h>
#include <EEPROMAnything.h>
#include <SPI.h>
#include <SFE_LSM9DS0.h>
#include <piCommon.h>
#include <slave1.h>
#include <DebugUtils.h>

#define LED 13

#define COMPCONSTANT 0.9

union float2bytes { float f; uint8_t b[sizeof(float)]; };
float2bytes f2b;


elapsedMillis ledElapsedTime;
bool ledState = true;
uint32_t ledBlinkTime = 500;
elapsedMillis SerialRequestTime;


float bearing = 0;
float bearing_offset = 0;

uint8_t outBuffer[22] = {0};

inline void commandRequestStandardPacket();


void calibIMUOffset(){
	bearing_offset = 0;
	for (int i = 0; i < 10000; i++){
		slave1.imu.read();
		slave1.imu.complementaryFilterBearing(COMPCONSTANT);
	}
	for (int i = 0; i < 50; i++){
		slave1.imu.read();
		slave1.imu.complementaryFilterBearing(COMPCONSTANT);
		bearing = -slave1.imu.yaw;

		bearing_offset += bearing;
		delay(1);
	}
	bearing_offset /= 50;
}

void calibLight(){
	Serial.println("place on white");
	while(!Serial.available()){};
	CLEARSERIAL();

	slave1.lightArray.calibWhite();
	PRINTARRAY(slave1.lightArray.white);
	Serial.println("place on green");

	while(!Serial.available()){};
	CLEARSERIAL();

	slave1.lightArray.calibGreen();
	slave1.lightArray.endCalib();
	PRINTARRAY(slave1.lightArray.green);
	Serial.println();
	Serial.println("calibrated references values");
	PRINTARRAY(slave1.lightArray.refData);
	Serial.print("bad light sensors: ");
	for (int i = 0; i < 16; i++){
		if (slave1.lightArray.refData[i] == 255){
			Serial.print(i + 1);
			Serial.print('\t');
		}
	}
	Serial.println();
	Serial.println("Send anything to continue");
	while(!Serial.available()){};
	CLEARSERIAL();
}

void calibMag(){
	elapsedMillis elpsdPrintTime = 0;
	CLEARSERIAL();
	slave1.imu.initCalibMagRoutine();
	while(Serial.available() <= 0){
		slave1.imu.calibMagRoutine();
		if(elpsdPrintTime > 100){
			elpsdPrintTime = 0;
			// Serial.print(slave1.imu.mx, 6);
			// Serial.print('\t');
			// Serial.println(slave1.imu.my, 6);
			Serial.print("Mag readings: "); Serial.print(slave1.imu.mx);      Serial.print("\t");Serial.print(slave1.imu.my);      Serial.print("\t"); Serial.print(slave1.imu.mz);      Serial.println();
			Serial.print("Mag Minimums: "); Serial.print(slave1.imu.MagMinX); Serial.print("\t");Serial.print(slave1.imu.MagMinY); Serial.print("\t"); Serial.print(slave1.imu.MagMinZ); Serial.println();
			Serial.print("Mag Maximums: "); Serial.print(slave1.imu.MagMaxX); Serial.print("\t");Serial.print(slave1.imu.MagMaxY); Serial.print("\t"); Serial.print(slave1.imu.MagMaxZ); Serial.println(); Serial.println();
		}
	}
	// store mag calibration in EEPROM
	slave1.imu.storeMagCalibrations();
	// calculate magnetometer calibrations
	slave1.imu.preCalculateCalibParams();
	while(Serial.available() > 0){
		Serial.read();
	}
}

int main(void){	<commit_msg>changed calibration routine ui<commit_after>/*
 * slave1.cpp
 * Team Pi Slave 1 Code
 * 
 * The Slave 1 functions as the orientation/location processor by acquiring
 * data from the iNEMO LSM9DS0 IMU, and 16 light sensors. This data
 * is interpreted and returned to the master Teensy using Serial/UART
 * 
 * Dependencies:
 *  	SFE_LSM9DS0
 *  	EEPROMAnything
 * All other non core libraries are written by me.
 *
 * By <NAME>
 * Originally authored in November 2014
 * Copyright (c) 2015 Team PI
 */


#include <WProgram.h>

#include <EEPROM.h>
#include <EEPROMAnything.h>
#include <SPI.h>
#include <SFE_LSM9DS0.h>
#include <piCommon.h>
#include <slave1.h>
#include <DebugUtils.h>

#define LED 13

#define COMPCONSTANT 0.9

union float2bytes { float f; uint8_t b[sizeof(float)]; };
float2bytes f2b;


elapsedMillis ledElapsedTime;
bool ledState = true;
uint32_t ledBlinkTime = 500;
elapsedMillis SerialRequestTime;


float bearing = 0;
float bearing_offset = 0;

uint8_t outBuffer[22] = {0};

inline void commandRequestStandardPacket();


void calibIMUOffset(){
	bearing_offset = 0;
	for (int i = 0; i < 10000; i++){
		slave1.imu.read();
		slave1.imu.complementaryFilterBearing(COMPCONSTANT);
	}
	for (int i = 0; i < 50; i++){
		slave1.imu.read();
		slave1.imu.complementaryFilterBearing(COMPCONSTANT);
		bearing = -slave1.imu.yaw;

		bearing_offset += bearing;
		delay(1);
	}
	bearing_offset /= 50;
}

void calibLight(){
	Serial.println("place on white");
	while(!Serial.available()){};
	CLEARSERIAL();

	slave1.lightArray.calibWhite();
	PRINTARRAY(slave1.lightArray.white);
	Serial.println("place on green");

	while(!Serial.available()){};
	CLEARSERIAL();

	slave1.lightArray.calibGreen();
	slave1.lightArray.endCalib();
	PRINTARRAY(slave1.lightArray.green);
	Serial.println();
	Serial.println("calibrated references values");
	PRINTARRAY(slave1.lightArray.refData);
	Serial.print("bad light sensors: ");
	for (int i = 0; i < 16; i++){
		if (slave1.lightArray.refData[i] == 255){
			Serial.print(i + 1);
			Serial.print('\t');
		}
	}
	Serial.println();
	Serial.println("Send anything to continue");
	while(!Serial.available()){};
	CLEARSERIAL();
}

void calibMag(){
	elapsedMillis elpsdPrintTime = 0;
	CLEARSERIAL();
	slave1.imu.initCalibMagRoutine();
	while(Serial.available() <= 0){
		slave1.imu.calibMagRoutine();
		if(elpsdPrintTime > 100){
			elpsdPrintTime = 0;
			// Serial.print(slave1.imu.mx, 6);
			// Serial.print('\t');
			// Serial.println(slave1.imu.my, 6);
			Serial.print("Mag readings: "); Serial.print(slave1.imu.mx);      Serial.print("\t");Serial.print(slave1.imu.my);      Serial.print("\t"); Serial.print(slave1.imu.mz);      Serial.println();
			Serial.print("Mag Minimums: "); Serial.print(slave1.imu.MagMinX); Serial.print("\t");Serial.print(slave1.imu.MagMinY); Serial.print("\t"); Serial.print(slave1.imu.MagMinZ); Serial.println();
			Serial.print("Mag Maximums: "); Serial.print(slave1.imu.MagMaxX); Serial.print("\t");Serial.print(slave1.imu.MagMaxY); Serial.print("\t"); Serial.print(slave1.imu.MagMaxZ); Serial.println(); Serial.println();
		}
	}
	// store mag calibration in EEPROM
	slave1.imu.storeMagCalibrations();
	// calculate magnetometer calibrations
	slave1.imu.preCalculateCalibParams();
	CLEARSERIAL();
	Serial.println("PRESS AND KEY TO CONTINUE");
	while(!Serial.available()){};
	CLEARSERIAL();
}

int main(void){	
{'fraction_non_alphanumeric': 0.15829825616355983, 'fraction_numerical': 0.02841250751653638, 'mean_word_length': 4.671781756180733, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 24, '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': '5748574', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2381, 'n_words': 498}