callback(data) not updating
I am using callback(data) to get the data from the subscriber, however after one iteration it's not updating. I tried trying solution of other people but that is not working for me.
#!/usr/bin/env python3
import rospy
from std_msgs.msg import String
from rospy.numpy_msg import numpy_msg
from rospy_tutorials.msg import Floats
import sys
import copy
import rospy
import time
import moveit_commander
import moveit_msgs.msg
import geometry_msgs.msg
from math import pi
from std_msgs.msg import String
from moveit_commander.conversions import pose_to_list
from tf import TransformListener
global my_data
def callback(data):
my_data = data.data
my_data = my_data.astype("float64")
# rospy.loginfo(my_data)
# moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node("move_group_python_interface_tutorial", anonymous=True)
robot = moveit_commander.RobotCommander()
scene = moveit_commander.PlanningSceneInterface()
_commander = moveit_commander.move_group.MoveGroupCommander("xarm{}".format(6))
display_trajectory_publisher = rospy.Publisher(
"/move_group/display_planned_path",
moveit_msgs.msg.DisplayTrajectory,
queue_size=20,
)
# We can get the name of the reference frame for this robot:
planning_frame = _commander.get_planning_frame()
print("============ Reference frame: %s" % planning_frame)
# We can also print the name of the end-effector link for this group:
eef_link = _commander.get_end_effector_link()
print("============ End effector: %s" % eef_link)
# We can get a list of all the groups in the robot:
group_names = robot.get_group_names()
print("============ Robot Groups:", robot.get_group_names())
# Sometimes for debugging it is useful to print the entire state of the
# robot:
print("============ Printing robot state")
print(robot.get_current_state())
print("")
current_pose = _commander.get_current_pose(end_effector_link="link6").pose
print(f"The current pose is {current_pose}")
pose_goal = geometry_msgs.msg.Pose()
print(f"valuesssss {my_data[0]},{my_data[1]},{my_data[2]}")
pose_goal.position.x = my_data[0]
pose_goal.position.y = my_data[1]
pose_goal.position.z = my_data[2]
pose_goal.orientation.x = 0.1375399725278269
pose_goal.orientation.y = 0.13221897080143274
pose_goal.orientation.z = 0.6228175168854516
pose_goal.orientation.w = 0.7587484697697222
print(pose_goal)
_commander.set_pose_target(pose_goal)
_commander.set_goal_tolerance(10e-6)
rospy.loginfo("Planning Trajectory to Pose 1")
plan1 = _commander.plan()
rospy.loginfo("Done Planning Trajectory to Pose 1")
rospy.loginfo("Executing Trajectory to Pose 1")
success = _commander.go(wait=True)
current_pose = _commander.get_current_pose(end_effector_link="link6").pose
print(f"The current pose at the end is {current_pose}")
rospy.loginfo("Done Executing Trajectory to Pose 1")
_commander.stop()
def listener():
rospy.init_node("move_group_python_interface_tutorial", anonymous=True)
s = rospy.Subscriber("marker_wrt_base_pose", numpy_msg(Floats), callback)
rospy.spin()
if __name__ == "__main__":
listener()
We don’t need
rospy.init_node
inside the callback. There are many more issues with the above code. I suggest posting the code which runs!I have changed the dummy code to original one, please guide me to resolve this issue.
There are many issues with the code. Thus, it is better to spend some time understanding the concepts. Nevertheless, please don't instantiate
rospy.init_node
,moveit_commander
, androspy.Publisher
inside the callback.