0
$\begingroup$

Rosanswers logo

I have a Robai Cyton gamma arm that I'm attempting to connect to with ROS by trying to call a Python script from a C++ program.

What I want to do is use C++ and OpenCV to get a video from an Xbox Kinect. From the kinect video I want to be able to click on a point in the image and send the x-y-z position (after converting them to my robot coordinate system) to a Python Script using OpenRave to figure out the inverse kinematics. After the position of my joint angles are known I want to use ROS to send them to the robot.

Currently, I can send the x-y-z locations and find the inverse kinematics no problem and everything works together nicely when I don't have import rospy in my python script(not trying to send the robot my joint angles). I also can move the robot with a different python script I have so I know I can connect with and move it.

Without the ROS commands to try to publish to the robot when I run the c++ exe I get the joint angles for the different links of my robot.

getIndicesFromJointNames [0] ['link1']
[ 1.          0.78545125  0.62655888  0.96602943  1.01751733  1.06180138
 -0.7132951 ]

When I add the command

import rospy 

and subsequently try to publish them to the robot

> rospy.init_node('shoulder_roll')   
> ...
> ...
pub = rospy.Publisher('/theta_2/command', Float64)
pub.publish(Float64(sol.item(1)))
pub = rospy.Publisher('/theta_3/command', Float64)
pub.publish(Float64(sol.item(2)*-1)) 
pub = rospy.Publisher('/theta_4/command', Float64)
pub.publish(Float64(sol.item(3)))
    

I get the error

 Traceback (most recent call last):
  File "/home/nick/fuerte_workspace/Robai/bin/test.py", line 22, in run
    import rospy
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/rospy/client.py", line 53, in <module>
    import rospy.core
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/rospy/core.py", line 66, in <module>
    from rospy.names import *
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/rospy/names.py", line 86, in <module>
    _mappings = load_mappings(sys.argv)
AttributeError: 'module' object has no attribute 'argv'

Any help or suggestions would be appreciated

Thanks, Nick


Originally posted by nickd on ROS Answers with karma: 92 on 2013-08-05

Post score: 1


Original comments

Comment by mdtobi on 2013-12-06:
Hi Nick, Did you make any progress on this issue? I'm asking, because I'm receiving the same error while importing rospy in a c++ class. I've already looked into the names.py but the load_mappings object has an 'argv' attribute, so the error-message is kind of misguiding me. Kind regards, Tobi

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Ok I just found the reason for this failure: You need to add PySys_SetArgv(argc, argv); right after Py_Initialize(); to assign the c++-arguments over to the Python interpreter which otherwise would be started without any arguments. After appending this line, sys.argv will be set and the rospy module would be loaded.


Originally posted by mdtobi with karma: 36 on 2013-12-07

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.