3.2加载RVIZ常用的Display

在这里插入图片描述
在这里插入图片描述

前面基本的gird图形设计好了,接下来就是去设置gird的图层属性,
在qrviz.hpp中声明一个接口函数:

    void Display_Grid(int Cell_Count,QColor color,bool enable);

初始化这个接口函数

void qrviz::Display_Grid(int Cell_Count,QColor color,bool enable)
{
    if(Grid_!=NULL)
    {
        delete Grid_;
        Grid_=NULL;
    }
    Grid_=manager_->createDisplay("rviz/Grid","myGrid",enable);
    //设置cell Count
    Grid_->subProp("Plane Cell Count")->setValue(Cell_Count);
    //设置颜色
    Grid_->subProp("Color")->setValue(color);
    ROS_ASSERT(Grid_!=NULL);
}

在在qrviz.hpp中声明Gird对象:

    rviz::Display* Grid_=NULL;

注意理解代码:是如何在main_window.cpp中去更改rviz的显示图层:

//链接Grid_Check是否被选中,来更新rviz图层显示,在槽函数中调用我们qrviz.cpp中写的接口函数Display_Grid
//connect(Grid_Check,SIGNAL(stateChanged(int)),this,SLOT(slot_display_grid(int)));
//更新图层函数,通过调用Display_Grid接口函数,传入设置更改后的参数

void MainWindow::slot_display_grid(int state)
{
    bool enable=state>1?true:false;
    //颜色使用";"分割,所以先对文本框内容进行拆分,转化为int 类型,然后传入Display_Gird接口函数
    QStringList qli=Grid_Color_Box->currentText().split(";");
    QColor color=QColor(qli[0].toInt(),qli[1].toInt(),qli[2].toInt());
    myrviz->Display_Grid(Cell_Count_Box->text().toInt(),color,enable);
}

需要理解的地方:
//这里的"rviz/Grid" 是代表类名,必须和rviz的名称对应,第二个参数图层名称,可以随便起
//还有就是manger必须有一个Display对象接受他,所以我们在对象的.hpp中获取一个display对象
//rviz::Display* Grid_=NULL;

    //通过 RVIZ控制对象创建Gird图层
    Grid_=manager_->createDisplay("rviz/Grid","myGrid",enable);
    //设置cell Count,通过subProp方法
    Grid_->subProp("Plane Cell Count")->setValue(Cell_Count);
    //设置颜色
    Grid_->subProp("Color")->setValue(color);

在这里插入图片描述
tf设计步骤:
qrviz.hpp创建一个接口函数:

    void Display_TF(bool enable);

创建一个私有的TF对象

rviz::Display* TF_=NULL;

去定义这个接口函数

void qrviz::Display_TF(bool enable)
{
    if(TF_!=NULL)
    {
        delete TF_;
        TF_=NULL;
    }
    TF_=manager_->createDisplay("rviz/TF","myTF",enable);
    //每创建一个manger都要ASSER断言一下,避免山退的bug
    ROS_ASSERT(TF_!=NULL);
}

在mian_window.cpp中进行ui设计

    //TF ui
    QTreeWidgetItem* TF=new QTreeWidgetItem(QStringList()<<"TF");
    //设置图标
    TF->setIcon(0,QIcon(":/classes/images/classes/TF.png"));
    //checkbox
    QCheckBox* TF_Check=new QCheckBox();
    connect(TF_Check,SIGNAL(stateChanged(int)),this,SLOT(slot_display_tf(int)));
    //向Treewidget添加TF Top节点
    ui.treeWidget->addTopLevelItem(TF);
    //向TF添加checkbox
    ui.treeWidget->setItemWidget(TF,1,TF_Check);

在main_window.hpp中声明槽函数

void slot_display_tf(int);

定义槽函数

//TF
void MainWindow::slot_display_tf(int state)
{
    bool enable=state>1?true:false;
    myrviz->Display_TF(enable);
}

运行,将FixedFream 坐标系改为base_footprint 即可看见坐标系
搞定:

激光显示:
注意需要把Fiexd_Fream改为laser,LaserScan的话题是"/scan",keyi可以看到几乎和rviz里面效果是一样的在这里插入图片描述

地图显示:
基本步骤:都是一样的和激光雷达
在这里插入图片描述
这里有一个bug,当你在qrviz.hpp中声明rviz::Display* RobotModel_=NULL;
的时候,有可能会出现山退的现象,解决方法:
将他的声明放置到qrviz.cpp中,作为.cpp文件的全局变量

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值