mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 11:55:00 +00:00
added and fixed logger
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@ src/C++/Driver/Makefile
|
||||
src/C++/Driver/vgcore*
|
||||
src/C++/Driver/cmake_install.cmake
|
||||
src/C++/Driver/Makefile
|
||||
src/C++/Driver/log
|
||||
|
@@ -16,20 +16,21 @@ int main()
|
||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
// thread mv(movement);
|
||||
// mv.join(); //only exit once thread one is done running
|
||||
|
||||
// checkCenterCliff();
|
||||
logToFile();
|
||||
|
||||
//seperate thread so sleep doesnt block main thread
|
||||
thread logger(logToFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int checkCenterCliff()
|
||||
{
|
||||
while(true){
|
||||
std::cout << robot.parser.data.CliffCenter << endl;
|
||||
while (true)
|
||||
{
|
||||
std::cout << robot.parser.data.CliffCenter << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int movement()
|
||||
{
|
||||
int text;
|
||||
@@ -65,17 +66,67 @@ int movement()
|
||||
}
|
||||
}
|
||||
|
||||
void logToFile()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TKobukiData robotData = robot.parser.data;
|
||||
std::ofstream outputFile("log", std::ios_base::app); // Open file in append mode to not overwrite own content
|
||||
if (outputFile.is_open())
|
||||
{ // check if the file was opened successfully
|
||||
// Get current time
|
||||
std::time_t now = std::time(nullptr);
|
||||
outputFile << "Timestamp: " << std::ctime(&now);
|
||||
// Write data to the file
|
||||
outputFile << "analogInputCh0: " << robotData.analogInputCh0 << "\n";
|
||||
outputFile << "analogInputCh1: " << robotData.analogInputCh1 << "\n";
|
||||
outputFile << "analogInputCh2: " << robotData.analogInputCh2 << "\n";
|
||||
outputFile << "analogInputCh3: " << robotData.analogInputCh3 << "\n";
|
||||
outputFile << "digitalInput: " << robotData.digitalInput << "\n";
|
||||
outputFile << "timestamp: " << robotData.timestamp << "\n";
|
||||
outputFile << "BumperCenter: " << robotData.BumperCenter << "\n";
|
||||
outputFile << "BumperLeft: " << robotData.BumperLeft << "\n";
|
||||
outputFile << "BumperRight: " << robotData.BumperRight << "\n";
|
||||
outputFile << "WheelDropLeft: " << robotData.WheelDropLeft << "\n";
|
||||
outputFile << "WheelDropRight: " << robotData.WheelDropRight << "\n";
|
||||
outputFile << "CliffCenter: " << robotData.CliffCenter << "\n";
|
||||
outputFile << "CliffLeft: " << robotData.CliffLeft << "\n";
|
||||
outputFile << "CliffRight: " << robotData.CliffRight << "\n";
|
||||
outputFile << "EncoderLeft: " << robotData.EncoderLeft << "\n";
|
||||
outputFile << "EncoderRight: " << robotData.EncoderRight << "\n";
|
||||
outputFile << "PWMleft: " << robotData.PWMleft << "\n";
|
||||
outputFile << "PWMright: " << robotData.PWMright << "\n";
|
||||
outputFile << "ButtonPress: " << robotData.ButtonPress << "\n";
|
||||
outputFile << "Charger: " << robotData.Charger << "\n";
|
||||
outputFile << "Battery: " << robotData.Battery << "\n";
|
||||
outputFile << "overCurrent: " << robotData.overCurrent << "\n";
|
||||
outputFile << "IRSensorRight: " << robotData.IRSensorRight << "\n";
|
||||
outputFile << "IRSensorCenter: " << robotData.IRSensorCenter << "\n";
|
||||
outputFile << "IRSensorLeft: " << robotData.IRSensorLeft << "\n";
|
||||
outputFile << "GyroAngle: " << robotData.GyroAngle << "\n";
|
||||
outputFile << "GyroAngleRate: " << robotData.GyroAngleRate << "\n";
|
||||
outputFile << "CliffSensorRight: " << robotData.CliffSensorRight << "\n";
|
||||
outputFile << "CliffSensorCenter: " << robotData.CliffSensorCenter << "\n";
|
||||
outputFile << "CliffSensorLeft: " << robotData.CliffSensorLeft << "\n";
|
||||
outputFile << "wheelCurrentLeft: " << robotData.wheelCurrentLeft << "\n";
|
||||
outputFile << "wheelCurrentRight: " << robotData.wheelCurrentRight << "\n";
|
||||
outputFile << "frameId: " << robotData.frameId << "\n";
|
||||
outputFile << "HardwareVersionPatch: " << robotData.extraInfo.HardwareVersionPatch << "\n";
|
||||
outputFile << "HardwareVersionMinor: " << robotData.extraInfo.HardwareVersionMinor << "\n";
|
||||
outputFile << "HardwareVersionMajor: " << robotData.extraInfo.HardwareVersionMajor << "\n";
|
||||
outputFile << "FirmwareVersionPatch: " << robotData.extraInfo.FirmwareVersionPatch << "\n";
|
||||
outputFile << "FirmwareVersionMinor: " << robotData.extraInfo.FirmwareVersionMinor << "\n";
|
||||
outputFile << "FirmwareVersionMajor: " << robotData.extraInfo.FirmwareVersionMajor << "\n";
|
||||
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
|
||||
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
||||
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
||||
outputFile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error opening file\n";
|
||||
}
|
||||
|
||||
void logToFile(){
|
||||
std::ofstream outputFile("log");
|
||||
|
||||
if (outputFile.is_open()) { // check if the file was opened successfully
|
||||
outputFile << robot.parser.data.analogInputCh0; // write data to the file
|
||||
outputFile.close(); // close the file when done
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error opening file\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2)); // Sleep for 2 seconds
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user