mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
made it so we can read indiviual buttons
This commit is contained in:
@@ -671,7 +671,7 @@ void CKobuki::sendNullMessage(){
|
|||||||
0x00, // Placeholder for radius
|
0x00, // Placeholder for radius
|
||||||
0x00 // Placeholder for checksum
|
0x00 // Placeholder for checksum
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
message[10] = message[2] ^ message[3] ^ message[4] ^ message[5] ^ message[6] ^
|
message[10] = message[2] ^ message[3] ^ message[4] ^ message[5] ^ message[6] ^
|
||||||
message[7] ^ message[8] ^ message[9];
|
message[7] ^ message[8] ^ message[9];
|
||||||
|
@@ -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) {
|
||||||
@@ -110,7 +108,7 @@ void KobukiParser::parseBasicData(TKobukiData &output, unsigned char *data, int
|
|||||||
checkedValue += 2;
|
checkedValue += 2;
|
||||||
output.BumperCenter = (data[checkedValue] & 0x02) >> 1;
|
output.BumperCenter = (data[checkedValue] & 0x02) >> 1;
|
||||||
output.BumperLeft = (data[checkedValue] & 0x04) >> 2;
|
output.BumperLeft = (data[checkedValue] & 0x04) >> 2;
|
||||||
output.BumperRight = data[checkedValue] & 0x01;
|
output.BumperRight = data[checkedValue] & 0x01;
|
||||||
checkedValue++;
|
checkedValue++;
|
||||||
output.WheelDropLeft = (data[checkedValue] & 0x02) >> 1;
|
output.WheelDropLeft = (data[checkedValue] & 0x02) >> 1;
|
||||||
output.WheelDropRight = data[checkedValue] & 0x01;
|
output.WheelDropRight = data[checkedValue] & 0x01;
|
||||||
@@ -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++;
|
||||||
|
@@ -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;
|
||||||
|
@@ -12,60 +12,60 @@ void logToFile();
|
|||||||
|
|
||||||
int main()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkCenterCliff()
|
int checkCenterCliff()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
std::cout << robot.parser.data.CliffSensorRight << endl;
|
std::cout << robot.parser.data.CliffSensorRight << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int movement()
|
int movement()
|
||||||
{
|
{
|
||||||
int text;
|
int text;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
cout << "gimme input: ";
|
cout << "gimme input: ";
|
||||||
cin >> text;
|
cin >> text;
|
||||||
|
|
||||||
if (text == 1)
|
if (text == 1)
|
||||||
{
|
{
|
||||||
robot.forward(400);
|
robot.forward(400);
|
||||||
|
}
|
||||||
}
|
else if (text == 2)
|
||||||
else if (text == 2)
|
{
|
||||||
{
|
// 1 is full circle
|
||||||
// 1 is full circle
|
robot.Rotate(90);
|
||||||
robot.Rotate(90);
|
}
|
||||||
}
|
else if (text == 3)
|
||||||
else if (text == 3)
|
{
|
||||||
{
|
// Add your code here for text == 3
|
||||||
// Add your code here for text == 3
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
robot.doRotation(text);
|
||||||
robot.doRotation(text);
|
throw "NaN";
|
||||||
throw "NaN";
|
}
|
||||||
}
|
catch (const char *msg)
|
||||||
catch (const char *msg)
|
{
|
||||||
{
|
cerr << msg << endl;
|
||||||
cerr << msg << endl;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void logToFile()
|
void logToFile()
|
||||||
@@ -73,7 +73,7 @@ void logToFile()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
TKobukiData robotData = robot.parser.data;
|
TKobukiData robotData = robot.parser.data;
|
||||||
std::ofstream outputFile("log", std::ios_base::app); // Open file in append mode to not overwrite own content
|
std::ofstream outputFile("log", std::ios_base::app); // Open file in append mode to not overwrite own content
|
||||||
if (outputFile.is_open())
|
if (outputFile.is_open())
|
||||||
{ // check if the file was opened successfully
|
{ // check if the file was opened successfully
|
||||||
// Get current time
|
// Get current time
|
||||||
@@ -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";
|
||||||
@@ -122,7 +124,7 @@ void logToFile()
|
|||||||
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
|
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
|
||||||
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
||||||
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user