0
$\begingroup$

Rosanswers logo

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}

Originally posted by olacv15 on ROS Answers with karma: 3 on 2018-03-14

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2018-03-14

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by olacv15 on 2018-03-15:
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

Comment by gvdhoorn on 2018-03-15:
Simulink can generate Python code now?

Comment by olacv15 on 2018-03-15:
Simulink still generates cpp, but communication between my Simulink cpp node and CAN bus python node works fine.

Comment by gvdhoorn on 2018-03-15:
Ok. No real-time requirements then?

$\endgroup$

Your Answer

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