Commit d47dc9a9 authored by Valentin Platzgummer's avatar Valentin Platzgummer

bug appearded again

parent 29b83181
...@@ -719,27 +719,27 @@ void WimaController::_eventTimerHandler() ...@@ -719,27 +719,27 @@ void WimaController::_eventTimerHandler()
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
_pRosBridge->publish(_snakeTilesLocal, "/snake/tiles");
_pRosBridge->publish(_snakeOrigin, "/snake/origin"); _pRosBridge->publish(_snakeOrigin, "/snake/origin");
_pRosBridge->publish(_snakeTilesLocal, "/snake/tiles");
using namespace std::placeholders; // using namespace std::placeholders;
auto progressCallBack = std::bind(&WimaController::_progressFromJson, // auto progressCallBack = std::bind(&WimaController::_progressFromJson,
this, // this,
_1, // _1,
std::ref(_nemoProgress)); // std::ref(_nemoProgress));
_pRosBridge->subscribe("/nemo/progress", progressCallBack); // _pRosBridge->subscribe("/nemo/progress", progressCallBack);
_pRosBridge->subscribe("/nemo/heartbeat", [this, &nemoStatusTicker](JsonDocUPtr pDoc){ // _pRosBridge->subscribe("/nemo/heartbeat", [this, &nemoStatusTicker](JsonDocUPtr pDoc){
if ( !this->_pRosBridge->casePacker()->unpack(pDoc, this->_nemoHeartbeat) ) { // if ( !this->_pRosBridge->casePacker()->unpack(pDoc, this->_nemoHeartbeat) ) {
if ( this->_nemoHeartbeat.status() == this->_fallbackStatus ) // if ( this->_nemoHeartbeat.status() == this->_fallbackStatus )
return; // return;
this->_nemoHeartbeat.setStatus(this->_fallbackStatus); // this->_nemoHeartbeat.setStatus(this->_fallbackStatus);
} // }
nemoStatusTicker.reset(); // nemoStatusTicker.reset();
this->_fallbackStatus = -1; /*Timeout*/ // this->_fallbackStatus = -1; /*Timeout*/
emit WimaController::nemoStatusChanged(); // emit WimaController::nemoStatusChanged();
emit WimaController::nemoStatusStringChanged(); // emit WimaController::nemoStatusStringChanged();
}); // });
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();
qWarning() << "Duration: " << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() qWarning() << "Duration: " << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count()
......
...@@ -37,11 +37,6 @@ void ROSBridge::ComPrivate::TopicPublisher::start() ...@@ -37,11 +37,6 @@ void ROSBridge::ComPrivate::TopicPublisher::start()
if ( _running.load() ) // start called while thread running. if ( _running.load() ) // start called while thread running.
return; return;
_running.store(true); _running.store(true);
{
std::lock_guard<std::mutex> lk(*_rbcMutex);
_rbc->addClient(ROSBridge::ComPrivate::_topicAdvertiserKey);
_rbc->addClient(ROSBridge::ComPrivate::_topicPublisherKey);
}
ROSBridge::ComPrivate::ThreadData data{ ROSBridge::ComPrivate::ThreadData data{
*_casePacker, *_casePacker,
*_rbc, *_rbc,
...@@ -64,17 +59,19 @@ void ROSBridge::ComPrivate::TopicPublisher::reset() ...@@ -64,17 +59,19 @@ void ROSBridge::ComPrivate::TopicPublisher::reset()
if ( !_pThread ) if ( !_pThread )
return; return;
_pThread->join(); _pThread->join();
{
std::lock_guard<std::mutex> lk(*_rbcMutex);
_rbc->removeClient(ROSBridge::ComPrivate::_topicAdvertiserKey);
_rbc->removeClient(ROSBridge::ComPrivate::_topicPublisherKey);
}
_queue.clear(); _queue.clear();
_advertisedTopicsHashList.clear(); _advertisedTopicsHashList.clear();
} }
void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data) void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data)
{ {
// Init.
{
std::lock_guard<std::mutex> lk(data.rbcMutex);
data.rbc.addClient(ROSBridge::ComPrivate::_topicAdvertiserKey);
data.rbc.addClient(ROSBridge::ComPrivate::_topicPublisherKey);
}
// Main Loop.
while(data.running.load()){ while(data.running.load()){
std::unique_lock<std::mutex> lk(data.queueMutex); std::unique_lock<std::mutex> lk(data.queueMutex);
// Check if new data available, wait if not. // Check if new data available, wait if not.
...@@ -87,13 +84,6 @@ void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data ...@@ -87,13 +84,6 @@ void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data
data.queue.pop_front(); data.queue.pop_front();
lk.unlock(); lk.unlock();
// Debug output.
// std::cout << "Transmitter loop json document:" << std::endl;
// rapidjson::OStreamWrapper out(std::cout);
// rapidjson::Writer<rapidjson::OStreamWrapper> writer(out);
// pJsonDoc->Accept(writer);
// std::cout << std::endl << std::endl;
// Get tag from Json message and remove it. // Get tag from Json message and remove it.
Tag tag; Tag tag;
bool ret = data.casePacker.getTag(pJsonDoc, tag); bool ret = data.casePacker.getTag(pJsonDoc, tag);
...@@ -108,20 +98,28 @@ void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data ...@@ -108,20 +98,28 @@ void ROSBridge::ComPrivate::transmittLoop(ROSBridge::ComPrivate::ThreadData data
if ( data.advertisedTopicsHashList.count(hash) == 0) { if ( data.advertisedTopicsHashList.count(hash) == 0) {
data.advertisedTopicsHashList.insert(hash); data.advertisedTopicsHashList.insert(hash);
{ {
std::cout << ROSBridge::ComPrivate::_topicAdvertiserKey << ";"
<< tag.topic() << ";"
<< tag.messageType() << ";" << std::endl;
std::lock_guard<std::mutex> lk(data.rbcMutex); std::lock_guard<std::mutex> lk(data.rbcMutex);
data.rbc.advertise(ROSBridge::ComPrivate::_topicAdvertiserKey, data.rbc.advertise(ROSBridge::ComPrivate::_topicAdvertiserKey,
tag.topic(), tag.topic(),
tag.messageType() ); tag.messageType() );
} }
} }
// Debug output.
//std::cout << "Hash Set size: " << advertisedTopicsHashList.size() << std::endl;
// Send Json message. // Publish Json message.
{ {
std::lock_guard<std::mutex> lk(data.rbcMutex); std::lock_guard<std::mutex> lk(data.rbcMutex);
data.rbc.publish(tag.topic(), *pJsonDoc.get()); data.rbc.publish(tag.topic(), *pJsonDoc.get());
} }
} // while loop } // while loop
// Tidy up.
{
std::lock_guard<std::mutex> lk(data.rbcMutex);
data.rbc.removeClient(ROSBridge::ComPrivate::_topicAdvertiserKey);
data.rbc.removeClient(ROSBridge::ComPrivate::_topicPublisherKey);
}
} }
...@@ -36,11 +36,6 @@ public: ...@@ -36,11 +36,6 @@ public:
//! @brief Resets the publisher. //! @brief Resets the publisher.
void reset(); void reset();
template<class T>
void publish(const T &msg, const std::string &topic){
JsonDocUPtr docPtr(_casePacker->pack(msg, topic));
publish(std::move(docPtr));
}
void publish(JsonDocUPtr docPtr){ void publish(JsonDocUPtr docPtr){
{ {
std::lock_guard<std::mutex> lock(_queueMutex); std::lock_guard<std::mutex> lock(_queueMutex);
...@@ -49,6 +44,12 @@ public: ...@@ -49,6 +44,12 @@ public:
_cv.notify_one(); // Wake publisher thread. _cv.notify_one(); // Wake publisher thread.
} }
template<class T>
void publish(const T &msg, const std::string &topic){
JsonDocUPtr docPtr(_casePacker->pack(msg, topic));
publish(std::move(docPtr));
}
private: private:
JsonQueue _queue; JsonQueue _queue;
std::mutex _queueMutex; std::mutex _queueMutex;
......
...@@ -24,13 +24,13 @@ void ROSBridge::ComPrivate::TopicSubscriber::start() ...@@ -24,13 +24,13 @@ void ROSBridge::ComPrivate::TopicSubscriber::start()
void ROSBridge::ComPrivate::TopicSubscriber::reset() void ROSBridge::ComPrivate::TopicSubscriber::reset()
{ {
if ( _running ){ if ( _running ){
_running = false;
{ {
std::lock_guard<std::mutex> lk(*_rbcMutex); std::lock_guard<std::mutex> lk(*_rbcMutex);
for (std::string clientName : _clientList){ for (std::string clientName : _clientList){
_rbc->removeClient(clientName); _rbc->removeClient(clientName);
} }
} }
_running = false;
{ {
std::lock_guard<std::mutex> lk(_callbackMap.mutex); std::lock_guard<std::mutex> lk(_callbackMap.mutex);
_callbackMap.map.clear(); _callbackMap.map.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment