Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues Calibrating with Zed2 Camera. #147

Open
jide07 opened this issue Jan 9, 2025 · 0 comments
Open

Issues Calibrating with Zed2 Camera. #147

jide07 opened this issue Jan 9, 2025 · 0 comments

Comments

@jide07
Copy link

jide07 commented Jan 9, 2025

I am trying to calibrate using Franka arm with the zed2 camera. This first problem is knowing which branch of the tf tree from zed2 I want to attach with the panda_link8(pand_hand), I am doing eye-in-hand calibration,
Here is what the zed2 tree looks like
Image

I have tried to link pand_link8 with both base_link and zed2_base_link. after getting the calibrated result, and I publish the static transform, the zed2 tree get disconnected, the map->odom part of the tree is required for the zed camera to work(I assume), so I linked the panda_link0 to the map of zed2.

I got the calibration results but the arm is not moving, so I assume the calibration with map is wrong?

Here's my question
Is the calibration result wrong and how do I know here what I have

  <!-- The rpy in the comment uses the extrinsic XYZ convention, which is the same as is used in a URDF. See
       http://wiki.ros.org/geometry2/RotationMethods and https://en.wikipedia.org/wiki/Euler_angles for more info. -->
  <!-- xyz="0.0183375 -0.278508 -0.223526" rpy="3.10416 -0.0439826 0.0656729" -->
  <node pkg="tf2_ros" type="static_transform_publisher" name="camera_link_broadcaster"
      args="0.0183375 -0.278508 -0.223526   0.999031 -0.0332282 -0.0213595 0.0194235 panda_hand map" />
</launch>

Why is this code not working

import sys
import rospy
import moveit_commander
import tf2_ros
import geometry_msgs.msg
from geometry_msgs.msg import Pose
from tf2_geometry_msgs import do_transform_pose

# Global variable to store the last pose to compare with the new pose
last_pose = None
threshold = 0.01  # Minimum movement distance (in meters)

def move_to_goal(target_pose, move_group):
    # Set the target pose for the arm and execute the movement
    move_group.set_pose_target(target_pose)
    rospy.loginfo("Planning the trajectory")
    plan = move_group.go(wait=True)

    if plan:
        rospy.loginfo("Move command executed successfully")
    else:
        rospy.logwarn("Move command failed")

    # Clear the target to allow for future movements
    move_group.stop()
    move_group.clear_pose_targets()

def callback(msg, args):
    move_group, tf_buffer = args  # Unpack the arguments

    global last_pose
    detected_pose = msg  # Keep the PoseStamped message as it is

    rospy.loginfo("Received detected pose: Position (x: %f, y: %f, z: %f), Orientation (x: %f, y: %f, z: %f, w: %f)",
                  detected_pose.pose.position.x, detected_pose.pose.position.y, detected_pose.pose.position.z,
                  detected_pose.pose.orientation.x, detected_pose.pose.orientation.y, detected_pose.pose.orientation.z, detected_pose.pose.orientation.w)

    try:
        # Transform the pose
        transform = tf_buffer.lookup_transform('panda_link0', 'map', rospy.Time(0), rospy.Duration(1.0))
        transformed_pose = do_transform_pose(detected_pose, transform)  # Pass the full PoseStamped object

        rospy.loginfo("Transformed pose: Position (x: %f, y: %f, z: %f), Orientation (x: %f, y: %f, z: %f, w: %f)",
                      transformed_pose.pose.position.x, transformed_pose.pose.position.y, transformed_pose.pose.position.z,
                      transformed_pose.pose.orientation.x, transformed_pose.pose.orientation.y, transformed_pose.pose.orientation.z, transformed_pose.pose.orientation.w)

        if last_pose is None:
            last_pose = transformed_pose.pose
            move_to_goal(transformed_pose.pose, move_group)
        else:
            distance = ((last_pose.position.x - transformed_pose.pose.position.x) ** 2 +
                        (last_pose.position.y - transformed_pose.pose.position.y) ** 2 +
                        (last_pose.position.z - transformed_pose.pose.position.z) ** 2) ** 0.5

            if distance > threshold:
                last_pose = transformed_pose.pose
                move_to_goal(transformed_pose.pose, move_group)
            else:
                rospy.loginfo("No significant movement detected, skipping arm movement.")

    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException) as e:
        rospy.logerr("TF Error: %s", str(e))


def listener():
    # Initialize the moveit_commander and rospy node
    moveit_commander.roscpp_initialize(sys.argv)
    rospy.init_node('move_robot', anonymous=True)

    # Initialize the MoveGroupCommander for the arm
    group_name = "panda_arm"  # Adjust if needed
    move_group = moveit_commander.MoveGroupCommander(group_name)

    # Initialize TF2 listener
    tf_buffer = tf2_ros.Buffer()
    tf_listener = tf2_ros.TransformListener(tf_buffer)

    # Subscribe to the detected object position topic
    # rospy.Subscriber("/detected_object_position", geometry_msgs.msg.PoseStamped, callback, (move_group, tf_buffer))
    rospy.Subscriber("/detected_object_position", geometry_msgs.msg.PoseStamped, callback, (move_group, tf_buffer))


    rospy.spin()

if __name__ == "__main__":
    listener()

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant