即使前方荊棘滿地,也要跨上戰馬,一路前行!
keep learning,keep programing!
ros中的座標變換主要形式為廣播和監聽,可以發布座標系a、座標系b與世界座標系的關係,可以監聽得到座標系a與座標系b之間的轉換關係,本文主要參考古月老師的教程,發布turtle1~turtle3與world座標系,並監聽turtle1與turtle2、turtle3之間的座標轉換關係,發布控制指令,控制小海龜運動,並通過launc**件實現重對映,多次呼叫發布節點和監聽節點。
通過訂閱海龜turtle(重對映名字)的位姿資訊,將其x,y和 theta設定為轉換矩陣transform的引數,並發布出去,發布為從世界座標系轉換到turtle座標系的轉換矩陣t,具體實現如下:
#include
#include
#include
#include
using
namespace std;
std::string turtle_name;
void
posecallback
(const turtlesim::poseconstptr& msg)
intmain
(int argc,
char
** ar**)
ros中的座標 廣播和監聽是通過tf樹的形式,故可以監聽對應tf樹下的座標變換,再獲取其轉換矩陣t,例程中先呼叫服務生成了乙隻新的turtle,然後發布其運動訊息控制其運動,本文編寫了兩個監聽者test_listen和test_listen2,具體實現如下:
#include
#include
#include
#include
intmain
(int argc,
char
** ar**)
catch
(tf::transformexception &ex)
geometry_msgs::twist vel_msg;
vel_msg.angular.z =
4.0*
atan2
(transform.
getorigin()
.y()
, transform.
getorigin()
.x()
);vel_msg.linear.x =
0.5*
sqrt
(pow
(transform.
getorigin()
.x()
,2)+
pow(transform.
getorigin()
.y()
,2))
; turtle_vel.
publish
(vel_msg)
; rate.
sleep()
;}return0;
};
1、功能包依賴
geometry_msgs、 roscpp、rospy、 std_msgs、 turtlesim、 tf
add_executable(test_br src/test_broadcaster.cpp)
target_link_libraries(test_br $
)add_executable(test_listener src/test_listen.cpp)
target_link_libraries(test_listener $
)add_executable(test_listener2 src/test_listen2.cpp)
target_link_libraries(test_listener2 $
)
2、launc**件"turtle_name1"
default
="/turtle1"
/>
"turtle_name2"
default
="/turtle2"
/>
"turtle_name3"
default
="/turtle3"
/>
"tf_turtle1_br" pkg =
"test_tf"
type
="test_br" output=
"screen"
>
"turtle_name" value=
"$(arg turtle_name1)"
/>
<
/node>
"tf_turtle2_br" pkg =
"test_tf"
type
="test_br" output=
"screen"
>
"turtle_name" value=
"$(arg turtle_name2)"
/>
<
/node>
"tf_turtle3_br" pkg =
"test_tf"
type
="test_br" output=
"screen"
>
"turtle_name" value=
"$(arg turtle_name3)"
/>
<
/node>
"test_listener" pkg =
"test_tf"
type
="test_listener"
/>
"test_listener2" pkg =
"test_tf"
type
="test_listener2"
/>
"turtlesim" pkg =
"turtlesim"
type
="turtlesim_node"
/>
"turtlesim2" pkg =
"turtlesim"
type
="turtle_teleop_key"
/>
<
/launch>
執行roslaunch test_tf turtle.launch
1、座標關係圖
通過如下命令檢視座標關係圖
2、海龜追逐圖
ros中的座標變換是非常重要的一種方法,在機械人中有著廣泛應用,一般在接收座標間變換矩陣後,還需要通過eigen庫中的一些操作再做一些變換,比如機械人幀間位姿的匹配等;若已知世界座標系中機械人a的位姿為(x1,y1,theta1) ,機械人b的位姿為(x2,y2,theta2),如何求機械人a在機械人b中的座標?可以通過求出座標系a到座標系b的轉換矩陣tba,再求解座標為(tba(0,2),tba(1,2),atan2(tba0,0))
ROS複習筆記之 座標變換(TF)
參考資料為 ros中的座標轉換tf在描述組成機械人的每個部分 障礙物和外部物體時是最有用的概念之一。這些可以被描述為位置 position 和方向 direction 統稱為姿態 pose 在此,位置由x y z這3個向量表示,而方向是用四元數 quaternion x y z w表示。四元數並不直...
ROS學習之TF變換
tf能夠根據時間緩衝並維護多個參考係之間的座標變換,可以在任意時間,將點 向量 等資料的座標,完成座標變換。tf的使用方法 兩個概念了解一下 監聽tf變換 接收並快取系統中發布的所有參考係變換,並從中查詢所需要的參考係變換。廣播tf變換 向系統中廣播參考係之間的座標變換關係。系統中更能可能會存在多個...
ROS 做tf座標變換的幾種座標(一)
平時開發機械人時少不了一些感測器接受資訊並傳給機械人本體,無論是做導航 雷達或視覺 還是做定位追蹤,都需要一些附加在機械人本體上的座標系來實現,所以下面簡單介紹幾種常見的座標 base link 機械人本體座標系,與機械人中心重合 base footprint 座標系原點為base link原點在地...