Error when running StetchBodyNode from stretch_driver

In a python file I have imported the StretchBodyNode from stretch_driver.py as a class and am running the following code.

node = StretchBodyNode()
node.main()

However, when I call main, I get the following error:

Traceback (most recent call last):
  File "stretch_driver.py", line 622, in <module>
    node.main()
  File "stretch_driver.py", line 513, in main
    filename = rospy.get_param('~controller_calibration_file')
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 467, in get_param
    return _param_server[param_name] #MasterProxy does all the magic for us
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/msproxy.py", line 123, in __getitem__
    raise KeyError(key)
KeyError: '~controller_calibration_file'

I"m not sure what the issue is - there are no similar errors online. Could it be because I am just trying to run the python file and have not integrated it with anything in ROS?

Hi @Robot_Lover, your diagnosis is correct. Trying to run the StretchBodyNode directly using the Python interpreter will not work because StretchBodyNode is a ROS node that uses the ROS ecosystem for various functionalities, such as the parameter server, message passing, and much more.

In particular, the KeyError you’re seeing above is appearing because the ROS parameter sever is not active. This parameter server is tied to a ROS master, so we can launch a master and the StretchBodyNode node using the following commands:

roscore

[in a separate terminal, because the old one will not accept new commands until you have quit roscore using Ctrl-C]

rosrun stretch_core stretch_driver

roscore launches a master here, and the rosrun command runs the stretch_driver node. With the node active, you can interact with it by passing it ROS messages, whether from the commandline or from another Python/C++ node. You may refer to the Python ROS Node tutorial on the ROS wiki to see how to do this.

Hi @bshah ,

Thanks for your response! I’ve looked through the Python ROS Node tutorial and I understand how to create publisher/subscriber nodes that communicate with each other, but I want to get clarification on how I would pass the stretch_driver node instructions.

Would I be publishing/subscribing to topics contained in stretch_driver (along the vein of

pub = rospy.Publisher('chatter', String, queue_size=10)
or 
rospy.Subscriber("chatter", String, callback)

Thank you so much for your help! Also is there a timeline for when the ROS tutorials for stretch or the stretch simulator will be out?

Hi @Robot_Lover, that’s the right idea. You can create a ROS package with a single node that defines subscribers and publishers. By publishing to the right topics, you can give the robot commands to execute. You may find a list of these topics using the “rostopic” tool as discussed in this post.

In terms of timing, we plan to begin releasing ROS tutorials throughout the summer, with the first one coming near start of June. Additionally, we are tentatively looking at a beta release for the Stretch simulator sometime in the fall.

Glad to help and let me know if you have more questions!

Hi Binit,

Two additional questions. First, if I’m trying to create a Python class to perform basic actions on the Stretch Robot, should I initialize the class as type StretchBodyNode or type HelloNode? I noticed that in the demos, only type HelloNode was used to make the class.

In addition, I’m still struggling a bit with regards to actually getting the robot to move using commands from the command line by publishing a topic. Is it possible that you could write out a sample command that you would use to move the base of the robot forward by x units by publishing to a topic once you’ve started roscore and rosrun stretch_core stretch_driver?

Thanks!