ros rviz 插件开发

1. rviz 插件,tools 开发总结(画虚拟墙开发,虚拟路径开发):

主要是参照了rviz 中measure_tool.cpp 中划线的方法,并把线转化成点云数据,然后发给costmap层。

ros的基础知识:

ros c++ 下点的数据定义及使用:

头文件:#include <geometry_msgs/Point32.h>

定义一个点变量:geometry_msgs::Point32 p;

使用例子:

p.x=start_pos.x+((end_pos.x-start_pos.x)/point_num)*i;

p.y=a*p.x+b;

p.z=0.35;

消息的数据格式:

eaibot@PS3B-B1:~$ rosmsg show geometry_msgs/Point32

float32 x

float32 y

float32 z

ros c++ 下点云数据定义及使用

头文件:#include "sensor_msgs/PointCloud.h"

定义变量:sensor_msgs::PointCloud virtualWall_pointCloud;

使用例子:

virtualWall_pointCloud.header.stamp= ros::Time::now();

virtualWall_pointCloud.header.frame_id = context_->getFixedFrame().toStdString();

geometry_msgs::Point32 p;

p.x=start_pos.x+((end_pos.x-start_pos.x)/point_num)*i;

p.y=a*p.x+b;

p.z=0.35;

virtualWall_pointCloud.points.push_back(p);

pub_.publish(virtualWall_pointCloud);

消息的数据格式:

eaibot@PS3B-B1:~$ rosmsg show sensor_msgs/PointCloud

std_msgs/Header header

uint32 seq

time stamp

string frame_id

geometry_msgs/Point32[] points

float32 x

float32 y

float32 z

sensor_msgs/ChannelFloat32[] channels

string name

float32[] values

ros rviz 包中特定的知识:

1.鼠标事件

函数定义:

virtual int processMouseEvent(ViewportMouseEvent& event);

其中 ViewportMouseEvent viewport_mouse_event.h 中定义

常用时间如下:

//按钮事件

bool left() { return buttons_down & Qt::LeftButton; }

bool middle() { return buttons_down & Qt::MidButton; }

bool right() { return buttons_down & Qt::RightButton; }

bool shift() { return modifiers & Qt::ShiftModifier; }

bool control() { return modifiers & Qt::ControlModifier; }

bool alt() { return modifiers & Qt::AltModifier; }

//鼠标事件

bool leftUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton; }

bool middleUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton; }

bool rightUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton; }

bool leftDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton; }

bool middleDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton; }

bool rightDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton; }

rviz 包中尚需解决的问题:

1.对整个包的整体接口,各种类的继承不熟悉,不够了解

2.对tf 的坐标的各种转换关系不清楚。

ros costmap 包中特定的知识:

在cost_values.h 中定义的costmap cost 对应的情况

没有信息

static const unsigned char NO_INFORMATION = 255;

致命的障碍

static const unsigned char LETHAL_OBSTACLE = 254;

有可能是障碍物

static const unsigned char INSCRIBED_INFLATED_OBSTACLE = 253;

没有障碍物

static const unsigned char FREE_SPACE = 0;

在costmap_2d.h 中常用的函数数

参数:mx,my 为costmap的像素值,wx和wy 为世界坐标的x,y值

作用:通过costmap的像素点转化成世界坐标

void mapToWorld(unsigned int mx, unsigned int my, double& wx, double& wy) const;

参数:wx和wy 为世界坐标的x,y值, mx,my 为costmap的像素值

作用:把世界坐标的x,y 点 转化成相对应的costmap 的像素值。

bool worldToMap(double wx, double wy, unsigned int& mx, unsigned int& my) const;

参数:mx,my 为costmap的像素值,cost 为该像素值对应的cost值,-1和255 表示未知的,0表示

无障碍物1-253表示有可能有障碍物,值越大,可能性越大,254 表示致命障碍物

作用:设置该像素对应的cost 值

void setCost(unsigned int mx, unsigned int my, unsigned char cost);

参数:mx,my 为costmap的像素值,cost 为该像素值对应的cost值,-1和255 表示未知的,0表示

无障碍物1-253表示有可能有障碍物,值越大,可能性越大,254 表示致命障碍物

作用:获取该像素对应的cost 值

unsigned char getCost(unsigned int mx, unsigned int my) const;

/**

* @brief Turn this costmap into a copy of a window of a costmap passed in

* @param map The costmap to copy

* @param win_origin_x The x origin (lower left corner) for the window to copy, in meters

* @param win_origin_y The y origin (lower left corner) for the window to copy, in meters

* @param win_size_x The x size of the window, in meters

* @param win_size_y The y size of the window, in meters

*/

bool copyCostmapWindow(const Costmap2D& map, double win_origin_x, double win_origin_y, double win_size_x,

double win_size_y);

参数: mx,my 为costmap的像素值

作用:根据costmap像素,获取对应cost 列表中该像素对应的索引,

inline unsigned int getIndex(unsigned int mx, unsigned int my) const

参数: index 为cost列表的索引,mx,my 为costmap的像素值

作用:根据cost 列表的索引获取相对应costmap 的像素值,

inline void indexToCells(unsigned int index, unsigned int& mx, unsigned int& my) const

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值