Skip to content

Commit bb8ed1f

Browse files
author
saurabh borse
committed
fixed odometry for wheel encoders
1 parent 443b3b8 commit bb8ed1f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

robotino_simulation/include/robotino_simulation/robotino_driver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RobotinoDriver : public webots_ros2_driver::PluginInterface {
8484
std::thread act_thread_;
8585
double act_frequency_ = 10.0;
8686

87-
std::string odom_source_ = "encoders";
87+
std::string odom_source_ = "gps";
8888
};
8989
} // namespace robotino_driver
9090
#endif

robotino_simulation/src/robotino_driver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ void RobotinoDriver::init(
103103
wb_motor_set_velocity(motors_[0], angular_velocity[1]);
104104
wb_motor_set_velocity(motors_[1], angular_velocity[2]);
105105

106-
// Uncomment the following code to use the odometry from the wheel sensors
107-
if (odom_source_ == "encoders") {
106+
if (odom_source_ == "encoder") {
108107
double curr_time_ = wb_robot_get_time();
109108
double time_diff_ = curr_time_ - last_sample_time_;
110109
int sec_ = static_cast<int>(curr_time_);
@@ -113,7 +112,9 @@ void RobotinoDriver::init(
113112
time_stamp_.sec = sec_;
114113
time_stamp_.nanosec = nanosec_;
115114
read_data();
116-
publish_odom(time_stamp_, time_diff_);
115+
if (time_diff_ != 0.0) {
116+
publish_odom(time_stamp_, time_diff_);
117+
}
117118
last_sample_time_ = curr_time_;
118119
}
119120
{
@@ -245,7 +246,6 @@ void RobotinoDriver::publish_odom(const TimeStamp &time_stamp,
245246
double w2 = (wheel2_ticks - prev_wheel2_ticks_) / (time_diff);
246247

247248
auto velocity = inverse_kinematics(w0, w1, w2);
248-
249249
double phi = prev_odom_omega_ + (velocity[2] * time_diff);
250250
double x = prev_odom_x_ + (((velocity[0] * cos(phi)) - (velocity[1] * sin(phi))) * time_diff);
251251
//double x = prev_odom_x_ + (velocity[0]*time_diff);

0 commit comments

Comments
 (0)