Skip to content
This repository has been archived by the owner on Feb 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #501 from fqez/issue_498
Browse files Browse the repository at this point in the history
[issue #498] Interfaces on demand for uav_viewer. Also minor GUI impr…
  • Loading branch information
fqez authored Jun 22, 2016
2 parents 240d4fe + 63a6bb9 commit 1d1d74c
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 47 deletions.
3 changes: 3 additions & 0 deletions src/stable/tools/uav_viewer/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ void MainWindow::initButtons(){
MainWindow::~MainWindow()
{
delete sensors;
delete vel;
delete dataw;
delete ui;

}

void MainWindow::updateThreadGUI()
Expand Down
22 changes: 17 additions & 5 deletions src/stable/tools/uav_viewer/gui/ui_mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,48 @@ class Ui_MainWindow
QLabel *imageLLabel;
QCheckBox *velBox;
QCheckBox *dataBox;
QLabel *velLabel;
QLabel *dataLabel;
QWidget *gps_tab;

void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(900, 620);
MainWindow->setMinimumSize(QSize(650, 620));
MainWindow->setMaximumSize(QSize(650, 620));
MainWindow->setMinimumSize(QSize(700, 620));
MainWindow->setMaximumSize(QSize(700, 620));

centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));

tabWidget = new QTabWidget(centralWidget);
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
tabWidget->setGeometry(QRect(10, 0, 630, 611));
tabWidget->setGeometry(QRect(10, 0, 680, 611));

view_tab = new QWidget();
view_tab->setObjectName(QString::fromUtf8("view_tab"));

battery = new QwtThermo(view_tab);
battery->setObjectName(QString::fromUtf8("battery"));
battery->setGeometry(QRect(530, 30, 56, 241));
battery->setGeometry(QRect(580, 50, 56, 241));
battery->setMaxValue(100);
batteryLabel = new QLabel(view_tab);
batteryLabel->setObjectName(QString::fromUtf8("batteryLabel"));
batteryLabel->setGeometry(QRect(540, 290, 51, 21));
batteryLabel->setGeometry(QRect(580, 310, 51, 21));

velBox = new QCheckBox(view_tab);
velBox->setObjectName(QString::fromUtf8("velBox"));
dataBox = new QCheckBox(view_tab);
dataBox->setObjectName(QString::fromUtf8("dataBox"));
velBox->setGeometry(550, 370, 20, 20);
dataBox->setGeometry(550, 400, 20, 20);
velLabel = new QLabel(view_tab);
velLabel->setObjectName(QString::fromUtf8("velLabel"));
velLabel->setGeometry(QRect(570, 370, 65, 21));
dataLabel = new QLabel(view_tab);
dataLabel->setObjectName(QString::fromUtf8("dataLabel"));
dataLabel->setGeometry(QRect(570, 400, 51, 21));

imageLabel = new QLabel(view_tab);
imageLabel->setObjectName(QString::fromUtf8("imageLabel"));
Expand Down Expand Up @@ -207,6 +217,8 @@ class Ui_MainWindow
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "uav_viewer", 0, QApplication::UnicodeUTF8));
batteryLabel->setText(QApplication::translate("MainWindow", "Battery", 0, QApplication::UnicodeUTF8));
velLabel->setText(QApplication::translate("MainWindow", "Velocities", 0, QApplication::UnicodeUTF8));
dataLabel->setText(QApplication::translate("MainWindow", "Data", 0, QApplication::UnicodeUTF8));
imageLabel->setText(QString());
controlBox->setTitle(QApplication::translate("MainWindow", "Control", 0, QApplication::UnicodeUTF8));
takeoff_button->setText(QApplication::translate("MainWindow", "take off", 0, QApplication::UnicodeUTF8));
Expand Down
2 changes: 2 additions & 0 deletions src/stable/tools/uav_viewer/gui/velwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ VelWidget::VelWidget(QWidget *parent) :
setUI();
}

VelWidget::~VelWidget(){}

void VelWidget::setSensors(Sensors* sensors){
this->sensors=sensors;
}
Expand Down
1 change: 1 addition & 0 deletions src/stable/tools/uav_viewer/gui/velwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class VelWidget: public QWidget
QwtDial *createDial(int pos);
void drawVelocitiesValues(float vlx,float vly,float vlz);
void setSensors(Sensors* sensors);
~VelWidget();



Expand Down
204 changes: 162 additions & 42 deletions src/stable/tools/uav_viewer/sensors/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,112 @@ Sensors::Sensors(Ice::CommunicatorPtr ic)
this-> ic = ic;
Ice::PropertiesPtr prop = ic->getProperties();
//Camera
jderobot::ImageDataPtr data;
Ice::ObjectPrx basecamera = ic->propertyToProxy("UAVViewer.Camera.Proxy");
if (0==basecamera)
throw "Could not create proxy";
if (0==basecamera) {
cameraON = false;
image.create(400, 400, CV_8UC3);
std::cout << "Camera configuration not specified" <<std::endl;
//throw "Could not create proxy";

/*cast to CameraPrx*/
cprx = jderobot::CameraPrx::checkedCast(basecamera);
if (0==cprx)
throw "Camera -> Invalid proxy";
}else{
try{
/*cast to CameraPrx*/
cprx = jderobot::CameraPrx::checkedCast(basecamera);
if (0==cprx)
throw "Camera -> Invalid proxy";

jderobot::ImageDataPtr data = cprx->getImageData("RGB8");
cameraON=true;
data = cprx->getImageData("RGB8");
}
catch(Ice::ConnectionRefusedException& e){
cameraON=false;
std::cout << "Camera inactive" << std::endl;

//create an empty image if no camera connected (avoid seg. fault)
image.create(400, 400, CV_8UC3);
}
}

//Navdata
Ice::ObjectPrx basenavdata = ic->propertyToProxy("UAVViewer.Navdata.Proxy");
if (0==basenavdata)
throw "Could not create proxy";
if (0==basenavdata){
navDataON = false;
std::cout << "NavData configuration not specified" <<std::endl;
//throw "Could not create proxy";
}else{
try{
/*cast to NavdataPrx*/
navprx = jderobot::NavdataPrx::checkedCast(basenavdata);
if (0==navprx)
throw "Navdata -> Invalid proxy";

navDataON = true;
}catch(Ice::ConnectionRefusedException& e){
navDataON = false;
std::cout << "NavData inactive" << std::endl;
}
}

/*cast to NavdataPrx*/
navprx = jderobot::NavdataPrx::checkedCast(basenavdata);
if (0==navprx)
throw "Navdata -> Invalid proxy";
//CMDVel
Ice::ObjectPrx basecmd = ic->propertyToProxy("UAVViewer.CMDVel.Proxy");
if (0==basecmd)
throw "Could not create proxy";
if (0==basecmd) {
cmdVelON = false;
std::cout << "CMDVel configuration not specified" <<std::endl;
//throw "Could not create proxy";
}else{
try{
/*cast to CMDVelPrx*/
cmdprx = jderobot::CMDVelPrx::checkedCast(basecmd);
if (0==cmdprx)
throw "CMDVel -> Invalid proxy";

cmdVelON = true;
}catch(Ice::ConnectionRefusedException& e){
cmdVelON = false;
std::cout << "CMDVel inactive" << std::endl;
}
}

/*cast to CMDVelPrx*/
cmdprx = jderobot::CMDVelPrx::checkedCast(basecmd);
if (0==cmdprx)
throw "CMDVel -> Invalid proxy";
//Pose3D
Ice::ObjectPrx basepose = ic->propertyToProxy("UAVViewer.Pose3D.Proxy");
if (0==basepose)
throw "Could not create proxy";
if (0==basepose){
pose3dON = false;
std::cout << "Pose3D configuration not specified" <<std::endl;
//throw "Could not create proxy";
}else{
try{
/*cast to Pose3DPrx*/
poseprx = jderobot::Pose3DPrx::checkedCast(basepose);
if (0==poseprx)
throw "Pose3D -> Invalid proxy";

/*cast to Pose3DPrx*/
poseprx = jderobot::Pose3DPrx::checkedCast(basepose);
if (0==poseprx)
throw "Pose3D -> Invalid proxy";
pose3dON = true;
}catch(Ice::ConnectionRefusedException& e) {
pose3dON = false;
std::cout << "Pose3D inactive" << std::endl;
}
}

//Pose3D
//Extra
Ice::ObjectPrx baseextra = ic->propertyToProxy("UAVViewer.Extra.Proxy");
if (0==baseextra)
throw "Could not create proxy";
if (0==baseextra){
extraON = false;
std::cout << "Extra configuration not specified" <<std::endl;
//throw "Could not create proxy";
}else{
try{
/*cast to ArDronePrx*/
arextraprx = jderobot::ArDroneExtraPrx::checkedCast(baseextra);
if (0==arextraprx)
throw "ArDroneExtra -> Invalid proxy";

/*cast to ArDronePrx*/
arextraprx = jderobot::ArDroneExtraPrx::checkedCast(baseextra);
if (0==arextraprx)
throw "ArDroneExtra -> Invalid proxy";
extraON = true;
}catch(Ice::ConnectionRefusedException& e){
extraON = false;
std::cout << "Pose3D inactive" << std::endl;
}
}

this->tracking=false;
this->flying=false;
Expand All @@ -75,20 +133,72 @@ void Sensors::sendVelocitiesToUAV(float vx,float vy,float vz,float roll,float pi
vel->angularX=roll;
vel->angularY=pitch;

cmdprx->setCMDVelData(vel);
if(cmdVelON)
cmdprx->setCMDVelData(vel);

mutexDrone.unlock();
}
void Sensors::update()
{
mutex.lock();
if(cameraON) {
jderobot::ImageDataPtr data = cprx->getImageData("RGB8");
image.create(data->description->height, data->description->width, CV_8UC3);
memcpy((unsigned char *) image.data ,&(data->pixelData[0]), image.cols*image.rows * 3);
}else{

//create empty image if the interface is not connected
image.create(400, 400, CV_8UC3);
}
mutex.unlock();
mutexDrone.lock();
navdata=navprx->getNavdata();
pose3DDataPtr = poseprx->getPose3DData();
if(navDataON)
navdata=navprx->getNavdata();
else{

//creating empty navdata if interface not connected
jderobot::NavdataDataPtr emptyNav = new jderobot::NavdataData();
emptyNav->vx = 0;
emptyNav->vy = 0;
emptyNav->vz = 0;
emptyNav->ax = 0;
emptyNav->ay = 0;
emptyNav->az = 0;
emptyNav->rotX = 0;
emptyNav->rotY = 0;
emptyNav->rotZ = 0;
emptyNav->batteryPercent = 0.0;
emptyNav->altd = 0;
emptyNav->vehicle = 0;
emptyNav->state = 0;
emptyNav->magX = 0;
emptyNav->magY = 0;
emptyNav->magZ = 0;
emptyNav->pressure = 0;
emptyNav->windAngle = 0.0;
emptyNav->windCompAngle = 0.0;
emptyNav->windSpeed = 0.0;
emptyNav->tagsCount = 0;

navdata = emptyNav;
}
if(pose3dON)
pose3DDataPtr = poseprx->getPose3DData();
else{

//create empty pose3d if interface not connected.
jderobot::Pose3DDataPtr emptyPose = new jderobot::Pose3DData();
emptyPose->h = 0.0;
emptyPose->x = 0.0;
emptyPose->y = 0.0;
emptyPose->z = 0.0;
emptyPose->q0 = 0.0;
emptyPose->q1 = 0.0;
emptyPose->q2 = 0.0;
emptyPose->q3 = 0.0;

pose3DDataPtr = emptyPose;
}
mutexDrone.unlock();

}
Expand Down Expand Up @@ -119,40 +229,50 @@ cv::Mat Sensors::getImage()

void Sensors::takeOff(){
mutexDrone.lock();
if(extraON){
if(!rst){
arextraprx->takeoff();
this->flying=true;
std::cout << "takeoff"<<std::endl;
}
}
mutexDrone.unlock();
}

void Sensors::land(){
mutexDrone.lock();

if(!rst){
jderobot::CMDVelDataPtr cmd=new jderobot::CMDVelData();
cmd->linearX=cmd->linearY=cmd->linearZ=0;
cmd->angularX=cmd->angularY=cmd->angularZ=0;
cmdprx->setCMDVelData(cmd);
arextraprx->land();
this->flying=false;
this->tracking=false;
if (cmdVelON) {
jderobot::CMDVelDataPtr cmd=new jderobot::CMDVelData();
cmd->linearX=cmd->linearY=cmd->linearZ=0;
cmd->angularX=cmd->angularY=cmd->angularZ=0;
cmdprx->setCMDVelData(cmd);
}
if (extraON) {
arextraprx->land();
this->flying=false;
this->tracking=false;
}
std::cout << "land"<<std::endl;
}
mutexDrone.unlock();
}

void Sensors::reset(){
mutexDrone.lock();
if(extraON){
arextraprx->reset();
this->flying=false;
this->tracking=false;
this->rst=!this->rst;
}
mutexDrone.unlock();
}

void Sensors::toggleCam(){
mutex.lock();
if(extraON)
arextraprx->toggleCam();
mutex.unlock();
}
Expand Down
6 changes: 6 additions & 0 deletions src/stable/tools/uav_viewer/sensors/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Sensors
bool flying;
bool rst;

bool cameraON;
bool navDataON;
bool cmdVelON;
bool pose3dON;
bool extraON;

};

#endif // SENSORS_H

0 comments on commit 1d1d74c

Please sign in to comment.