当前位置:网站首页>rospy Odometry天坑小计
rospy Odometry天坑小计
2022-07-25 09:24:00 【墨色玫瑰】
rospy Odometry天坑小计
在使用 python 自己搭建 ros 控制小车的上位机接口时,遇到了一个非常奇怪的问题,发布里程计的时候,一旦里程计得到订阅,发布者就会报 ndarray 属性找不到错误,乍一看着实让人脑瓜疼,明明处理的是四元数,为什么会和 n u m p y numpy numpy扯上关系。百度和 C S D N CSDN CSDN上并没有找到相关问题的记录,有人发出来的示例也都没有处理这个问题。这里记录一下,既是笔记,也是警示自己,处理这些情况的时候一定不能先入为主,还是得谨慎思考。
首先上图,报错截图如下,充满迷惑:
引发这个错误的源代码如下:
odom = nav_msgs.msg.Odometry()
odom.header.stamp = self.last_t
odom.header.frame_id = "odom"
odom.pose.pose.position.x = self.x
odom.pose.pose.position.y = self.y
odom.pose.pose.position.z = 0.
odom.pose.pose.orientation = odom_q
odom.child_frame_id = 'base_link'
odom.twist.twist.linear.x = self.vx
odom.twist.twist.linear.y = self.vy
odom.twist.twist.linear.z = 0.
odom.twist.twist.angular.z = self.w
print(odom)
self.odom_pub.publish(odom)
错误出现的第一时间翻阅了 Odometry 源码,并没有发现什么问题,CSDN 上也没有发现类似的情况。最终谷歌找到ROS问答社区发现问题,这里这个兄弟也遭遇了同样的情况。
问题出在上述代码第7行,其中 odom.pose.pose.orientation 是一个标准的四元数类型,而 odom_q 却是一个 numpy 的数组,因此在消息内部处理的时候遭遇该错误。
而这个 odom_q 是来自于下面这样一行变换,这句的作用是通过欧拉角得到四元数,但是这个函数有点反人类,它返回的四元数使用 ndarray 表示的,而不是标准的四元数,这于 C + + C++ C++中的完全不一样,从 C + + C++ C++转过来轻易不会注意到这个问题。
odom_q = tf.transformations.quaternion_from_euler(0, 0, self.thelta)
(也不知道作者和管理者是怎么想的,这也太坑了)
找到问题之后,问题就好办了,正确的写法如下:
odom.pose.pose.orientation.x = odom_q[0]
odom.pose.pose.orientation.y = odom_q[1]
odom.pose.pose.orientation.z = odom_q[2]
odom.pose.pose.orientation.w = odom_q[3]
至此,问题都得到解决。
参考文章:Error assigning a python quaternion - ROS Answers: Open Source Q&A Forum
边栏推荐
- [deep learning] convolutional neural network
- Hyperautomation for the enhancement of automation in industries 论文翻译
- CCF 201512-3 画图
- ADC介绍
- How to install pytorch—— A most simple and effective method!
- [Android studio] batch data import to Android local database
- ECO简介
- App lifecycle and appledelegate, scenedelegate
- VCS常用命令
- Camera attitude estimation
猜你喜欢

从Anaconda到TensorFlow到Jupyter一路踩坑一路填平

鱼眼图像自监督深度估计原理分析和Omnidet核心代码解读

@5-1 CCF 2019-12-1 reporting

数字IC设计SOC入门进阶

单目深度估计自监督模型Featdepth解读(下)——openMMLab框架使用

Data viewing and parameter modification of multi-channel vibrating wire, temperature and analog sensing signal acquisition instrument

~3 CCF 2022-03-2 travel plan

Gartner 2022年顶尖科技趋势之超级自动化

Coredata storage to do list

Mlx90640 infrared thermal imaging sensor temperature measurement module development notes (III)
随机推荐
@5-1 CCF 2019-12-1 reporting
First knowledge of opencv4.x --- drawing shapes on images
ARM GIC简介
从Anaconda到TensorFlow到Jupyter一路踩坑一路填平
Yolov5 realizes target detection of small data sets -- kolektor defect data set
~2 CCF 2022-03-1 uninitialized warning
OC -- Inheritance and polymorphic and pointer
CCF 201509-4 高速公路
Mlx90640 infrared thermal imager temperature measurement module development notes (I)
[data mining] nearest neighbor and Bayesian classifier
MLX90640 红外热成像传感器测温模块开发笔记(三)
单目深度估计模型Featdepth实战中的问题和拓展
一个可以返回前一页并自动刷新页面的ASP代码.
Defect detection network -- hybrid supervision (kolektor defect data set reproduction)
Get to know opencv4.x for the first time --- add Gaussian noise to the image
SystemVerilog syntax
基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(上)
CCF 201509-3 模板生成系统
Mixed supervision for surface defect detection: from weakly to fully supervised learning
一个硬件攻城狮的经济学基础