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

Problem while running C++ and Python node together in ROS

asked 2018-05-02 09:03:03 -0600

rajavardhanr6 gravatar image

updated 2018-05-03 08:32:15 -0600

gvdhoorn gravatar image

Hi everyone,

I had designed a controller in simulink. I had generated ros c++ code using robotics system toolbox from mathworks. I'm planning to integrate with the existing crazyflie ros library. All my files in crazyflie ros library are in python and the node i had generated from simulink is in c++. I'm getting an error "If it is a script, you may be missing #! declaration at the top" , when i'm trying to execute roslaunch. I see this command at the top of every python file in my library "#!/usr/bin/env python". I do understand that it is just telling that it is a python script. Could anyone please let me know how to fix this error?

Crazyflie ros library:



auto-starting new master
process[master]: started with pid [3827]

setting /run_id to 984e8218-4ea5-11e8-ab32-334fbf79bdff

process[rosout-1]: started with pid [3840]

started core service [/rosout]

process[rviz-2]: started with pid [3857]

process[crazyflie/crazyflie_add-3]: started with pid [3858]

process[crazyflie/joy-4]: started with pid [3859]

process[crazyflie/joystick_controller-5]: started with pid [3868]

Unable to launch [crazyflie/mycontroller2016b_node-6]. 

If it is a script, you may be missing a '#!' declaration at the top.

The traceback for the exception was written to the log file

[crazyflie/joystick_controller-5] killing on exit

[crazyflie/mycontroller2016b_node-6] killing on exit

[crazyflie/crazyflie_add-3] killing on exit

[crazyflie/joy-4] killing on exit

[rviz-2] killing on exit

launch file:

<?xml version="1.0"?>
  <arg name="uri" default="radio://0/100/2M/E7E7E7E7E7" />
  <arg name="frame" default="base_link" />
  <arg name="joy_dev" default="/dev/input/js0" />
  <arg name="x" default="2.8" />
  <arg name="y" default="2.3" />
  <arg name="z" default="1" />

  <param name="robot_description" command="$(find xacro)/ $(find crazyflie_description)/urdf/crazyflie2.urdf.xacro" />
  <node name="rviz" pkg="rviz" type="rviz"
        args="-d $(find bitcraze_lps_estimator)/data/rvizconfig_with_goal.rviz"/>

  <group ns="crazyflie">
    <rosparam command="load" file="$(find bitcraze_lps_estimator)/data/anchor_pos.yaml" />

    <node pkg="crazyflie_driver" type="crazyflie_add" name="crazyflie_add" output="screen">
      <param name="uri" value="$(arg uri)" />
      <param name="tf_prefix" value="crazyflie" />
        genericLogTopics: ["log_kfpos", "log_kfqt", "log_ranges"]
        genericLogTopicFrequencies: [30, 30, 30]
        genericLogTopic_log_kfpos_Variables: ["kalman.stateX", "kalman.stateY", "kalman.stateZ"]
        genericLogTopic_log_kfqt_Variables: ["kalman.q0", "kalman.q1", "kalman.q2", "kalman.q3"]
        genericLogTopic_log_ranges_Variables: ["ranging.distance0", "ranging.distance1", "ranging.distance2", "ranging.distance3", "ranging.distance4", "ranging.distance5", "ranging.state"]

    <node name="joy" pkg="joy" type="joy_node" output="screen">
      <param name="dev" value="$(arg joy_dev)" />

    <node name="joystick_controller" pkg="crazyflie_demo" type="" output="screen">
      <param name="use_crazyflie_controller" value="True" />

    <node name="mycontroller2016b_node" pkg="mycontroller2016b" type="ert_main.cpp" output="screen"/>

    <node name="pose" pkg="crazyflie_demo" type="" output="screen">
      <param name="name" value="goal" />
      <param name="rate" value="30" />
      <param name="x" value="$(arg x)" />
      <param name="y" value="$(arg y)" />
      <param name="z" value="$(arg z)" />

    <node name="lps_efk_bridge" pkg="bitcraze_lps_estimator" type="" output="screen"/>

    <node name="lps_viz" pkg="bitcraze_lps_estimator" type="" />

    <node name="log_range" pkg="bitcraze_lps_estimator" type="" />

  </group ...
edit retag flag offensive close merge delete


Can you please update your question with a copy and paste of the error directly in your question instead of linking to a screenshot? Images are not searchable and people cannot copy and paste the text from the image. Please see our support guidelines

jayess gravatar image jayess  ( 2018-05-02 11:17:51 -0600 )edit

@rajavardhanr6: did you actually compile the sources Simulink generated for you? You cannot run a .cpp file like you would a .py file.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-03 05:28:01 -0600 )edit

Yes i do compiled using catkin_make when i exported the files from Simulink.Is there any other way to compile cpp files?

rajavardhanr6 gravatar image rajavardhanr6  ( 2018-05-03 05:43:55 -0600 )edit

Then please copy the contents of your launch file into your question text. Use the edit button/link.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-03 05:52:50 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-03 08:34:03 -0600

gvdhoorn gravatar image
<node name="mycontroller2016b_node" pkg="mycontroller2016b" type="ert_main.cpp" output="screen"/>

As I hinted at in my earlier comment, you cannot start a .cpp file like this. It's not a script.

You can only start the compiled node.

Yes i do compiled using catkin_make

then you must have written a CMakeLists.txt, so what name did you give the binary? Use that name for the value for type.

edit flag offensive delete link more


yeah i got it thanks

rajavardhanr6 gravatar image rajavardhanr6  ( 2018-05-04 06:38:22 -0600 )edit

Question Tools

1 follower


Asked: 2018-05-02 08:57:40 -0600

Seen: 1,369 times

Last updated: May 03 '18