diff --git a/control/gcs/develop/xtdrone_qt/README.md b/control/gcs/develop/xtdrone_qt/README.md new file mode 100644 index 0000000..e69de29 diff --git a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/formrviz.h b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/formrviz.h new file mode 100644 index 0000000..302e47a --- /dev/null +++ b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/formrviz.h @@ -0,0 +1,29 @@ +#ifndef FORMRVIZ_H +#define FORMRVIZ_H + +#include + +namespace Ui { +class FormRviz; +} + +class FormRviz : public QWidget +{ + Q_OBJECT + +public: + explicit FormRviz(QWidget *parent = nullptr); + ~FormRviz(); + +private slots: + void on_button_image_cancel_clicked(); + void on_button_image_ok_clicked(); + +signals: + void rviz_to_main(QString); + +private: + Ui::FormRviz *ui; +}; + +#endif // FORMRVIZ_H diff --git a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/main_window.hpp b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/main_window.hpp index c1024e8..b11f89d 100644 --- a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/main_window.hpp +++ b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/main_window.hpp @@ -16,6 +16,7 @@ #include "ui_main_window.h" #include "qnode.hpp" #include "form.h" +#include "formrviz.h" #include "qrviz.hpp" #include #include @@ -24,6 +25,8 @@ #include #include #include +#include +#include /***************************************************************************** ** Namespace @@ -86,6 +89,21 @@ public: int plot_count = 0; int randnum; QColor color; + QComboBox* fixed_box; + QSpinBox* Cell_count_box; + QComboBox* Grid_color_box; + QComboBox* Laser_topic_box; + std::vector Pose_Check; + std::vector Image_Check; + std::vector Image_topic_box; + std::vector Pose_topic_box; + std::vector Pose_color_box; + std::vector Pose_shape_box; + QCheckBox* Tf_showname_Check; + int pose_num=0; + int image_num=0; + QSignalMapper* signalMapper_image; + QSignalMapper* signalMapper_pose; void ReadSettings(); // Load up qt program settings at startup @@ -115,7 +133,17 @@ public Q_SLOTS: void slot_quick_output(); void slot_box_maps_change(const QString); void slot_update_plot(float, float); - + void slot_treewidget_value_change(QString); + void slot_display_grid(int); + void slot_display_tf(int); + void slot_display_Laser(int); + void slot_display_Image(int); + void slot_display_Pose(int); + void slot_btn_add_click(bool); + void slot_addrviz(QString); + void slot_btn_estimate_click(bool); + void slot_btn_goal_click(bool); + void slot_rviz_control(); private: void init_uisettings(); Ui::MainWindowDesign ui; diff --git a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qnode.hpp b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qnode.hpp index 3511517..441a8cf 100644 --- a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qnode.hpp +++ b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qnode.hpp @@ -32,6 +32,9 @@ #include //#include #include +#include +#include +#include /***************************************************************************** @@ -79,6 +82,11 @@ public: void stop_control(bool q_stop_flag); void get_uav_control(LISTINT multirotor_get_control); void run(); + geometry_msgs::Pose goal_pose; + bool get_goal_flag = false; + double roll, pitch, yaw; + tf::Quaternion quat; + int count_control = 0; @@ -100,6 +108,7 @@ Q_SIGNALS: void loggingUpdated(); void rosShutdown(); void uavposition(float posi_x, float posi_y); + void rvizsetgoal(); private: int init_argc; @@ -115,7 +124,12 @@ private: ros::Publisher leader_cmd_vel_flu_pub; ros::Publisher leader_cmd_accel_flu_pub; ros::Publisher leader_cmd_pub; + ros::Publisher path_pub; void publish(); + ros::Subscriber goal_sub; + void goal_callback(const geometry_msgs::PoseStamped &msg); + geometry_msgs::Twist get_uav_control(double distance, int control_num); + double pos2ang(double xa, double ya, double xb, double yb); }; diff --git a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qrviz.hpp b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qrviz.hpp index 9802ff3..c217cf0 100644 --- a/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qrviz.hpp +++ b/control/gcs/develop/xtdrone_qt/include/xtdrone_qt/qrviz.hpp @@ -14,8 +14,25 @@ class qrviz { public: qrviz(QVBoxLayout* layout); + void Set_FixedFrame(QString Frame_name); + void Display_Grid(int Cell_count, QColor color, bool enable); + void Display_TF(bool enable1, bool enable); + void Display_LaserScan(QString laser_topic, bool enable); + void Display_Image(QString Image_topic, bool enable, int num); + void Display_Pose(QString pose_topic, QString pose_shape, QColor color, bool enable, int num); + void Set_start_pose(); + void Set_goal_pose(); private: rviz::RenderPanel* render_panel; + rviz::VisualizationManager* manager; + rviz::Display* Grid = NULL; + rviz::Display* Tf = NULL; + rviz::Display* Laser = NULL; + std::vector Image; + std::vector Pose; + rviz::ToolManager* tool_manager; + int count_pose_num[20]={0}; + int count_image_num[20]={0}; }; #endif // QRVIZ_HPP diff --git a/control/gcs/develop/xtdrone_qt/src/formrviz.cpp b/control/gcs/develop/xtdrone_qt/src/formrviz.cpp new file mode 100644 index 0000000..0fb9cb3 --- /dev/null +++ b/control/gcs/develop/xtdrone_qt/src/formrviz.cpp @@ -0,0 +1,49 @@ +#include "../include/xtdrone_qt/formrviz.h" +#include "ui_formrviz.h" + +FormRviz::FormRviz(QWidget *parent) : + QWidget(parent), + ui(new Ui::FormRviz) +{ + ui->setupUi(this); +} + +FormRviz::~FormRviz() +{ + delete ui; +} + + +void FormRviz::on_button_image_cancel_clicked() +{ + this->hide(); +} + +void FormRviz::on_button_image_ok_clicked() +{ + if (ui->button_image_camera->isChecked()) + { + emit rviz_to_main("image"); + this->hide(); + } + else if(ui->button_image_tf->isChecked()) + { + emit rviz_to_main("tf"); + this->hide(); + } + else if(ui->button_image_laser->isChecked()) + { + emit rviz_to_main("laser"); + this->hide(); + } + else if(ui->button_image_addtopic->isChecked()) + { + QString topic = ui->edit_addtopic->text(); + emit rviz_to_main(topic); + this->hide(); + } + else + this->hide(); + + +} diff --git a/control/gcs/develop/xtdrone_qt/src/main_window.cpp b/control/gcs/develop/xtdrone_qt/src/main_window.cpp index c3204ac..074c821 100644 --- a/control/gcs/develop/xtdrone_qt/src/main_window.cpp +++ b/control/gcs/develop/xtdrone_qt/src/main_window.cpp @@ -107,15 +107,41 @@ MainWindow::MainWindow(int argc, char** argv, QWidget *parent) QTreeWidgetItem* Global = new QTreeWidgetItem(QStringList()<<"Global Options"); ui.treeWidget->addTopLevelItem(Global); Global->setExpanded(true); + // FixFrame QTreeWidgetItem* Fixed_frame = new QTreeWidgetItem(QStringList()<<"Fixed Frame"); - QComboBox* fixed_box = new QComboBox(); + fixed_box = new QComboBox(); fixed_box->addItem("map"); - fixed_box->setMaximumWidth(100); + fixed_box->addItem("base_footprint"); + fixed_box->addItem("laser"); + fixed_box->setMaximumWidth(120); fixed_box->setEditable(true); + connect(fixed_box,SIGNAL(currentTextChanged(QString)),this,SLOT(slot_treewidget_value_change(QString))); Global->addChild(Fixed_frame); ui.treeWidget->setItemWidget(Fixed_frame,1,fixed_box); ui.treeWidget->header()->setMaximumSectionSize(150); ui.treeWidget->header()->setDefaultSectionSize(150); + // Grid + QTreeWidgetItem* Grid = new QTreeWidgetItem(QStringList()<<"Grid"); + QCheckBox* Grid_Check = new QCheckBox(); + connect(Grid_Check, SIGNAL(stateChanged(int)), this, SLOT(slot_display_grid(int))); + ui.treeWidget->addTopLevelItem(Grid); + ui.treeWidget->setItemWidget(Grid,1,Grid_Check); + Grid->setExpanded(true); + QTreeWidgetItem* Cell_count = new QTreeWidgetItem(QStringList()<<"Cell Count"); + Grid->addChild(Cell_count); + Cell_count_box = new QSpinBox(); + Cell_count_box->setValue(15); + Cell_count_box->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Cell_count,1,Cell_count_box); + QTreeWidgetItem* Grid_color = new QTreeWidgetItem(QStringList()<<"Color"); + Grid->addChild(Grid_color); + Grid_color_box = new QComboBox(); + Grid_color_box->addItem("160;160;160"); + Grid_color_box->setEditable(true); + Grid_color_box->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Grid_color,1,Grid_color_box); + signalMapper_image = new QSignalMapper(this); + signalMapper_pose = new QSignalMapper(this); } @@ -184,6 +210,10 @@ void MainWindow::ReadSettings() { connect(ui.button_connect,SIGNAL(clicked(bool)),this,SLOT(slot_btn_connect_click(bool))); connect(ui.comboBox_maps,SIGNAL(currentTextChanged(const QString)),this,SLOT(slot_box_maps_change(const QString))); connect(&qnode, SIGNAL(uavposition(float, float)),this,SLOT(slot_update_plot(float, float))); + connect(ui.button_add, SIGNAL(clicked(bool)),this,SLOT(slot_btn_add_click(bool))); + connect(ui.button_estimate, SIGNAL(clicked(bool)),this,SLOT(slot_btn_estimate_click(bool))); + connect(ui.button_goal, SIGNAL(clicked(bool)),this,SLOT(slot_btn_goal_click(bool))); + connect(&qnode, SIGNAL(rvizsetgoal()),this,SLOT(slot_rviz_control())); } void MainWindow::WriteSettings() { @@ -208,7 +238,6 @@ void MainWindow::Seriesint(int ch) color.setBlue(randnum); color_plot.push_back(color); seriesList[ch]->setPen(QPen(color,2,Qt::SolidLine)); - qDebug()<<"colot_polt"; chart->setAxisX(axisX, seriesList[ch]); chart->setAxisY(axisY, seriesList[ch]); } @@ -238,6 +267,9 @@ void MainWindow::init_uisettings() ui.checkBox_quadplane->setCheckable(false); ui.checkBox_tiltrotor->setCheckable(false); ui.checkBox_tailsitter->setCheckable(false); +// ui.button_add->setChecked(false); +// ui.button_add->setEnabled(false); + once_flag = 0; twice_flag = 0; ui.box_go_and_back_2->setProperty("value", 0.0); @@ -397,10 +429,13 @@ void MainWindow::slot_btn_run_click(bool) if ( !qnode.init(multirotor_select, multirotor_num, multi_type,control_type.toStdString())) { //toStdString() showNoMasterMessage(); + ui.treeWidget->setEnabled(false); } else { ui.button_run->setEnabled(false); ui.button_control->setEnabled(true); my_rviz = new qrviz(ui.verticalLayout_rviz); + ui.treeWidget->setEnabled(true); +// ui.button_add->setEnabled(true); } } @@ -435,7 +470,7 @@ void MainWindow::slot_quick_output() ui.launch_info_text->append(""+launch_cmd->readAllStandardError()+""); ui.launch_info_text->append(""+launch_cmd->readAllStandardOutput()+""); } -void MainWindow::slot_box_valuechange(double value) +void MainWindow::slot_box_valuechange(double) { qDebug()<<"change!!!"; double forward_change = ui.box_go_and_back_2->value(); @@ -448,7 +483,7 @@ void MainWindow::slot_box_valuechange(double value) qnode.set_cmd(forward_change, upward_change, leftward_change, orientation_change, ctrl_leader, cmd3, cmd_vel_mask); } -void MainWindow::box_command_valuechange(const QString value) +void MainWindow::box_command_valuechange(const QString) { qDebug()<<"change!!!"; double forward_change = ui.box_go_and_back_2->value(); @@ -580,7 +615,7 @@ QString MainWindow::box_formation_valuechange(const QString formation_mid) return formation2; } -void MainWindow::slot_checkbox_get_uav_control(int value) +void MainWindow::slot_checkbox_get_uav_control(int) { multirotor_get_control.clear(); for (int i = 0; iappend(x_position, y_position); // if (plot_count==1 ||plot_count ==5) // { - qDebug()<<"series"<Set_FixedFrame(fixed_box->currentText()); +} + +void MainWindow::slot_display_grid(int state) +{ + bool enable=state>1?true:false; + QStringList cut_color = Grid_color_box->currentText().split(";"); + QColor color = QColor(cut_color[0].toInt(),cut_color[1].toInt(),cut_color[2].toInt()); + my_rviz->Display_Grid(Cell_count_box->text().toInt(), color, enable); +} + +void MainWindow::slot_display_tf(int state) +{ + bool enable=state>1?true:false; + int state1 = Tf_showname_Check->checkState(); + bool enable1=state1>1?true:false; + my_rviz->Display_TF(enable1, enable); +} + +void MainWindow::slot_display_Laser(int state) +{ + bool enable=state>1?true:false; + my_rviz->Display_LaserScan(Laser_topic_box->currentText(),enable); +} + +void MainWindow::slot_display_Image(int num) +{ + bool enable = Image_Check[num]->checkState()>1?true:false; + my_rviz->Display_Image(Image_topic_box[num]->currentText(),enable, num); +} + +void MainWindow::slot_display_Pose(int num) +{ + bool enable = Pose_Check[num]->checkState()>1?true:false; + QStringList cut_color = Pose_color_box[num]->currentText().split(";"); + QColor color = QColor(cut_color[0].toInt(),cut_color[1].toInt(),cut_color[2].toInt()); + my_rviz->Display_Pose(Pose_topic_box[num]->currentText(),Pose_shape_box[num]->currentText(),color,enable,num); + qDebug()<<"test!!!"; +} + +void MainWindow::slot_btn_add_click(bool) +{ + FormRviz* frviz=new FormRviz; + frviz->show(); + connect(frviz,SIGNAL(rviz_to_main(QString)),this,SLOT(slot_addrviz(QString))); +} + +void MainWindow::slot_addrviz(QString value) +{ + qDebug()<addTopLevelItem(TF); + ui.treeWidget->setItemWidget(TF,1,TF_Check); + QTreeWidgetItem* Tf_showname = new QTreeWidgetItem(QStringList()<<"Show Names"); + TF->addChild(Tf_showname); + Tf_showname_Check = new QCheckBox(); + ui.treeWidget->setItemWidget(Tf_showname,1,Tf_showname_Check); + Tf_showname_Check->setCheckState(Qt::CheckState(2)); + } + else if (value == "laser") + { + //Laser + QTreeWidgetItem* Laser = new QTreeWidgetItem(QStringList()<<"Laser Scan"); + QCheckBox* Laser_Check = new QCheckBox(); + connect(Laser_Check, SIGNAL(stateChanged(int)), this, SLOT(slot_display_Laser(int))); + ui.treeWidget->addTopLevelItem(Laser); + ui.treeWidget->setItemWidget(Laser,1,Laser_Check); + QTreeWidgetItem* Laser_topic = new QTreeWidgetItem(QStringList()<<"Topic"); + Laser->addChild(Laser_topic); + Laser_topic_box = new QComboBox(); + Laser_topic_box->addItem("/scan"); + Laser_topic_box->setEditable(true); + Laser_topic_box->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Laser_topic,1,Laser_topic_box); + } + else if (value == "image") + { + //Image + QTreeWidgetItem* Image = new QTreeWidgetItem(QStringList()<<"Image"); + Image_Check.push_back(new QCheckBox()); + connect(Image_Check[image_num], SIGNAL(stateChanged(int)), signalMapper_image, SLOT(map())); + signalMapper_image->setMapping(Image_Check[image_num],image_num); + connect(signalMapper_image,SIGNAL(mapped(int)),this,SLOT(slot_display_Image(int))); + ui.treeWidget->addTopLevelItem(Image); + ui.treeWidget->setItemWidget(Image,1,Image_Check[image_num]); + QTreeWidgetItem* Image_topic = new QTreeWidgetItem(QStringList()<<"Topic"); + Image->addChild(Image_topic); + Image_topic_box.push_back( new QComboBox()); + Image_topic_box[image_num]->addItem(""); + Image_topic_box[image_num]->setEditable(true); + Image_topic_box[image_num]->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Image_topic,1,Image_topic_box[image_num]); + image_num++; + } + else + { + value.remove(QChar('\n'), Qt::CaseInsensitive); + //Add topic + QTreeWidgetItem* Pose = new QTreeWidgetItem(QStringList()<<"Pose"); + Pose_Check.push_back(new QCheckBox()); + connect(Pose_Check[pose_num], SIGNAL(stateChanged(int)), signalMapper_pose, SLOT(map())); + signalMapper_pose->setMapping(Pose_Check[pose_num],pose_num); + connect(signalMapper_pose,SIGNAL(mapped(int)),this,SLOT(slot_display_Pose(int))); + ui.treeWidget->addTopLevelItem(Pose); + ui.treeWidget->setItemWidget(Pose,1,Pose_Check[pose_num]); + QTreeWidgetItem* Pose_topic = new QTreeWidgetItem(QStringList()<<"Topic"); + Pose->addChild(Pose_topic); + Pose_topic_box.push_back(new QComboBox()); + Pose_topic_box[pose_num]->addItem(value); + Pose_topic_box[pose_num]->setEditable(true); + Pose_topic_box[pose_num]->setMaximumWidth(200); + ui.treeWidget->setItemWidget(Pose_topic,1,Pose_topic_box[pose_num]); + QTreeWidgetItem* Pose_color = new QTreeWidgetItem(QStringList()<<"Color"); + Pose->addChild(Pose_color); + Pose_color_box.push_back(new QComboBox()); + Pose_color_box[pose_num]->addItem("160;160;160"); + Pose_color_box[pose_num]->setEditable(true); + Pose_color_box[pose_num]->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Pose_color,1,Pose_color_box[pose_num]); + QTreeWidgetItem* Pose_shape = new QTreeWidgetItem(QStringList()<<"Shape"); + Pose->addChild(Pose_shape); + Pose_shape_box.push_back(new QComboBox()); + Pose_shape_box[pose_num]->addItem("Axes"); + Pose_shape_box[pose_num]->addItem("Arrow"); + Pose_shape_box[pose_num]->setEditable(true); + Pose_shape_box[pose_num]->setMaximumWidth(120); + ui.treeWidget->setItemWidget(Pose_shape,1,Pose_shape_box[pose_num]); + pose_num++; + } +} + +void MainWindow::slot_btn_estimate_click(bool) +{ + my_rviz->Set_start_pose(); +} + +void MainWindow::slot_btn_goal_click(bool) +{ + my_rviz->Set_goal_pose(); +} +void MainWindow::slot_rviz_control() +{ + ui.box_go_and_back_2->setProperty("value", 0.0); + ui.box_up_and_down_2->setProperty("value", 0.0); + ui.box_left_and_right_2->setProperty("value", 0.0); + ui.box_orientation->setProperty("value", 0.0); +} } // namespace xtdrone_qt diff --git a/control/gcs/develop/xtdrone_qt/src/qnode.cpp b/control/gcs/develop/xtdrone_qt/src/qnode.cpp index c5cb7bd..34bcbb2 100644 --- a/control/gcs/develop/xtdrone_qt/src/qnode.cpp +++ b/control/gcs/develop/xtdrone_qt/src/qnode.cpp @@ -18,6 +18,8 @@ #include "../include/xtdrone_qt/qnode.hpp" //#include #include "QDebug" +#include + typedef QList LISTTWIST; typedef QList LISTPOSE; @@ -51,9 +53,9 @@ QNode::~QNode() { *****************************************************************************/ -void odm_groundtruth_callback(const nav_msgs::Odometry::ConstPtr& msg, int num_odm, geometry_msgs::Pose local_pose[]) +void odm_groundtruth_callback(const geometry_msgs::PoseStamped::ConstPtr& msg, int num_odm, geometry_msgs::Pose local_pose[]) { - local_pose[num_odm] = msg->pose.pose; + local_pose[num_odm] = msg->pose; // qDebug()<<"pose::"<("chatter_0", 1000); + goal_sub = n.subscribe("/move_base_simple/goal", 1000, &QNode::goal_callback, this); + path_pub = n.advertise("trajectory", 1, true); if (control_type == "vel") { for (int i = 0; i < leng_select; i ++) @@ -129,7 +133,7 @@ bool QNode::init(const LISTINT multi_select, const int *multi_num, const LISTSTR } else { - buffer_multi_cmd_vel_flu_pub.push_back(n.advertise("/xtdrone/"+multi_type[counnnnnt]+"_"+std::to_string(k)+"/cmd_vel_flu", 1000)); + buffer_multi_cmd_vel_flu_pub.push_back(n.advertise("/xtdrone/"+multi_type[counnnnnt]+"_"+std::to_string(k)+"/cmd_vel_enu", 1000)); buffer_multi_cmd_pub.push_back(n.advertise("/xtdrone/"+multi_type[counnnnnt]+"_"+std::to_string(k)+"/cmd",1000)); qDebug()<<"multi_type"<("/xtdrone/"+multi_type[counnnt]+'_'+std::to_string(k)+"/ground_truth/odom", 1000, boost::bind(&odm_groundtruth_callback, _1, counnnt, local_pose))); + buffer_multi_odom_groundtruth_sub.push_back(n.subscribe(multi_type[counnnt]+'_'+std::to_string(k)+"/mavros/local_position/pose", 1000, boost::bind(&odm_groundtruth_callback, _1, counnnt, local_pose))); counnnt ++; } } @@ -218,6 +222,17 @@ void QNode::start_control(bool q_start_control_flag) qDebug()<<"control!!!"; } +void QNode::goal_callback(const geometry_msgs::PoseStamped &msg) +{ + goal_pose.position.x = msg.pose.position.x; + goal_pose.position.y = msg.pose.position.y; + get_goal_flag = true; + qDebug()<<"goal x:"< 3) + { + arrive_flag = true; + arrive_count = 0; + get_goal_flag = false; + } + else + arrive_flag = false; + } + else + { + arrive_count = 0; + arrive_flag = false; + } + if (!arrive_flag) + { + tf::quaternionMsgToTF(local_pose[control_num].orientation, quat); + tf::Matrix3x3(quat).getRPY(roll, pitch, yaw); +// qDebug()<<"yaw:"< 2.0) + uav_vel_total = 2.0; + double target_yaw = pos2ang(goal_pose.position.x, goal_pose.position.y, local_pose[control_num].position.x, local_pose[control_num].position.y); + count_control ++; + double mid_yaw = target_yaw - yaw; + if (mid_yaw > 3.1415926) + mid_yaw = mid_yaw - 3.1415926*2; + else if(mid_yaw < -3.1415926) + mid_yaw = 2*3.1415926 + mid_yaw; + vel_goal.angular.x = 0.0; + vel_goal.angular.y = 0.0; + vel_goal.angular.z = 1.0* mid_yaw; + if (vel_goal.angular.z > 3.0) + vel_goal.angular.z = 3.0; + else if (vel_goal.angular.z < -3.0) + vel_goal.angular.z = -3.0; + vel_goal.linear.x = uav_vel_total * cos(target_yaw); + vel_goal.linear.y = uav_vel_total * sin(target_yaw); + vel_goal.linear.z = 0.0; + if (count_control %30 == 0) + { + qDebug()<<"target_yaw"< 0 && angle < 0) + angle = angle + 3.1415926; + else if (ya-yb < 0 && angle > 0) + angle = angle - 3.1415926; + else if (ya-yb == 0) + { + if (xa-xb > 0) + angle = 0.0; + else + angle = 3.1415926; + } + } + else + { + if (ya-yb > 0) + angle = 3.1415926 / 2; + else if (ya-yb <0) + angle = -3.1415926 / 2; + else + angle = 0.0; + } + if (angle < 0) + angle = angle + 2 * 3.1415926; + return angle; +} } // namespace xtdrone_qt diff --git a/control/gcs/develop/xtdrone_qt/src/qrviz.cpp b/control/gcs/develop/xtdrone_qt/src/qrviz.cpp index 61b6ab5..f76b4d3 100644 --- a/control/gcs/develop/xtdrone_qt/src/qrviz.cpp +++ b/control/gcs/develop/xtdrone_qt/src/qrviz.cpp @@ -1,8 +1,115 @@ #include "../include/xtdrone_qt/qrviz.hpp" +#include qrviz::qrviz(QVBoxLayout* layout) { // create rviz render_panel = new rviz::RenderPanel(); layout->addWidget(render_panel); + manager = new rviz::VisualizationManager(render_panel); + tool_manager = manager->getToolManager(); + ROS_ASSERT(manager!=NULL); + render_panel->initialize(manager->getSceneManager(),manager); // must before mananer->init + //init rviz + manager->initialize(); + manager->startUpdate(); + manager->removeAllDisplays(); + +} +void qrviz::Set_FixedFrame(QString Fixed_name) +{ + manager->setFixedFrame(Fixed_name); + qDebug()<getFixedFrame(); +} +void qrviz::Display_Grid(int Cell_count, QColor color, bool enable) +{ + if (Grid!=NULL) // only one grid is added on rviz + { + delete Grid; + Grid = NULL; + } + Grid = manager->createDisplay("rviz/Grid","myGrid",enable); + Grid->subProp("Plane Cell Count")->setValue(Cell_count); + Grid->subProp("Color")->setValue(color); + ROS_ASSERT(Grid!=NULL); + manager->startUpdate(); +} +void qrviz::Display_Pose(QString pose_topic, QString pose_shape, QColor color, bool enable, int num) +{ + if (count_pose_num[num]==0) + { + count_pose_num[num]++; + Pose.push_back(NULL); + } + else + { + if (Pose[num]!=NULL) // only one grid is added on rviz + { + delete Pose[num]; + Pose[num] = NULL; + } + } + Pose[num] = manager->createDisplay("rviz/Pose","myPose",enable); + Pose[num]->subProp("Topic")->setValue(pose_topic); + Pose[num]->subProp("Color")->setValue(color); + Pose[num]->subProp("Shape")->setValue(pose_shape); + ROS_ASSERT(Pose[num]!=NULL); + manager->startUpdate(); +} +void qrviz::Display_TF(bool enable1, bool enable) +{ + if (Tf!=NULL) // only one grid is added on rviz + { + delete Tf; + Tf = NULL; + } + Tf = manager->createDisplay("rviz/TF","myTF",enable); + Tf->subProp("Show Names")->setValue(enable1); + ROS_ASSERT(Tf!=NULL); + manager->startUpdate(); +} +void qrviz::Display_LaserScan(QString laser_topic, bool enable) +{ + if (Laser!=NULL) // only one grid is added on rviz + { + delete Laser; + Laser = NULL; + } + Laser = manager->createDisplay("rviz/LaserScan","myLaser",enable); + Laser->subProp("Topic")->setValue(laser_topic); + ROS_ASSERT(Laser!=NULL); + manager->startUpdate(); +} +void qrviz::Display_Image(QString Image_topic, bool enable, int num) +{ + qDebug()<<"image_num"<createDisplay("rviz/Image","myImage",enable); + Image[num]->subProp("Image Topic")->setValue(Image_topic); + ROS_ASSERT(Image[num]!=NULL); + manager->startUpdate(); +} +void qrviz::Set_start_pose() +{ + rviz::Tool* current_tool = tool_manager->addTool("rviz/SetInitialPose"); + tool_manager->setCurrentTool(current_tool); +} +void qrviz::Set_goal_pose() +{ + rviz::Tool* current_tool = tool_manager->addTool("rviz/SetGoal"); + rviz::Property* pro = current_tool->getPropertyContainer(); + pro->subProp("Topic")->setValue("/move_base_simple/goal"); + tool_manager->setCurrentTool(current_tool); } diff --git a/control/gcs/develop/xtdrone_qt/ui/form.ui b/control/gcs/develop/xtdrone_qt/ui/form.ui index ccdb11c..dec0068 100644 --- a/control/gcs/develop/xtdrone_qt/ui/form.ui +++ b/control/gcs/develop/xtdrone_qt/ui/form.ui @@ -44,7 +44,9 @@ p, li { white-space: pre-wrap; } - font: 75 15pt "Ubuntu Mono"; + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); Reset @@ -60,7 +62,9 @@ p, li { white-space: pre-wrap; } - font: 75 15pt "Ubuntu Mono"; + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); Ignore diff --git a/control/gcs/develop/xtdrone_qt/ui/formrviz.ui b/control/gcs/develop/xtdrone_qt/ui/formrviz.ui new file mode 100644 index 0000000..0b403d6 --- /dev/null +++ b/control/gcs/develop/xtdrone_qt/ui/formrviz.ui @@ -0,0 +1,160 @@ + + + FormRviz + + + + 0 + 0 + 330 + 353 + + + + Rviz + + + + + 20 + 60 + 271 + 211 + + + + background-color: rgb(238, 238, 236); + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 10 + 160 + 221 + 25 + + + + add topic here + + + + + + 10 + 11 + 110 + 136 + + + + + + + font: 57 15pt "Ubuntu"; +color: rgb(32, 74, 135); + + + image + + + + + + + font: 57 15pt "Ubuntu"; +color: rgb(32, 74, 135); + + + tf + + + + + + + font: 57 15pt "Ubuntu"; +color: rgb(32, 74, 135); + + + laser + + + + + + + font: 57 15pt "Ubuntu"; +color: rgb(32, 74, 135); + + + add topic + + + + + + + + + + 198 + 300 + 91 + 25 + + + + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); + + + OK + + + + + + 60 + 10 + 191 + 41 + + + + color: rgb(32, 74, 135); +font: 57 23pt "Ubuntu"; + + + Display types + + + + + + 20 + 300 + 91 + 25 + + + + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); + + + Cancel + + + + + + diff --git a/control/gcs/develop/xtdrone_qt/ui/main_window.ui b/control/gcs/develop/xtdrone_qt/ui/main_window.ui index 08f5041..1bf58db 100644 --- a/control/gcs/develop/xtdrone_qt/ui/main_window.ui +++ b/control/gcs/develop/xtdrone_qt/ui/main_window.ui @@ -800,7 +800,7 @@ border-bottom-color: rgb(186, 189, 182); 0 0 281 - 651 + 661 @@ -810,7 +810,7 @@ border-bottom-color: rgb(186, 189, 182); background-color: rgb(238, 238, 236); - 0 + 1 @@ -837,7 +837,7 @@ border-bottom-color: rgb(186, 189, 182); 0 0 281 - 621 + 591 @@ -857,6 +857,28 @@ border-bottom-color: rgb(186, 189, 182); + + + + 90 + 600 + 89 + 25 + + + + Add more display types + + + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); + + + + Add + + @@ -1666,35 +1688,60 @@ font: 57 12pt "Ubuntu"; - 110 + 150 10 - 741 + 701 481 - + 10 - 9 - 91 - 58 + 400 + 135 + 90 - + + + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); + + - PushButton + 2D pose Estimate - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + font: 57 12pt "Ubuntu"; +color: rgb(32, 74, 135); +border-bottom-color: rgb(186, 189, 182); + + - PushButton + 2D Nav Goal