made it so we can read indiviual buttons

This commit is contained in:
2024-10-22 15:10:08 +02:00
parent 1175444abf
commit 7fa04a5c35
4 changed files with 53 additions and 50 deletions

View File

@@ -1,8 +1,6 @@
#include "KobukiParser.h" #include "KobukiParser.h"
#include <iostream> #include <iostream>
//checkedValue const maken //moet checkenvalue gebruiken of moet kijken naar de payloadlength welke dingen er extra zijn
//bitwise operators nachecken met website van kobuki serial website
//cliffsensor kan rauwe getallen zijn
int KobukiParser::parseKobukiMessage(TKobukiData &output, unsigned char *data) { int KobukiParser::parseKobukiMessage(TKobukiData &output, unsigned char *data) {
int rtrnvalue = checkChecksum(data); int rtrnvalue = checkChecksum(data);
if (rtrnvalue != 0) { if (rtrnvalue != 0) {
@@ -127,7 +125,9 @@ void KobukiParser::parseBasicData(TKobukiData &output, unsigned char *data, int
checkedValue++; checkedValue++;
output.PWMright = data[checkedValue]; output.PWMright = data[checkedValue];
checkedValue++; checkedValue++;
output.ButtonPress = data[checkedValue]; output.ButtonPress1 = data[checkedValue] & 0x01;
output.ButtonPress2 = data[checkedValue] & 0x02;
output.ButtonPress3 = data[checkedValue] & 0x04;
checkedValue++; checkedValue++;
output.Charger = data[checkedValue]; output.Charger = data[checkedValue];
checkedValue++; checkedValue++;

View File

@@ -19,7 +19,8 @@ struct TKobukiData {
int CliffCenter, CliffLeft, CliffRight; int CliffCenter, CliffLeft, CliffRight;
int EncoderLeft, EncoderRight; int EncoderLeft, EncoderRight;
int PWMleft, PWMright; int PWMleft, PWMright;
int ButtonPress, Charger, Battery, overCurrent; int ButtonPress1, ButtonPress2, ButtonPress3;
int Charger, Battery, overCurrent;
int IRSensorRight, IRSensorCenter, IRSensorLeft; int IRSensorRight, IRSensorCenter, IRSensorLeft;
int GyroAngle, GyroAngleRate; int GyroAngle, GyroAngleRate;
int CliffSensorRight, CliffSensorCenter, CliffSensorLeft; int CliffSensorRight, CliffSensorCenter, CliffSensorLeft;

View File

@@ -15,11 +15,12 @@ int main()
unsigned char *null_ptr(0); unsigned char *null_ptr(0);
robot.startCommunication("/dev/ttyUSB0", true, null_ptr); robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
std::thread safety([&robot]() { robot.robotSafety(); }); // use a lambda function to call the member function std::thread safety([&robot]()
{ robot.robotSafety(); }); // use a lambda function to call the member function
safety.detach(); safety.detach();
thread movementThread(movement); thread movementThread(movement);
movementThread.join(); //so the program doesnt quit movementThread.join(); // so the program doesnt quit
return 0; return 0;
} }
@@ -42,7 +43,6 @@ int movement()
if (text == 1) if (text == 1)
{ {
robot.forward(400); robot.forward(400);
} }
else if (text == 2) else if (text == 2)
{ {
@@ -98,7 +98,9 @@ void logToFile()
outputFile << "EncoderRight: " << robotData.EncoderRight << "\n"; outputFile << "EncoderRight: " << robotData.EncoderRight << "\n";
outputFile << "PWMleft: " << robotData.PWMleft << "\n"; outputFile << "PWMleft: " << robotData.PWMleft << "\n";
outputFile << "PWMright: " << robotData.PWMright << "\n"; outputFile << "PWMright: " << robotData.PWMright << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress << "\n"; outputFile << "ButtonPress: " << robotData.ButtonPress1 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress2 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress3 << "\n";
outputFile << "Charger: " << robotData.Charger << "\n"; outputFile << "Charger: " << robotData.Charger << "\n";
outputFile << "Battery: " << robotData.Battery << "\n"; outputFile << "Battery: " << robotData.Battery << "\n";
outputFile << "overCurrent: " << robotData.overCurrent << "\n"; outputFile << "overCurrent: " << robotData.overCurrent << "\n";