Error: Threads Multiple Definition of
I have two GUI exactly the same except a few alterations. I copy-paste the code and changed only the node.
Code:
#include "tum_ardrone_gui.h"
#include "RosThread.h"
//#include "PingThread.h"
#include "time.h"
//#include "../HelperFunctions.h"
#include "ros/ros.h"
#include "ros/package.h"
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <string.h>
int getdirtxt (std::string dir, std::vector<std::string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
std::cout << "Error(" << errno << ") opening " << dir << std::endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
std::string f = dirp->d_name;
if(f.size() > 4 && f.substr(f.size()-4) == ".txt")
files.push_back(std::string(dirp->d_name));
}
closedir(dp);
return 0;
}
tum_ardrone_gui::tum_ardrone_gui(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
rosThread = NULL;
sensGaz = sensYaw = sensRP = 1;
currentControlSource = CONTROL_NONE;
useHovering = true;
for(int i=0;i<8;i++)
{
isPressed[i] = false;
lastRepeat[i] = 0;
}
QObject::connect( this, SIGNAL(setCountsSignal(unsigned int,unsigned int,unsigned int,unsigned int) ),
this, SLOT( setCountsSlot(unsigned int,unsigned int,unsigned int,unsigned int) ) );
QObject::connect( this, SIGNAL( setPingsSignal(int, int) ),
this, SLOT( setPingsSlot(int, int) ) );
QObject::connect( this, SIGNAL( setControlSourceSignal(int) ),
this, SLOT( setControlSourceSlot(int) ) );
QObject::connect( this, SIGNAL( addLogLineSignal(QString) ),
this, SLOT( addLogLineSlot(QString) ) );
QObject::connect( this, SIGNAL( setAutopilotInfoSignal(QString) ),
this, SLOT( setAutopilotInfoSlot(QString) ) );
QObject::connect( this, SIGNAL( setStateestimationInfoSignal(QString) ),
this, SLOT( setStateestimationInfoSlot(QString) ) );
QObject::connect( this, SIGNAL( setMotorSpeedsSignal(QString) ),
this, SLOT( setMotorSpeedsSlot(QString) ) );
QObject::connect( this, SIGNAL( closeWindowSignal() ),
this, SLOT( closeWindowSlot() ) );
std::vector<std::string> files = std::vector<std::string>();
getdirtxt( ros::package::getPath("tum_ardrone") + std::string("/flightPlans/"),files);
ui.comboBoxLoadFile->addItem(QString(""), QVariant());
for(unsigned int i=0;i<files.size();i++)
ui.comboBoxLoadFile->addItem(QString(files[i].c_str()), QVariant());
}
tum_ardrone_gui::~tum_ardrone_gui()
{
}
// clicked functions
void tum_ardrone_gui::LandClicked()
{
rosThread->sendLand();
}
void tum_ardrone_gui::TakeoffClicked()
{
rosThread->sendTakeoff();
}
void tum_ardrone_gui::ToggleCamClicked()
{
rosThread->sendToggleCam();
}
void tum_ardrone_gui::FlattrimClicked()
{
rosThread->sendFlattrim();
}
void tum_ardrone_gui::EmergencyClicked()
{
rosThread->sendToggleState();
}
void tum_ardrone_gui::ClearClicked()
{
rosThread->publishCommand("c clearCommands");
}
void tum_ardrone_gui::SendClicked()
{
QStringList l = ui.plainTextEditSendCommand->toPlainText().split('\n');
for(int i=0;i<l.length();i++)
{
std::string s = l[i].trimmed().toStdString();
if(s.size() > 0)
rosThread->publishCommand(std::string("c ")+s);
}
setControlSource(CONTROL_AUTO);
}
void tum_ardrone_gui::ClearSendClicked()
{
ClearClicked();
SendClicked();
}
void tum_ardrone_gui::ResetClicked()
{
setControlSource(CONTROL_NONE);
ClearClicked();
rosThread->publishCommand("f reset");
}
void tum_ardrone_gui::LoadFileChanged(QString val)
{
if(val == "")
ui.plainTextEditSendCommand->setPlainText("");
else
{
std::string path = ros::package::getPath("tum_ardrone") + std::string("/flightPlans/") + val.toStdString();
addLogLine("Load File "+ path);
std::ifstream t;
t.open(path.c_str());
std::string buffer = "";
std::string line;
while(!t.eof())
{
std::getline(t, line);
buffer = buffer + line + "\n";
}
t.close();
ui.plainTextEditSendCommand->setPlainText(buffer.c_str());
}
}
void tum_ardrone_gui::ToggledUseHovering(int val)
{
useHovering = (val != 0);
}
void tum_ardrone_gui::ToggledPingDrone(int val)
{
pingThread->measure = (val != 0);
}
// change control source functions
void tum_ardrone_gui::ControlSourceChanged()
{
ControlSource s = CONTROL_NONE;
if(ui.radioButtonControKB->isChecked())
s = CONTROL_KB;
if(ui.radioButtonControlNone->isChecked())
s = CONTROL_NONE;
if(ui.radioButtonControlJoy->isChecked())
s = CONTROL_JOY;
if(ui.radioButtonControlAuto->isChecked())
s = CONTROL_AUTO;
if(s != CONTROL_AUTO)
rosThread->publishCommand("c stop");
else
rosThread->publishCommand("c ...