feat(2.5d): dua roll/pitch do tu IMU vao TF tren phan cung that
Nguyen tac 2.5D la pose SE(2) con roll/pitch thi DO. Nhung do nghieng do
duoc truoc gio chi den duoc octomap/costmap qua gravity_align_nodelet;
RTAB-Map dat anh depth bang TF phang nen ban do 3D khong duoc bu nghieng.
Cach lam: khai hai khop revolute base_roll_joint / base_pitch_joint, va
base_tilt_tf.py publish /joint_states. robot_state_publisher lo phan TF nen
van la NGUON DUY NHAT cua moi canh - khong tranh chap.
Nghiem thu tren nhanh phan cung (description.launch use_sim:=false):
base_footprint -> base_roll_link /tf 392 ban tin
base_roll_link -> base_link /tf 392 ban tin
-> 2 canh, moi canh mot nguon
TF roll 5.057 pitch -8.637 vs IMU bom vao 5.000 / -8.670 -> lech 0.057
⚠️ Chi bat khi use_sim=false. Trong Gazebo giu khop fixed nhu cu: san phang
nen pitch do duoc chi 0.0006 do, khop revolute khong mang lai gi ma Gazebo
lai mo phong vat ly no. Da kiem: URDF sinh ra khi use_sim=true GIONG HET
TUNG BYTE ban truoc thay doi.
Da thu type="floating" truoc do va that bai, hai ly do doc lap:
1. urdf2sdf huy luon link goc -> gazebo_ros_p3d FATAL, mat /scan va odom
2. libkdl_parser doi floating thanh fixed -> RSP van phat, thanh hai nguon
Ca hai deu ghi lai trong robot.urdf.xacro de khong ai thu lai.
gravity_align_nodelet them param tilt_from_tf de KHONG bu hai lan; no buoc
theo use_sim trong perception.launch nen hai ben khong the lech nhau.
This commit is contained in:
@@ -51,9 +51,24 @@
|
||||
</node>
|
||||
|
||||
<!-- 3. Bu nghieng bang roll/pitch DO tu IMU -> he quy chieu thang dung -->
|
||||
<!--
|
||||
⚠️ tilt_from_tf PHAI khop description.launch:tilt_in_tf.
|
||||
|
||||
ca hai false - canh base_footprint -> base_link phang, nodelet tu ap
|
||||
Lift*Tilt. Day la mac dinh.
|
||||
ca hai true - base_tilt_tf.py da dua nghieng vao TF, nodelet chi tra
|
||||
thang base_footprint <- camera.
|
||||
|
||||
Lech nhau thi hong IM LANG, khong node nao bao loi:
|
||||
tilt_in_tf=true + tilt_from_tf=false -> cloud nghieng GAP DOI goc that
|
||||
tilt_in_tf=false + tilt_from_tf=true -> cloud khong duoc bu ti nao
|
||||
-->
|
||||
<arg name="tilt_from_tf" default="false"/>
|
||||
|
||||
<node pkg="nodelet" type="nodelet" name="gravity_align"
|
||||
args="load perception_3d/GravityAlignNodelet $(arg manager)"
|
||||
output="screen">
|
||||
<param name="tilt_from_tf" type="bool" value="$(arg tilt_from_tf)"/>
|
||||
<remap from="cloud_in" to="/perception/cloud_filtered"/>
|
||||
<remap from="cloud_aligned" to="/perception/cloud_aligned"/>
|
||||
<remap from="imu/data_raw" to="$(arg imu_topic)"/>
|
||||
|
||||
@@ -75,6 +75,20 @@ private:
|
||||
pnh_.param<std::string>("output_frame", output_frame_, "base_footprint");
|
||||
pnh_.param("wheel_radius", wheel_radius_, 0.075);
|
||||
|
||||
// ============ ⚠️ TRANH BU NGHIENG HAI LAN ============
|
||||
// false (mac dinh): canh base_footprint -> base_link trong TF la PHANG
|
||||
// (base_joint la khop fixed rpy="0 0 0"), nen node nay phai tu ap
|
||||
// Lift(0,0,r) * Tilt(roll,pitch).
|
||||
//
|
||||
// true: chay kem robot_bringup/scripts/base_tilt_tf.py, canh do TRONG TF
|
||||
// DA co san do nghieng. Node nay chi con tra thang
|
||||
// output_frame <- camera va ap mot phep duy nhat.
|
||||
// Van tu ap nua la NGHIENG HAI LAN - loi im lang, cloud lech gap doi
|
||||
// goc nghieng that ma khong co gi bao.
|
||||
//
|
||||
// PHAI dat bang description.launch:tilt_in_tf. Hai co lech nhau la sai.
|
||||
pnh_.param("tilt_from_tf", tilt_from_tf_, false);
|
||||
|
||||
// He so complementary filter: ty trong cua gyro.
|
||||
// 0.98 @200Hz -> hang so thoi gian ~0.25s. Gyro chiem uu the ngan han,
|
||||
// accel keo ve trong dai han.
|
||||
@@ -211,17 +225,23 @@ private:
|
||||
if (msg->width == 0 || msg->height == 0)
|
||||
return;
|
||||
|
||||
// --- Static transform camera -> base_link (tu URDF) ---
|
||||
// --- Transform camera -> khung dich ---
|
||||
// tilt_from_tf_=false: tra ve base_link (canh TF phang), phai tu ap
|
||||
// Lift*Tilt o duoi.
|
||||
// tilt_from_tf_=true : tra thang ve base_footprint - canh do da mang san
|
||||
// Lift va Tilt do base_tilt_tf.py phat.
|
||||
const std::string& target = tilt_from_tf_ ? output_frame_ : base_frame_;
|
||||
|
||||
geometry_msgs::TransformStamped tf_bl_cam;
|
||||
try
|
||||
{
|
||||
tf_bl_cam = tf_buffer_->lookupTransform(base_frame_, msg->header.frame_id,
|
||||
tf_bl_cam = tf_buffer_->lookupTransform(target, msg->header.frame_id,
|
||||
ros::Time(0), ros::Duration(0.1));
|
||||
}
|
||||
catch (const tf2::TransformException& ex)
|
||||
{
|
||||
NODELET_WARN_THROTTLE(5.0, "gravity_align: khong lookup duoc TF %s <- %s: %s",
|
||||
base_frame_.c_str(), msg->header.frame_id.c_str(), ex.what());
|
||||
target.c_str(), msg->header.frame_id.c_str(), ex.what());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,12 +275,16 @@ private:
|
||||
tf_bl_cam.transform.rotation.y,
|
||||
tf_bl_cam.transform.rotation.z).toRotationMatrix();
|
||||
|
||||
// Khi tilt_from_tf_=true, t_bl_cam DA la base_footprint <- camera va da
|
||||
// chua ca Lift lan Tilt. Nhan them nua la bu hai lan.
|
||||
Eigen::Affine3d tilt = Eigen::Affine3d::Identity();
|
||||
tilt.linear() = (Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitY()) *
|
||||
Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitX())).toRotationMatrix();
|
||||
|
||||
Eigen::Affine3d lift = Eigen::Affine3d::Identity();
|
||||
lift.translation() << 0.0, 0.0, wheel_radius_;
|
||||
if (!tilt_from_tf_)
|
||||
{
|
||||
tilt.linear() = (Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitY()) *
|
||||
Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitX())).toRotationMatrix();
|
||||
lift.translation() << 0.0, 0.0, wheel_radius_;
|
||||
}
|
||||
|
||||
const Eigen::Affine3f total = (lift * tilt * t_bl_cam).cast<float>();
|
||||
|
||||
@@ -308,6 +332,9 @@ private:
|
||||
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
|
||||
|
||||
std::string base_frame_, output_frame_;
|
||||
// true = canh base_footprint -> base_link trong TF DA co do nghieng
|
||||
// (base_tilt_tf.py phat) -> node nay KHONG duoc tu ap nua.
|
||||
bool tilt_from_tf_ = false;
|
||||
double wheel_radius_ = 0.075;
|
||||
double alpha_ = 0.98;
|
||||
double accel_gate_ = 1.0;
|
||||
|
||||
@@ -9,6 +9,7 @@ catkin_package()
|
||||
# phai build. Cai dat de dung duoc bang `rosrun robot_bringup teleop.py`.
|
||||
catkin_install_python(PROGRAMS
|
||||
scripts/teleop.py
|
||||
scripts/base_tilt_tf.py
|
||||
scripts/virtual_joystick.py
|
||||
# teleop_model.py la MODULE, khong phai node. Phai cai vao CUNG thu muc voi
|
||||
# virtual_joystick.py vi node import no theo kieu anh em (sys.path[0] la thu
|
||||
|
||||
@@ -22,6 +22,35 @@
|
||||
publish joint_states cho banh xe -> bat fake de TF khong dut. -->
|
||||
<arg name="publish_fake_joints" default="true"/>
|
||||
|
||||
<!--
|
||||
============ DUA DO NGHIENG VAO TF ============
|
||||
false (mac dinh) - base_joint la khop FIXED rpy="0 0 0".
|
||||
Do nghieng do tu IMU chi den duoc octomap/costmap qua
|
||||
gravity_align_nodelet. Ban do 3D cua RTAB-Map KHONG
|
||||
duoc bu nghieng.
|
||||
true - base_joint thanh FLOATING, base_tilt_tf.py phat canh
|
||||
base_footprint -> base_link kem roll/pitch do tu IMU.
|
||||
Moi thu doc TF deu nhan duoc, ke ca RTAB-Map.
|
||||
|
||||
⚠️ Mac dinh false vi ba ly do, xem khoi ghi chu trong robot.urdf.xacro:
|
||||
LiDAR cung nghieng theo (laser_link la con cua base_link), mo phong
|
||||
khong kiem chung duoc (san phang, pitch 0.0006°), va no them mot diem
|
||||
hong don cho cay TF.
|
||||
-->
|
||||
<!--
|
||||
Do nghieng vao TF. KHONG con la co rieng nua - no di theo use_sim:
|
||||
|
||||
use_sim=false (phan cung that) -> URDF dung hai khop revolute,
|
||||
base_tilt_tf.py publish /joint_states
|
||||
use_sim=true (Gazebo) -> URDF dung mot khop fixed, khong chay
|
||||
node. Sim san phang nen do nghieng
|
||||
luon ~0, khop revolute chi them rui ro.
|
||||
|
||||
Giu arg nay de khong pha giao dien cac launch goi vao day; no khong con
|
||||
tac dung. Xem khoi ghi chu trong robot.urdf.xacro.
|
||||
-->
|
||||
<arg name="tilt_in_tf" default="false"/>
|
||||
|
||||
<param name="robot_description"
|
||||
command="$(find xacro)/xacro $(find robot_bringup)/urdf/robot.urdf.xacro
|
||||
use_sim:=$(arg use_sim)"/>
|
||||
@@ -31,6 +60,37 @@
|
||||
<node name="robot_state_publisher" pkg="robot_state_publisher"
|
||||
type="robot_state_publisher" output="screen"/>
|
||||
|
||||
<!--
|
||||
Khi tilt_in_tf=true, khop base_joint la FLOATING nen robot_state_publisher
|
||||
KHONG phat canh base_footprint -> base_link nua. Node nay phat thay.
|
||||
|
||||
⚠️ respawn="true" la BAT BUOC, khong phai tuy chon: canh nay noi phan dinh
|
||||
vi voi toan bo cam bien. Node chet ma khong hoi sinh la cay TF dut lam doi,
|
||||
mat sach scan, cloud va localization.
|
||||
-->
|
||||
<!--
|
||||
Chi chay tren PHAN CUNG THAT. Trong Gazebo, URDF dung mot khop `fixed` nen
|
||||
robot_state_publisher da phat canh base_footprint -> base_link; bat node
|
||||
nay len se thanh hai nguon tranh nhau.
|
||||
|
||||
respawn="true": node chet thi RSP khong con goc khop moi, canh TF dung yen
|
||||
o gia tri cuoi va cloud se lech dan neu robot doi do nghieng.
|
||||
-->
|
||||
<node unless="$(arg use_sim)"
|
||||
name="base_tilt_tf" pkg="robot_bringup" type="base_tilt_tf.py"
|
||||
output="screen" respawn="true" respawn_delay="1">
|
||||
<!-- ⚠️ PHAI khop ten khop trong robot.urdf.xacro. Sai ten thi RSP im lang
|
||||
bo qua, khong bao loi, va canh TF dung nguyen o 0. -->
|
||||
<param name="roll_joint" value="base_roll_joint"/>
|
||||
<param name="pitch_joint" value="base_pitch_joint"/>
|
||||
<param name="rate" value="50.0"/>
|
||||
<param name="imu_topic" value="/imu/data_raw"/>
|
||||
<!-- Giu khop gravity_align_nodelet de hai ben khong cho ra goc khac nhau -->
|
||||
<param name="alpha" value="0.98"/>
|
||||
<param name="accel_lpf_alpha" value="0.05"/>
|
||||
<param name="accel_gate" value="0.5"/>
|
||||
</node>
|
||||
|
||||
<!--
|
||||
joint_states cho banh xe:
|
||||
L0 (mot minh) -> joint_state_publisher gia lap
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
-->
|
||||
<launch>
|
||||
|
||||
<!-- Dua do nghieng do tu IMU vao canh TF base_footprint -> base_link.
|
||||
Mac dinh false. Xem khoi ghi chu trong description.launch. -->
|
||||
<arg name="tilt_in_tf" default="false"/>
|
||||
|
||||
|
||||
<arg name="use_sim" default="true"/>
|
||||
<arg name="world" default="restaurant"/>
|
||||
<arg name="gui" default="true"/>
|
||||
@@ -29,6 +34,7 @@
|
||||
<!-- ============ L1: nguon cam bien ============ -->
|
||||
<group if="$(arg use_sim)">
|
||||
<include file="$(find robot_bringup)/launch/sim.launch">
|
||||
<arg name="tilt_in_tf" value="$(arg tilt_in_tf)"/>
|
||||
<arg name="world" value="$(arg world)"/>
|
||||
<arg name="gui" value="$(arg gui)"/>
|
||||
<arg name="rviz" value="$(arg rviz)"/>
|
||||
@@ -39,6 +45,7 @@
|
||||
<include file="$(find robot_bringup)/launch/description.launch">
|
||||
<arg name="use_sim" value="false"/>
|
||||
<arg name="rviz" value="$(arg rviz)"/>
|
||||
<arg name="tilt_in_tf" value="$(arg tilt_in_tf)"/>
|
||||
<!-- firmware MCU publish joint_states banh xe -->
|
||||
<arg name="publish_fake_joints" value="false"/>
|
||||
</include>
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
-->
|
||||
<launch>
|
||||
|
||||
<!-- Dua do nghieng do tu IMU vao canh TF base_footprint -> base_link.
|
||||
Mac dinh false. Xem khoi ghi chu trong description.launch. -->
|
||||
<arg name="tilt_in_tf" default="false"/>
|
||||
|
||||
|
||||
<arg name="use_sim" default="true"/>
|
||||
<arg name="world" default="restaurant"/>
|
||||
<arg name="gui" default="true"/>
|
||||
@@ -49,6 +54,7 @@
|
||||
args="0 0 0 0 0 0 map odom"/>
|
||||
|
||||
<include file="$(find robot_bringup)/launch/odom.launch">
|
||||
<arg name="tilt_in_tf" value="$(arg tilt_in_tf)"/>
|
||||
<arg name="use_sim" value="$(arg use_sim)"/>
|
||||
<arg name="world" value="$(arg world)"/>
|
||||
<arg name="gui" value="$(arg gui)"/>
|
||||
@@ -56,6 +62,10 @@
|
||||
</include>
|
||||
|
||||
<include file="$(find perception_3d)/launch/perception_nodelets.launch">
|
||||
<!-- Do nghieng nam trong TF chi khi chay phan cung that (URDF dung khop
|
||||
revolute + base_tilt_tf.py). Trong Gazebo canh do phang nen nodelet
|
||||
phai tu bu. Buoc theo use_sim de hai ben KHONG THE lech nhau. -->
|
||||
<arg name="tilt_from_tf" value="$(eval not arg('use_sim'))"/>
|
||||
<arg name="depth_image" value="$(arg depth_image)"/>
|
||||
<arg name="depth_info" value="$(arg depth_info)"/>
|
||||
<arg name="imu_topic" value="/imu/data_raw"/>
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
-->
|
||||
<launch>
|
||||
|
||||
<!-- Dua do nghieng do tu IMU vao canh TF base_footprint -> base_link.
|
||||
Mac dinh false. Xem khoi ghi chu trong description.launch. -->
|
||||
<arg name="tilt_in_tf" default="false"/>
|
||||
|
||||
|
||||
<!-- restaurant | hotel_corridor | hospital | hospital_two_floors
|
||||
| hospital_three_floors -->
|
||||
<arg name="world" default="restaurant"/>
|
||||
@@ -43,6 +48,7 @@
|
||||
|
||||
<!-- L0: URDF + TF. use_sim:=true de keo them plugin Gazebo vao URDF. -->
|
||||
<include file="$(find robot_bringup)/launch/description.launch">
|
||||
<arg name="tilt_in_tf" value="$(arg tilt_in_tf)"/>
|
||||
<arg name="use_sim" value="true"/>
|
||||
<arg name="rviz" value="$(arg rviz)"/>
|
||||
<!-- Gazebo se publish joint_states banh xe -> tat fake -->
|
||||
|
||||
194
src/robot_bringup/scripts/base_tilt_tf.py
Executable file
194
src/robot_bringup/scripts/base_tilt_tf.py
Executable file
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
base_tilt_tf - Dua do nghieng DO tu IMU vao TF, qua /joint_states.
|
||||
|
||||
============ VAI TRO TRONG KIEN TRUC 2.5D ============
|
||||
Nguyen tac cua 2.5D: pose la SE(2), con roll/pitch thi DO chu khong uoc luong.
|
||||
Cho dung de dat do nghieng do duoc la TF, khong phai pose:
|
||||
|
||||
map -> odom SLAM sua drift (RTAB-Map)
|
||||
odom -> base_footprint SE(2) phang tuyet doi (EKF, two_d_mode=true)
|
||||
base_footprint -> base_roll_link -> base_link <- NGHIENG NAM O DAY
|
||||
base_link -> laser/camera/imu tinh, tu URDF
|
||||
|
||||
Nho vay pose van la 3 bac tu do, ma moi thu doc TF - RTAB-Map, octomap,
|
||||
costmap, RViz - deu nhan duoc do nghieng that ma khong phai tu bu.
|
||||
|
||||
============ ⚠️ VI SAO PHAT /joint_states CHU KHONG PHAT TF ============
|
||||
Mot canh TF chi duoc co MOT nguon. robot_state_publisher phat MOI khop `fixed`,
|
||||
nen khong the vua de khop fixed vua tu phat canh do - se thanh hai nguon,
|
||||
va TF KHONG BAO LOI, no chi cho ket qua nhay lung tung.
|
||||
|
||||
Da thu de khop thanh `floating` cho RSP bo qua. THAT BAI, hai ly do:
|
||||
1. urdf2sdf cua Gazebo huy luon link goc:
|
||||
"link[base_footprint] is not modeled in sdf"
|
||||
[FATAL] gazebo_ros_p3d: bodyName: base_footprint does not exist
|
||||
2. libkdl_parser.so doi nguoc lai:
|
||||
"Converting unknown joint type of joint '%s' into a fixed joint"
|
||||
-> RSP van phat canh do tren phan cung that.
|
||||
|
||||
Cach dung: khai hai khop REVOLUTE trong URDF va publish /joint_states. Do la
|
||||
co che RSP ho tro san, nen RSP van la nguon duy nhat cua moi canh TF.
|
||||
|
||||
============ ⚠️ NODE NAY GIU MOT CANH TF SONG CON ============
|
||||
base_footprint -> base_link noi phan dinh vi voi toan bo phan cam bien. Node
|
||||
chet la RSP khong con goc khop -> canh dung yen o gia tri cuoi (khong dut han
|
||||
nhu truong hop tu phat TF, nhung cloud se lech dan neu robot doi do nghieng).
|
||||
|
||||
Node duoc viet de KHONG BAO GIO ngung phat:
|
||||
- Mat IMU -> phat roll=pitch=0 (coi nhu phang) va canh bao, VAN phat
|
||||
- IMU cu -> nhu tren
|
||||
- Chua co IMU lan nao -> phat 0 ngay tu dau
|
||||
Va nen dat respawn="true" trong launch.
|
||||
|
||||
============ CACH DO ROLL/PITCH ============
|
||||
Bo loc bu (complementary filter), giong het gravity_align_nodelet de hai ben
|
||||
khong lech nhau:
|
||||
|
||||
tich phan gyro -> nhanh, muot, nhung TROI (da do: 5.2 do sau ~10 s)
|
||||
goc tu accel -> khong troi, nhung nhieu va sai khi robot tang toc
|
||||
tron: rp = alpha * rp_gyro + (1-alpha) * rp_accel
|
||||
|
||||
⚠️ Chi lay goc tu accel khi | |a| - g | < accel_gate, tuc robot khong tang toc
|
||||
dang ke. Khong co cong nay thi luc tang toc accel do ca gia toc chuyen dong
|
||||
va bo loc keo pitch di sai.
|
||||
⚠️ Loc thong thap accel TRUOC khi so voi cong. Da mac loi cong tren mau tho:
|
||||
pitch troi toi 5.2 do; loc xong con 0.02 do.
|
||||
"""
|
||||
|
||||
import math
|
||||
|
||||
import rospy
|
||||
from sensor_msgs.msg import Imu, JointState
|
||||
from std_msgs.msg import Float64MultiArray
|
||||
|
||||
GRAVITY = 9.80665
|
||||
|
||||
|
||||
class BaseTiltTF(object):
|
||||
def __init__(self):
|
||||
# ⚠️ Ten PHAI khop robot.urdf.xacro. Sai ten thi RSP im lang bo qua,
|
||||
# khong bao loi, va canh TF dung nguyen o 0.
|
||||
self.roll_joint = rospy.get_param('~roll_joint', 'base_roll_joint')
|
||||
self.pitch_joint = rospy.get_param('~pitch_joint', 'base_pitch_joint')
|
||||
|
||||
self.rate_hz = rospy.get_param('~rate', 50.0)
|
||||
self.alpha = rospy.get_param('~alpha', 0.98)
|
||||
self.accel_lpf_alpha = rospy.get_param('~accel_lpf_alpha', 0.05)
|
||||
self.accel_gate = rospy.get_param('~accel_gate', 0.5)
|
||||
self.imu_timeout = rospy.get_param('~imu_timeout', 0.5)
|
||||
# Chan do nghieng vo ly: IMU loi hoac dat sai chieu thi thà coi la phang
|
||||
# con hon lam lech ca ban do.
|
||||
self.max_tilt = rospy.get_param('~max_tilt', math.radians(25.0))
|
||||
|
||||
self.roll = 0.0
|
||||
self.pitch = 0.0
|
||||
self.ax_f = 0.0
|
||||
self.ay_f = 0.0
|
||||
self.az_f = GRAVITY
|
||||
self.have_imu = False
|
||||
self.last_imu = None
|
||||
self.warned = False
|
||||
|
||||
# /joint_states chap nhan NHIEU nguon publish: robot_state_publisher
|
||||
# gom theo TEN KHOP. Node nay chi phat hai khop nghieng; banh xe do
|
||||
# firmware MCU phat. Khong dam nhau.
|
||||
self.js_pub = rospy.Publisher('/joint_states', JointState, queue_size=10)
|
||||
self.rp_pub = rospy.Publisher('~roll_pitch', Float64MultiArray,
|
||||
queue_size=10)
|
||||
rospy.Subscriber(rospy.get_param('~imu_topic', '/imu/data_raw'),
|
||||
Imu, self.on_imu, queue_size=100)
|
||||
|
||||
rospy.loginfo('base_tilt_tf: publish /joint_states cho [%s, %s] @ %.0f Hz',
|
||||
self.roll_joint, self.pitch_joint, self.rate_hz)
|
||||
rospy.loginfo('base_tilt_tf: roll/pitch DO tu IMU, KHONG uoc luong. '
|
||||
'Mat IMU -> phat 0 va canh bao, KHONG ngung phat.')
|
||||
|
||||
# ---------------- IMU ----------------
|
||||
|
||||
def on_imu(self, msg):
|
||||
now = msg.header.stamp
|
||||
if self.last_imu is None:
|
||||
self.last_imu = now
|
||||
self.have_imu = True
|
||||
return
|
||||
|
||||
dt = (now - self.last_imu).to_sec()
|
||||
self.last_imu = now
|
||||
# Bo mau nhay lui hoac cach qua xa (bag tua lai, /clock nhay)
|
||||
if dt <= 0.0 or dt > 0.5:
|
||||
return
|
||||
|
||||
# 1. Tich phan gyro - muot nhung troi
|
||||
self.roll += msg.angular_velocity.x * dt
|
||||
self.pitch += msg.angular_velocity.y * dt
|
||||
|
||||
# 2. Loc thong thap accel TRUOC khi so voi cong
|
||||
a = msg.linear_acceleration
|
||||
k = self.accel_lpf_alpha
|
||||
self.ax_f = k * a.x + (1.0 - k) * self.ax_f
|
||||
self.ay_f = k * a.y + (1.0 - k) * self.ay_f
|
||||
self.az_f = k * a.z + (1.0 - k) * self.az_f
|
||||
|
||||
norm = math.sqrt(self.ax_f ** 2 + self.ay_f ** 2 + self.az_f ** 2)
|
||||
if norm < 1e-3 or abs(norm - GRAVITY) >= self.accel_gate:
|
||||
return # dang tang toc -> accel khong dang tin, chi giu gyro
|
||||
|
||||
# 3. Keo ve goc do tu trong luc
|
||||
roll_a = math.atan2(self.ay_f, self.az_f)
|
||||
pitch_a = math.atan2(-self.ax_f,
|
||||
math.sqrt(self.ay_f ** 2 + self.az_f ** 2))
|
||||
self.roll = self.alpha * self.roll + (1.0 - self.alpha) * roll_a
|
||||
self.pitch = self.alpha * self.pitch + (1.0 - self.alpha) * pitch_a
|
||||
|
||||
# ---------------- TF ----------------
|
||||
|
||||
def tilt_now(self, stamp):
|
||||
"""Tra ve (roll, pitch). Luon tra duoc gia tri, khong bao gio raise."""
|
||||
fresh = (self.have_imu and self.last_imu is not None and
|
||||
(stamp - self.last_imu).to_sec() < self.imu_timeout)
|
||||
if not fresh:
|
||||
if not self.warned:
|
||||
rospy.logwarn('base_tilt_tf: KHONG co IMU moi -> phat roll=pitch=0. '
|
||||
'Ban do 3D se SAI neu robot thuc su nghieng.')
|
||||
self.warned = True
|
||||
return 0.0, 0.0
|
||||
|
||||
if self.warned:
|
||||
rospy.loginfo('base_tilt_tf: IMU tro lai.')
|
||||
self.warned = False
|
||||
|
||||
r = max(-self.max_tilt, min(self.max_tilt, self.roll))
|
||||
p = max(-self.max_tilt, min(self.max_tilt, self.pitch))
|
||||
if r != self.roll or p != self.pitch:
|
||||
rospy.logwarn_throttle(
|
||||
5.0, 'base_tilt_tf: nghieng vuot nguong %.1f do -> da chan. '
|
||||
'Kiem tra huong lap IMU.', math.degrees(self.max_tilt))
|
||||
return r, p
|
||||
|
||||
def publish(self, _evt=None):
|
||||
stamp = rospy.Time.now()
|
||||
r, p = self.tilt_now(stamp)
|
||||
|
||||
# Chi phat GOC KHOP. robot_state_publisher dung URDF de dung TF
|
||||
# base_footprint -> base_roll_link -> base_link, gom ca do cao
|
||||
# wheel_radius trong <origin> cua base_roll_joint.
|
||||
# => khong con phai tu tinh quaternion, va khong the lech voi URDF.
|
||||
js = JointState()
|
||||
js.header.stamp = stamp
|
||||
js.name = [self.roll_joint, self.pitch_joint]
|
||||
js.position = [r, p]
|
||||
js.velocity = []
|
||||
js.effort = []
|
||||
self.js_pub.publish(js)
|
||||
|
||||
m = Float64MultiArray()
|
||||
m.data = [r, p, 1.0 if not self.warned else 0.0]
|
||||
self.rp_pub.publish(m)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
rospy.init_node('base_tilt_tf')
|
||||
node = BaseTiltTF()
|
||||
rospy.Timer(rospy.Duration(1.0 / node.rate_hz), node.publish)
|
||||
rospy.spin()
|
||||
@@ -72,11 +72,127 @@
|
||||
<!-- base_footprint: hinh chieu tren san (z=0). Nav stack dung frame nay. -->
|
||||
<link name="base_footprint"/>
|
||||
|
||||
<joint name="base_joint" type="fixed">
|
||||
<parent link="base_footprint"/>
|
||||
<child link="base_link"/>
|
||||
<origin xyz="0 0 ${wheel_radius}" rpy="0 0 0"/>
|
||||
</joint>
|
||||
<!--
|
||||
============ CANH base_footprint -> base_link ============
|
||||
Canh nay quyet dinh he thong co THUC SU 2.5D hay khong.
|
||||
|
||||
tilt_in_tf = false (mac dinh)
|
||||
Khop FIXED, rpy="0 0 0". robot_state_publisher phat static TF.
|
||||
Do nghieng DO tu IMU chi duoc dung trong
|
||||
perception_3d/gravity_align_nodelet, va chi cho octomap + costmap.
|
||||
=> RTAB-Map dat anh depth bang TF PHANG -> dung hinh 3D KHONG duoc
|
||||
bu nghieng. Pose van SE(2), ne vat can van 2.5D, nhung ban do 3D
|
||||
thi khong.
|
||||
|
||||
tilt_in_tf = true
|
||||
Khop FLOATING -> robot_state_publisher KHONG phat canh nay nua,
|
||||
nhuong cho scripts/base_tilt_tf.py phat kem roll/pitch do tu IMU.
|
||||
=> moi thu doc TF deu nhan duoc do nghieng, ke ca RTAB-Map.
|
||||
|
||||
============ ⚠️ VI SAO MAC DINH VAN LA false ============
|
||||
1. laser_link la CON cua base_link. Bat co nay thi LiDAR cung nghieng theo,
|
||||
khong chi camera. Ma RTAB-Map lay frame_id=base_footprint, nen no doi
|
||||
chinh duong 2D SLAM dang cho ATE 0.0214 m.
|
||||
2. Mo phong KHONG kiem chung duoc: san Gazebo phang, pitch do duoc 0.0006°,
|
||||
nen bat hay tat cung ra ket qua nhu nhau. Chi co y nghia tren san that
|
||||
co go cua va doc.
|
||||
3. Them mot diem hong don: base_tilt_tf.py chet la cay TF DUT lam doi, moi
|
||||
thu phia duoi mat het. Khop fixed thi khong bao gio hong.
|
||||
|
||||
=> Bat khi chuyen sang phan cung that, sau khi da do duoc do nghieng thuc
|
||||
te cua san. Xem docs/SIM_VS_REAL.md.
|
||||
-->
|
||||
<!--
|
||||
============ DO NGHIENG TRONG TF ============
|
||||
Nguyen tac 2.5D: pose la SE(2), roll/pitch thi DO. Cho dung de dat do
|
||||
nghieng do duoc la TF, khong phai pose.
|
||||
|
||||
Van de: mot canh TF chi duoc co MOT nguon phat, ma robot_state_publisher
|
||||
phat MOI khop `fixed`. Muon canh do dong thi phai dung co che RSP ho tro
|
||||
san: khop REVOLUTE dieu khien qua /joint_states.
|
||||
|
||||
use_sim=false (phan cung that):
|
||||
base_footprint =[base_roll_joint revolute quanh X]=> base_roll_link
|
||||
base_roll_link =[base_pitch_joint revolute quanh Y]=> base_link
|
||||
scripts/base_tilt_tf.py publish /joint_states cho hai khop nay.
|
||||
RSP lo phan TF -> mot nguon duy nhat, khong tranh chap.
|
||||
|
||||
use_sim=true (Gazebo):
|
||||
base_footprint =[base_joint fixed]=> base_link
|
||||
Giu nguyen ven ban da chay tot (ATE 0.0214 m).
|
||||
|
||||
⚠️ VI SAO TACH THEO use_sim, du no pha nguyen tac parity sim/real:
|
||||
Khop revolute la khop THAT voi Gazebo - no se mo phong vat ly hai khop do
|
||||
va chung se tu lac, va moi link phai co <inertial> rieng vi khong con
|
||||
duoc lumping nhu khop fixed. Trong sim thi do nghieng luon ~0 (san phang,
|
||||
da do pitch 0.0006°) nen khop revolute khong mang lai gi ma chi them rui ro.
|
||||
Ten frame ma phan con lai cua he dung - base_footprint, base_link - GIU
|
||||
NGUYEN o ca hai. Chi co base_roll_link la them, va khong ai subscribe no.
|
||||
|
||||
============ ⚠️ DA THU type="floating" VA THAT BAI ============
|
||||
Y dinh: de khop nay thanh `floating` thi robot_state_publisher se khong
|
||||
phat canh nua, nhuong cho scripts/base_tilt_tf.py phat kem roll/pitch.
|
||||
KHONG LAM DUOC, hai ly do doc lap, ca hai deu da do duoc:
|
||||
|
||||
1. Gazebo huy luon link goc:
|
||||
urdf2sdf: link[base_footprint] is not modeled in sdf.
|
||||
urdf2sdf: [1] child joints ignored / [1] child links ignored
|
||||
[FATAL] gazebo_ros_p3d: bodyName: base_footprint does not exist
|
||||
-> mat /ground_truth/odom, mat /scan (0 ban tin), EKF khong co odom,
|
||||
map->base_footprint va odom->base_link DUT.
|
||||
|
||||
2. kdl_parser KHONG ton trong `floating`:
|
||||
libkdl_parser.so: "Converting unknown joint type of joint '%s'
|
||||
into a fixed joint"
|
||||
robot_state_publisher dung thu vien do, nen tren phan cung that no van
|
||||
phat canh nay -> TRANH CHAP hai nguon voi base_tilt_tf.py. TF khong bao
|
||||
loi, chi cho ket qua nhay lung tung.
|
||||
|
||||
=> Giu `fixed`. Do nghieng hien chi den duoc octomap/costmap qua
|
||||
perception_3d/gravity_align_nodelet; ban do 3D cua RTAB-Map van dat
|
||||
bang TF phang. Mon no nay CHUA TRA, xem docs/SIM_VS_REAL.md.
|
||||
|
||||
Huong sua dung: khai roll/pitch thanh HAI KHOP REVOLUTE va cho
|
||||
base_tilt_tf.py publish /joint_states thay vi publish TF - do la co che
|
||||
robot_state_publisher ho tro san. Chua lam vi chua kiem chung duoc.
|
||||
-->
|
||||
<xacro:if value="$(arg use_sim)">
|
||||
<joint name="base_joint" type="fixed">
|
||||
<parent link="base_footprint"/>
|
||||
<child link="base_link"/>
|
||||
<origin xyz="0 0 ${wheel_radius}" rpy="0 0 0"/>
|
||||
</joint>
|
||||
</xacro:if>
|
||||
|
||||
<xacro:unless value="$(arg use_sim)">
|
||||
<!-- Link trung gian. Khoi luong khong dang ke: no chi de mang mot bac tu
|
||||
do, khong phai vat the that. Van phai co <inertial> vi khop revolute
|
||||
khong duoc lumping nhu khop fixed. -->
|
||||
<link name="base_roll_link">
|
||||
<inertial>
|
||||
<mass value="0.001"/>
|
||||
<inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6"/>
|
||||
</inertial>
|
||||
</link>
|
||||
|
||||
<!-- Gioi han ±25°: chan gia tri vo ly khi IMU loi hoac lap sai chieu.
|
||||
base_tilt_tf.py cung chan o cung nguong, hai lop doc lap. -->
|
||||
<joint name="base_roll_joint" type="revolute">
|
||||
<parent link="base_footprint"/>
|
||||
<child link="base_roll_link"/>
|
||||
<origin xyz="0 0 ${wheel_radius}" rpy="0 0 0"/>
|
||||
<axis xyz="1 0 0"/>
|
||||
<limit lower="${-25*pi/180}" upper="${25*pi/180}" effort="0" velocity="0"/>
|
||||
</joint>
|
||||
|
||||
<joint name="base_pitch_joint" type="revolute">
|
||||
<parent link="base_roll_link"/>
|
||||
<child link="base_link"/>
|
||||
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||
<axis xyz="0 1 0"/>
|
||||
<limit lower="${-25*pi/180}" upper="${25*pi/180}" effort="0" velocity="0"/>
|
||||
</joint>
|
||||
</xacro:unless>
|
||||
|
||||
<!-- Tam hop than trong he base_link. Cong ground_clearance de day hop
|
||||
KHONG cham san; lui theo x de cam bien phia truoc khong bi che. -->
|
||||
|
||||
Reference in New Issue
Block a user