当前位置:网站首页>【从零开始学习SLAM】将坐标系变换关系发布到 topic tf
【从零开始学习SLAM】将坐标系变换关系发布到 topic tf
2022-07-28 15:46:00 【小秋SLAM实战教程】
创建功能包
roscpp
rospy
tf2
tf2_ros
编写代码
#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>
#include <eigen3/Eigen/Eigen>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Geometry>
#include <eigen3/Eigen/Eigenvalues>
#include <iostream>
#include <eigen3/Eigen/Core>
#include <cmath>
using namespace std;
using namespace Eigen;
int main(int argc, char** argv){
ros::init(argc, argv, "my_tf_broadcaster");
ros::NodeHandle node;
tf::TransformBroadcaster br;
tf::Transform transform;
ros::Rate rate(10.0);
while (node.ok()){
transform.setOrigin(tf::Vector3(1.0, 0.0, 0.0));
Eigen::AngleAxisd rotation_vector(M_PI/4, Eigen::Vector3d ( 0, 0, 1 ) );
std::cout << "angle is: " << rotation_vector.angle() * 180 / M_PI << " axis is: " << rotation_vector.axis().transpose() << std::endl;
//旋转向量转化为旋转矩阵
Eigen::Matrix3d rotation_matrix3d;
rotation_matrix3d = rotation_vector.matrix();
std::cout<<"rotation_matrix3d \n"<< rotation_matrix3d << std::endl;
// cos45 -sin45 0
// sin45 cos45 0
// 0 0 1
// 0.707107 -0.707107 0
// 0.707107 0.707107 0
// 0 0 1
// 旋转矩阵转换为欧拉角,"2" represents the z axis , "0" x axis, "1" y axis
Eigen::Vector3d euler_angle = rotation_matrix3d.eulerAngles(0, 1, 2);
std::cout << "绕z轴旋转的角度是 " << euler_angle.z() * 180 / M_PI << std::endl;
tf::Quaternion q;
q.setRPY(0, 0, euler_angle.z());
transform.setRotation( q );
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "map", "base_link"));
rate.sleep();
}
return 0;
};
// 精简版
// #include <ros/ros.h>
// #include <tf/transform_broadcaster.h>
// #include <eigen3/Eigen/Core>
// #include <eigen3/Eigen/Geometry>
// int main(int argc, char** argv){
// ros::init(argc, argv, "my_tf_pub");
// ros::NodeHandle n;
// tf::TransformBroadcaster br;
// tf::Transform transform;
// ros::Rate rate(10.0);
// while(n.ok()){
// transform.setOrigin(tf::Vector3(1.0, 0.0, 0.0));
// tf::Quaternion q;
// q.setRPY(0, 0, 0.78539);
// transform.setRotation(q);
// br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "map", "base_link"));
// rate.sleep();
// }
// return 0;
// }
边栏推荐
- Leetcode learn to insert and sort unordered linked lists (detailed explanation)
- Qt学习之信号和槽机制
- CRC16数据校验支持ModelBus和XMODEM校验模式(C语言)
- 在abaqus中使用PyQt设计GUI
- Li Hongyi, machine learning 4. Deep learning
- 使用js直传oss阿里云存储文件,解决大文件上传服务器限制
- Ansa secondary development - Introduction to interface development tools
- redis源码优化--绑核
- flashfxp 530 User cannot log in. ftp
- Some suggestions on optimizing HyperMesh script performance
猜你喜欢

USB产品(FX3、CCG3PA)的调试方法

Introduction and implementation of stack (detailed explanation)

Leetcode daily practice - the number of digits in the offer 56 array of the sword finger

MySQL view event status statements and modification methods

Fx3 development board and schematic diagram

Several methods of HyperMesh running script files

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi

ANSYS二次开发 - MFC界面调用ADPL文件

有趣的 Kotlin 0x07:Composition
随机推荐
遭MQ连连干翻后的醒悟!含恨码出这份MQ手册助力秋招之旅
Li Hongyi, machine learning 5. Tips for neural network design
Leetcode daily practice - the number of digits in the offer 56 array of the sword finger
一大早支付宝来短信说你中“奖”了?处理服务器挖矿病毒 - kthreaddi
Wechat official account to obtain material list
Several methods of HyperMesh running script files
在vs code上配置Hypermesh二次开发环境
PHP 图片上传
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
有趣的 Kotlin 0x07:Composition
Ansa secondary development - build ansa/meta secondary development environment on pycharm
Reset grafana login password to default password
Optimization of network request success rate in IM instant messaging software development
The epidemic dividend disappeared, and the "home fitness" foam dissipated
Detailed record of steps to configure web server (many references)
Qt学习第一天
Wake up after being repeatedly upset by MQ! Hate code out this MQ manual to help the journey of autumn recruitment
Automatically pack compressed backup download and delete bat script commands
Splash (渲染JS服务)介绍安装
微软100题-天天做-第16题