|
14 | 14 |
|
15 | 15 | #include "joint_trajectory_controller/cartesian_trajectory_generator.hpp"
|
16 | 16 |
|
| 17 | +#include "eigen3/Eigen/Eigen" |
17 | 18 | #include "tf2/transform_datatypes.h"
|
18 | 19 |
|
19 | 20 | #include "controller_interface/helpers.hpp"
|
@@ -398,12 +399,28 @@ bool CartesianTrajectoryGenerator::read_state_from_hardware(JointTrajectoryPoint
|
398 | 399 | state.positions[4] = orientation_angles[1];
|
399 | 400 | state.positions[5] = orientation_angles[2];
|
400 | 401 |
|
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]; |
407 | 424 |
|
408 | 425 | state.accelerations.clear();
|
409 | 426 | return true;
|
|
0 commit comments