33
44#include < gz/sim/System.hh>
55#include < gz/sim/Model.hh>
6- #include < gz/transport/Node.hh>
7- #include < gz/msgs/twist.pb.h>
8- #include < gz/math/Pose3.hh>
96#include < gz/math/Rand.hh>
107
118#include < rclcpp/rclcpp.hpp>
129#include < nav_msgs/msg/odometry.hpp>
1310
14- #include < mutex>
1511#include < string>
1612#include < memory>
1713
@@ -35,55 +31,44 @@ namespace custom_plugins
3531 const gz::sim::EntityComponentManager &_ecm) override ;
3632
3733 private:
38- void OnCmdVel (const gz::msgs::Twist &_msg);
39-
40- // Keeps angles bounded in [-pi, pi] so yaw differences remain well behaved.
4134 double NormalizeAngle (double _angle) const ;
4235
4336 gz::sim::Model model_;
44- gz::transport::Node gz_node_;
4537
4638 std::shared_ptr<rclcpp::Node> ros_node_;
4739 rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr ros_pub_;
4840
4941 std::string ros_topic_;
50- std::string gz_cmd_vel_topic_;
5142 std::string frame_id_;
5243 std::string child_frame_id_;
5344
54- bool initialized_{false };
45+ // Wheel joint entities resolved once in Configure.
46+ gz::sim::Entity left_joint_entity_{gz::sim::kNullEntity };
47+ gz::sim::Entity right_joint_entity_{gz::sim::kNullEntity };
5548
56- // Internal odometric estimate that is propagated only with noisy increments .
57- // This is the state published as odom_noisy and it is allowed to drift.
58- gz::math::Pose3d noisy_pose_internal_ ;
49+ // Differential drive kinematics — must match the DiffDrive plugin values .
50+ double wheel_radius_{ 0.033 };
51+ double wheel_separation_{ 0.287 } ;
5952
60- // True simulator pose used only to extract the real motion increment
61- // between consecutive simulation steps.
62- gz::math::Pose3d last_true_pose_ ;
53+ // Last joint positions used to compute per-tick angle deltas.
54+ double last_left_pos_{ 0.0 };
55+ double last_right_pos_{ 0.0 } ;
6356
6457 std::chrono::steady_clock::duration last_update_time_{0 };
6558
66- // Latest commanded velocities are still stored because they are useful
67- // as auxiliary information and to keep compatibility with the original plugin.
68- double current_v_{0.0 };
69- double current_w_{0.0 };
70-
71- // Last noisy body-frame velocities published in the odometry message.
72- double last_noisy_linear_velocity_{0.0 };
73- double last_noisy_angular_velocity_{0.0 };
74-
75- std::mutex mutex_;
59+ bool initialized_{false };
7660
77- // Legacy generic noise parameter kept for compatibility with the original SDF.
78- double gaussian_noise_coeff_{0.0 };
61+ // Accumulated noisy odometry estimate.
62+ double noisy_x_{0.0 };
63+ double noisy_y_{0.0 };
64+ double noisy_yaw_{0.0 };
7965
80- // Standard odometry motion-model coefficients.
81- // They control how rotation and translation uncertainties affect each other.
82- double alpha1_{0.0 };
83- double alpha2_{0.0 };
84- double alpha3_{0.0 };
85- double alpha4_{0.0 };
66+ // Standard odometry motion-model coefficients (Probabilistic Robotics, Ch. 5).
67+ double alpha1_{0.0 }; // rotation noise from rotation
68+ double alpha2_{0.0 }; // rotation noise from translation
69+ double alpha3_{0.0 }; // translation noise from translation
70+ double alpha4_{0.0 }; // translation noise from rotation
8671 };
8772}
8873
89- #endif
74+ #endif
0 commit comments