Automating terminal commands of ROS using python script

asked 2019-06-19 05:21:40 -0500

691TReilly gravatar image

I am currently trying to write an executable program in python that runs the following ROS command: rostopic echo dvrk/PSM1/position_cartesian_current however despite reading the ROS Tutorials, I am unsure how to go about doing this. Within a file called arm.pythe following subscriber and definition already exist:

rospy.Subscriber(self.__full_ros_namespace + '/position_cartesian_current', PoseStamped, self.__position_cartesian_current_cb)

def __position_cartesian_current_cb(self, data):
        self.__position_cartesian_current = posemath.fromMsg(data.pose)

Am I supposed to reuse this subscriber and definition in the automated python script? After obtaining the current Cartesian position, the robot will subsequently be moved to a different position, which can currently be accomplished using ROS commands in the terminal, however, the aim is to write a python script that automates these commands. Any help would be greatly appreciated!

edit retag flag offensive close merge delete

Comments

This is technically not an answer, but seeing as you're basically asking how to write a Python subscriber to the dvrk/PSM1/position_cartesian_current topic: would following Writing a Simple Publisher and Subscriber (Python) - Writing the Subscriber Node and then changing the topic type and name not work?

gvdhoorn gravatar imagegvdhoorn ( 2019-06-19 06:46:41 -0500 )edit