Skip to content

Commit 486c078

Browse files
authored
Merge pull request #9 from SchillingRobotics/ctg-meas-state-twist-body
Modify CTG to expect twist in measured state input to be in body frame
2 parents dfbd63e + 3cc05db commit 486c078

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

joint_trajectory_controller/src/cartesian_trajectory_generator.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "joint_trajectory_controller/cartesian_trajectory_generator.hpp"
1616

17+
#include "eigen3/Eigen/Eigen"
1718
#include "tf2/transform_datatypes.h"
1819

1920
#include "controller_interface/helpers.hpp"
@@ -398,12 +399,28 @@ bool CartesianTrajectoryGenerator::read_state_from_hardware(JointTrajectoryPoint
398399
state.positions[4] = orientation_angles[1];
399400
state.positions[5] = orientation_angles[2];
400401

401-
state.velocities[0] = measured_state->twist.twist.linear.x;
402-
state.velocities[1] = measured_state->twist.twist.linear.y;
403-
state.velocities[2] = measured_state->twist.twist.linear.z;
404-
state.velocities[3] = measured_state->twist.twist.angular.x;
405-
state.velocities[4] = measured_state->twist.twist.angular.y;
406-
state.velocities[5] = measured_state->twist.twist.angular.z;
402+
////// Convert measured twist which is in body frame to world frame since CTG/JTC expects state in world frame
403+
404+
Eigen::Quaterniond q_body_in_world(
405+
measured_state->pose.pose.orientation.w, measured_state->pose.pose.orientation.x,
406+
measured_state->pose.pose.orientation.y, measured_state->pose.pose.orientation.z);
407+
408+
Eigen::Vector3d linear_vel_body(
409+
measured_state->twist.twist.linear.x, measured_state->twist.twist.linear.y,
410+
measured_state->twist.twist.linear.z);
411+
auto linear_vel_world = q_body_in_world * linear_vel_body;
412+
413+
Eigen::Vector3d angular_vel_body(
414+
measured_state->twist.twist.angular.x, measured_state->twist.twist.angular.y,
415+
measured_state->twist.twist.angular.z);
416+
auto angular_vel_world = q_body_in_world * angular_vel_body;
417+
418+
state.velocities[0] = linear_vel_world[0];
419+
state.velocities[1] = linear_vel_world[1];
420+
state.velocities[2] = linear_vel_world[2];
421+
state.velocities[3] = angular_vel_world[0];
422+
state.velocities[4] = angular_vel_world[1];
423+
state.velocities[5] = angular_vel_world[2];
407424

408425
state.accelerations.clear();
409426
return true;

0 commit comments

Comments
 (0)