mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79
This commit is contained in:
@@ -781,6 +781,22 @@ void CKobuki::Rotate(int degrees) {
|
||||
}
|
||||
|
||||
|
||||
void CKobuki::robotSafety(std::string *pointerToMessage) {
|
||||
while (true) {
|
||||
|
||||
if (parser.data.BumperCenter || parser.data.BumperLeft || parser.data.BumperRight ||
|
||||
parser.data.CliffLeft || parser.data.CliffCenter || parser.data.CliffRight) {
|
||||
std::cout << "Safety condition triggered!" << std::endl; // Debug print
|
||||
*pointerToMessage = "stop";
|
||||
forward(-100); // reverse the robot
|
||||
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CKobuki::robotSafety() {
|
||||
while (true) {
|
||||
|
||||
|
@@ -76,7 +76,8 @@ public:
|
||||
void goToXy(long double xx, long double yy);
|
||||
void Rotate(int degrees);
|
||||
std::ofstream odometry_log;
|
||||
void robotSafety();
|
||||
void robotSafety(std::string *pointerToMessage);
|
||||
void robotSafety(); //overload
|
||||
void sendNullMessage();
|
||||
KobukiParser parser;
|
||||
|
||||
|
@@ -12,26 +12,30 @@ int movement();
|
||||
std::string readMQTT();
|
||||
void parseMQTT(std::string message);
|
||||
MqttClient client("mqtt://145.92.224.21:1883", "KobukiRPI", "ishak", "kobuki"); //create a client object
|
||||
|
||||
std::string message = "stop";
|
||||
|
||||
void setup(){
|
||||
unsigned char *null_ptr(0);
|
||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
client.connect();
|
||||
client.subscribe("home/commands");
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
||||
while(true){
|
||||
parseMQTT(readMQTT());
|
||||
}
|
||||
safety.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string readMQTT()
|
||||
{
|
||||
std::string message = client.getLastMessage();
|
||||
message = client.getLastMessage();
|
||||
if (!message.empty()) {
|
||||
std::cout << "MQTT Message: " << message << std::endl;
|
||||
}
|
||||
@@ -43,20 +47,21 @@ std::string readMQTT()
|
||||
|
||||
void parseMQTT(std::string message){
|
||||
if(message == "up"){
|
||||
robot.forward(600);
|
||||
robot.forward(1024);
|
||||
}
|
||||
else if(message == "left"){
|
||||
robot.Rotate(90);
|
||||
robot.Rotate(45);
|
||||
|
||||
}
|
||||
else if(message == "right"){
|
||||
robot.Rotate(-90);
|
||||
robot.Rotate(-45);
|
||||
}
|
||||
else if(message == "down"){
|
||||
robot.forward(600);
|
||||
robot.forward(-800);
|
||||
}
|
||||
else if(message == "stop"){
|
||||
robot.sendNullMessage();
|
||||
this_thread::sleep_for(chrono::milliseconds(1000));
|
||||
}
|
||||
else{
|
||||
std::cout << "Invalid command" << std::endl;
|
||||
|
Reference in New Issue
Block a user