ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Problem adding third party library

asked 2018-03-14 14:05:54 -0500

olacv15 gravatar image

Hi i am currently trying to make ROS node for sending CAN bus messages.

I need to import a python 2.7 library named "can" in the script. I tried to add the path to this library to my CMAKE list, but with no luck.

Here is the script and errors i am getting.

-- ==> add_subdirectory(motor_controller)
CMake Error at motor_controller/CMakeLists.txt:153 (target_link_libraries):
  Cannot specify link libraries for target "motor_controller_node" which is
  not built by this project.

My node python script

## # In ROS, nodes are uniquely named. If two nodes with the same
    # name are launched, the previous one is kicked off. The
    # anonymous=True flag means that rospy will choose a unique
    # name for our 'listener' node so that multiple listeners can
    # run simultaneously.


import rospy, can
from sensor_msgs.msg import RegionOfInterest

bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=500000)

msg = can.Message(arbitration_id=0x5F0,data=[0],extended_id=False)

msg.data[0] = 1



def callback(data):
        rospy.loginfo(data.y_offset)
        bus.send(msg)



def listener():

    rospy.init_node('listener', anonymous=True)

    rospy.Subscriber('MotorSetpoint', RegionOfInterest, callback)

    # spin() simply keeps python from exiting until this node is stopped
    rospy.spin()

if __name__ == '__main__':
    listener()

my attempt to link the library:

FIND_LIBRARY(EXT_LIBRARY can /usr/local/lib/python2.7/dist-packages/python_can-2.1.1.dev0-py2.7.egg/can/__init__.pyc
)

target_link_libraries(${PROJECT_NAME}_node
   ${catkin_LIBRARIES}
   ${EXT_LIBRARY}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-14 14:13:09 -0500

gvdhoorn gravatar image

CMakeLists.txt is not used for dependency management or resolution with Python packages.

If you can start a python interpreter from the command line and do import can, it should work in your Python script in your ROS package.

edit flag offensive delete link more

Comments

Thank you @gvdhoorn! Got it working now. I just started using ROS, and plans to use it to build a autonomous quad with generated navigation and stabilization nodes from simulink

olacv15 gravatar image olacv15  ( 2018-03-15 03:33:19 -0500 )edit

Simulink can generate Python code now?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-15 03:34:36 -0500 )edit

Simulink still generates cpp, but communication between my Simulink cpp node and CAN bus python node works fine.

olacv15 gravatar image olacv15  ( 2018-03-15 03:37:35 -0500 )edit

Ok. No real-time requirements then?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-15 04:07:55 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-14 14:05:54 -0500

Seen: 266 times

Last updated: Mar 14 '18