Skip to content

Commit

Permalink
Merge pull request #4 from SwarmUS/fix/SWARINFO-697/odom_velocities
Browse files Browse the repository at this point in the history
Fix velocities calculated in the odom topic
  • Loading branch information
etienn8 authored Nov 19, 2021
2 parents 21462f7 + 00f210d commit 0107f20
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/diffdrive_roscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ namespace roboclaw {
delta_2 = tmp;
}

double u_w = ((delta_1 + delta_2) / steps_per_meter) / 2.0;
double u_p = ((delta_2 - delta_1) / steps_per_meter);
double translation_displacement = ((delta_1 + delta_2) / steps_per_meter) / 2.0;
double angular_displacement = ((delta_2 - delta_1) / steps_per_meter);

double delta_x = u_w * cos(last_theta);
double delta_y = u_w * sin(last_theta);
double delta_theta = u_p / base_width;
double delta_x = translation_displacement * cos(last_theta);
double delta_y = translation_displacement * sin(last_theta);
double delta_theta = angular_displacement / base_width;

double cur_x = last_x + delta_x;
double cur_y = last_y + delta_y;
Expand All @@ -211,14 +211,14 @@ namespace roboclaw {

last_time = current_time;

// Position
// Position in the odom frame
odom.pose.pose.position.x = cur_x;
odom.pose.pose.position.y = cur_y;

// Velocity
odom.twist.twist.linear.x = (cur_x - last_x)/dt;
odom.twist.twist.linear.y = (cur_y - last_y)/dt;
odom.twist.twist.angular.z = (cur_theta - last_theta)/dt;
// Velocity in the base_footprint frame
odom.twist.twist.linear.x = translation_displacement/dt;
odom.twist.twist.linear.y = 0;
odom.twist.twist.angular.z = delta_theta/dt;

tf::Quaternion quaternion = tf::createQuaternionFromRPY(0.0, 0.0, cur_theta);
odom.pose.pose.orientation.w = quaternion.w();
Expand Down

0 comments on commit 0107f20

Please sign in to comment.