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:
@@ -1,8 +1,6 @@
|
||||
#include "KobukiParser.h"
|
||||
#include <iostream>
|
||||
//checkedValue const maken
|
||||
//bitwise operators nachecken met website van kobuki serial website
|
||||
//cliffsensor kan rauwe getallen zijn
|
||||
//moet checkenvalue gebruiken of moet kijken naar de payloadlength welke dingen er extra zijn
|
||||
int KobukiParser::parseKobukiMessage(TKobukiData &output, unsigned char *data) {
|
||||
int rtrnvalue = checkChecksum(data);
|
||||
if (rtrnvalue != 0) {
|
||||
@@ -127,7 +125,9 @@ void KobukiParser::parseBasicData(TKobukiData &output, unsigned char *data, int
|
||||
checkedValue++;
|
||||
output.PWMright = data[checkedValue];
|
||||
checkedValue++;
|
||||
output.ButtonPress = data[checkedValue];
|
||||
output.ButtonPress1 = data[checkedValue] & 0x01;
|
||||
output.ButtonPress2 = data[checkedValue] & 0x02;
|
||||
output.ButtonPress3 = data[checkedValue] & 0x04;
|
||||
checkedValue++;
|
||||
output.Charger = data[checkedValue];
|
||||
checkedValue++;
|
||||
|
@@ -19,7 +19,8 @@ struct TKobukiData {
|
||||
int CliffCenter, CliffLeft, CliffRight;
|
||||
int EncoderLeft, EncoderRight;
|
||||
int PWMleft, PWMright;
|
||||
int ButtonPress, Charger, Battery, overCurrent;
|
||||
int ButtonPress1, ButtonPress2, ButtonPress3;
|
||||
int Charger, Battery, overCurrent;
|
||||
int IRSensorRight, IRSensorCenter, IRSensorLeft;
|
||||
int GyroAngle, GyroAngleRate;
|
||||
int CliffSensorRight, CliffSensorCenter, CliffSensorLeft;
|
||||
|
@@ -12,60 +12,60 @@ void logToFile();
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char *null_ptr(0);
|
||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
unsigned char *null_ptr(0);
|
||||
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();
|
||||
|
||||
thread movementThread(movement);
|
||||
movementThread.join(); //so the program doesnt quit
|
||||
return 0;
|
||||
movementThread.join(); // so the program doesnt quit
|
||||
return 0;
|
||||
}
|
||||
|
||||
int checkCenterCliff()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::cout << robot.parser.data.CliffSensorRight << endl;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
std::cout << robot.parser.data.CliffSensorRight << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int movement()
|
||||
{
|
||||
int text;
|
||||
while (true)
|
||||
{
|
||||
int text;
|
||||
while (true)
|
||||
{
|
||||
cout << "gimme input: ";
|
||||
cin >> text;
|
||||
cin >> text;
|
||||
|
||||
if (text == 1)
|
||||
{
|
||||
if (text == 1)
|
||||
{
|
||||
robot.forward(400);
|
||||
|
||||
}
|
||||
else if (text == 2)
|
||||
{
|
||||
// 1 is full circle
|
||||
robot.Rotate(90);
|
||||
}
|
||||
else if (text == 3)
|
||||
{
|
||||
// Add your code here for text == 3
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
robot.doRotation(text);
|
||||
throw "NaN";
|
||||
}
|
||||
catch (const char *msg)
|
||||
{
|
||||
cerr << msg << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (text == 2)
|
||||
{
|
||||
// 1 is full circle
|
||||
robot.Rotate(90);
|
||||
}
|
||||
else if (text == 3)
|
||||
{
|
||||
// Add your code here for text == 3
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
robot.doRotation(text);
|
||||
throw "NaN";
|
||||
}
|
||||
catch (const char *msg)
|
||||
{
|
||||
cerr << msg << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void logToFile()
|
||||
@@ -73,7 +73,7 @@ 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
|
||||
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
|
||||
@@ -98,7 +98,9 @@ void logToFile()
|
||||
outputFile << "EncoderRight: " << robotData.EncoderRight << "\n";
|
||||
outputFile << "PWMleft: " << robotData.PWMleft << "\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 << "Battery: " << robotData.Battery << "\n";
|
||||
outputFile << "overCurrent: " << robotData.overCurrent << "\n";
|
||||
@@ -122,7 +124,7 @@ void logToFile()
|
||||
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
|
||||
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
||||
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
||||
outputFile.close();
|
||||
outputFile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user