Skip to content

Commit 232626e

Browse files
committed
Fix frame and gravity direction problem
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
1 parent b24dc5c commit 232626e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ur_controllers/src/gpio_controller.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ bool GPIOController::setGravity(const ur_msgs::srv::SetGravity::Request::SharedP
581581
ur_msgs::srv::SetGravity::Response::SharedPtr resp)
582582
{
583583
// Check transform
584-
const std::string base_frame_name = params_.tf_prefix + "base_link";
584+
const std::string base_frame_name = params_.tf_prefix + "base";
585585
geometry_msgs::msg::TransformStamped tf_to_base_link;
586586
try {
587587
tf_to_base_link = tf_buffer_->lookupTransform(base_frame_name, req->gravity.header.frame_id, tf2::TimePointZero);
@@ -591,11 +591,14 @@ bool GPIOController::setGravity(const ur_msgs::srv::SetGravity::Request::SharedP
591591
return false;
592592
}
593593

594+
// The passed gravity vector is the direction of gravity (towards the Earth)
595+
// But the UR Client Library call is expecting anti-gravity (away from Earth), so negate here
596+
tf2::Vector3 anti_gravity(-1 * req->gravity.vector.x, -1 * req->gravity.vector.y, -1 * req->gravity.vector.z);
597+
594598
// Rotate the gravity vector
595-
tf2::Vector3 raw_gravity(req->gravity.vector.x, req->gravity.vector.y, req->gravity.vector.z);
596599
tf2::Quaternion quat;
597600
tf2::fromMsg(tf_to_base_link.transform.rotation, quat);
598-
tf2::Vector3 transformed_gravity = tf2::quatRotate(quat, raw_gravity);
601+
tf2::Vector3 transformed_gravity = tf2::quatRotate(quat, anti_gravity);
599602

600603
// reset success flag
601604
std::ignore = command_interfaces_[CommandInterfaces::GRAVITY_ASYNC_SUCCESS].set_value(ASYNC_WAITING);

0 commit comments

Comments
 (0)