mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
got code from other branch
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include "KobukiDriver/graph.h"
|
||||
#include "MQTT/MqttClient.h"
|
||||
#include "KobukiDriver/CKobuki.h"
|
||||
|
||||
@@ -10,7 +9,7 @@ CKobuki robot;
|
||||
std::string readMQTT();
|
||||
void parseMQTT(std::string message);
|
||||
//ip, clientID, username, password
|
||||
MqttClient client("mqtt://145.92.224.21:1884", "KobukiRPI", "rpi", "rpiwachtwoordofzo"); // create a client object
|
||||
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi", "rpiwachtwoordofzo"); // create a client object
|
||||
std::string message = "stop";
|
||||
std::string serializeKobukiData(const TKobukiData &data);
|
||||
void sendKobukiData(TKobukiData &data);
|
||||
@@ -18,24 +17,27 @@ void sendKobukiData(TKobukiData &data);
|
||||
void setup()
|
||||
{
|
||||
unsigned char *null_ptr(0);
|
||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
// robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
//connect mqtt server and sub to commands
|
||||
|
||||
client.connect();
|
||||
client.subscribe("home/commands");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Unset the http_proxy environment variable
|
||||
|
||||
|
||||
setup();
|
||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
||||
|
||||
while(true){
|
||||
parseMQTT(readMQTT());
|
||||
parseMQTT(readMQTT());
|
||||
}
|
||||
sendMqtt.join();
|
||||
safety.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string readMQTT()
|
||||
@@ -270,6 +272,7 @@ std::string serializeKobukiData(const TKobukiData &data) {
|
||||
void sendKobukiData(TKobukiData &data) {
|
||||
while (true) {
|
||||
client.publishMessage("kobuki/data", serializeKobukiData(data));
|
||||
std::cout << "Sent data" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user