Errors while doing Exercises 2.1 and 2.2

Hello,

I’m in the course of beginner: ROS basics 5days.

Right now I’m learning how to create a publisher and subscriber.

When I’m trying to do exercise2.1 and exercise 2.2, I got the same errors:

(1) If I use the code: rosrun exercise21 move_robot.launch , the error is:

      home/user/catkin_ws/src/exercise21/launch/move_robot.launch: line 1: syntax error near unexpected token `newline'
/home/user/catkin_ws/src/exercise21/launch/move_robot.launch: line 1: `<launch>'

(2) If I use the code: roslaunch exercise21 move_robot.launch , the error is:

       ERROR: cannot launch node of type [exercise_21/move_robot.py]: exercise_21

I create a ROS pkg as: catkin_create_pkg my_pkg rospy

I also make the pkg as: catkin_make.

Would you help me figure out the problem?

Hi @mingyucai0915 :slight_smile: , welcome to the community!

  1. rosrun executes a file directly, so you have to execute
    rosrun exercise21 move_robot.py
    instad of
    rosrun exercise21 move_robot.launch

  2. Always make sure that your file is executable (chmod +x)

  3. After catkin_make you always have to source your setup file, so that roslaunch knows where the newly compiled packages are. source ~/catkin_ws/devel/setup.bash

  4. If you create a new package and have your code there, you have to launch the file from that package. roslaunch my_pkg <launchfile.launch>

1 Like