ROS2 No executable found (ros2 run pack nodo)

asked 2023-06-25 19:45:02 -0500

Antonio Avezon gravatar image
Hello. I am new programming in ROS2 and I need help. I have carried out the following steps, without errors (but in the end it does not execute):

Create the workspace folder: **mkdir workspace**
Enter the workspace folder: **cd workspace**
Create a package: **ros2 pkg create --build-type ament_cmake lidar_publisher**
Enter the lidar_publisher package folder: **cd lidar_publisher**
Create the "src" folder: **mkdir src**
Enter the "src" folder: **cd src**
Install dependencies: **rosdep install -i --from-path src --rosdistro foxy -y**
Inside the "src" folder, create the following files: lidar_publisher.py, CMakeLists.txt, package.xml, setup.cfg, setup.py
Build the project from the *workspace* folder: **colcon build**
Set up the environment variables: **source install/setup.bash**
Try to execute the created script: **ros2 run lidar_publisher lidar_publisher** or **ros2 run lidar_publisher lidar_publisher.py**

This is the code for cMakelist.txt:

`cmake_minimum_required(VERSION 3.5) project(lidar_publisher)

Find required packages

find_package(ament_cmake REQUIRED) find_package(rclpy REQUIRED) find_package(sensor_msgs REQUIRED)

Add the Python publisher script to the package

ament_python_install_package(lidar_publisher)

Install the Python publisher script

install(PROGRAMS lidar_publisher.py DESTINATION lib/lidar_publisher )

Add package dependencies

ament_depends(rclpy sensor_msgs)

Generate the package build file

ament_package() ` package.xml

<package format="3"> <name>lidar_publisher</name> <version>0.1.0</version> <description>Package for lidar_publisher</description> <maintainer <a="" href="mailto:email="user@mail.com"&gt;User&lt;/maintainer">email="user@mail.com">User> <license>TODO: License declaration</license> <buildtool_depend>ament_cmake</buildtool_depend> <build_depend>rclpy</build_depend> <build_depend>sensor_msgs</build_depend> <exec_depend>ament_cmake</exec_depend> <exec_depend>rclpy</exec_depend> <exec_depend>sensor_msgs</exec_depend> <export> <build_type>ament_python</build_type> </export> </maintainer></package>

setup.cfg

[develop] script-dir=$base/lib/lidar_publisher [install] install-scripts=$base/lib/lidar_publisher

setup.py

from setuptools import setup package_name = 'lidar_publisher' setup( name=package_name, version='0.1.0', packages=[], py_modules=[ 'lidar_publisher', ], install_requires=[ 'setuptools', 'ros2pkg', 'ament_index_python', 'rclpy', 'sensor_msgs', ], data_files=[ ('share/ament_index/resource_index/packages', ['resource/' + package_name]), ('share/' + package_name, ['package.xml']), ], zip_safe=True, author='User', author_email='User', maintainer='User', maintainer_email='User@mail.com', keywords=['ROS'], classifiers=[ 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache License 2.0', 'Programming Language :: Python', 'Topic :: Software Development', ], description='Package for lidar publisher', license='Apache License 2.0', tests_require=['pytest'], entry_points={ 'console_scripts': [ 'lidar_publisher = lidar_publisher:main', ], }, )

lidar_publisher.py

import rclpy from rclpy.node import Node from sensor_msgs.msg import LaserScan class LidarPublisher(Node): def __init__(self): super().__init__('lidar_publisher') self.publisher_ = self.create_publisher(LaserScan, 'lidar_scan', 10) def publish_lidar_data(self): scan_msg = LaserScan() # Configurar los datos del escaneo aquí self.publisher_.publish(scan_msg) def main(args=None): rclpy.init(args=args) lidar_publisher = LidarPublisher() rclpy.spin(lidar_publisher) lidar_publisher.destroy_node() rclpy.shutdown() if __name__ == '__main__': main()

All this to receive at the end a message "No executable found" Something is missing, and this may also help other people who may have the same error, that's why I wrote it in full. Thank you very much to anyone who can help me. I have used a translator. Greetings from Chile.

edit retag flag offensive close merge delete

Comments

Unfortunately the code got piled up! I didn't write it like that

Antonio Avezon gravatar image Antonio Avezon  ( 2023-06-25 19:47:21 -0500 )edit