Hi, I am a beginner at ROS and was trying to do the exercise 2.1 of “ROS Learning Week - Day 4” rosject.
When I do the roslaunch command, the following error comes up:
ERROR: cannot launch node of type [exercise_2_1/simple_topic_publisher_exercise2_1.py]: can’t locate node [simple_topic_publisher_exercise2_1.py] in package [exercise_2_1]
When I try to give execute permission by doing chmod +x simple_topic_publisher_exercise2_1.py, the following error comes up:
chmod: cannot access ‘simple_topic_publisher_exercise2_1.py’: No such file or directory
The only thing I did differently from the notebook was, instead of editing in the simple_topic_publisher.py file from an older example in the same rosject, I made a separate package(exercise_2_1) with separate launch file(simple_topic_publisher_exercise2_1.launch) and python file(simple_topic_publisher_exercise2_1.py).
All the locations and names are correct as per my limited knowledge. I even tried running roscore in a separate shell and then tried doing roslaunch and chmod again, but same errors came up. Please help me figure out where I am going wrong.
I have attached a picture containing the locations of files & the launch file code.
This is the python code:
#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
rospy.init_node(‘twisting’)
pub2 = rospy.Publisher(’/cmd_vel’, Twist, queue_size=1)
rate = rospy.Rate(2)
var = Twist()
Twist.linear.x = 0.3
Twist.angular.z = 0.3
while not rospy.is_shutdown():
pub2.publish(var)
rate.sleep()
Hi @Joseph1001 , thanks for the reply. I tried your solutions, but the same errors are popping up still.
Can you try the following to check if the package exist:
rospack list | grep <replace with name of the package you created>
Do share the result
Hi @tsturbo , i tired to replicate your file but did not get any error as you said.
I did get a lot of errors in your python code you shared, i have commented the same in the code:
#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
rospy.init_node("twisting")
pub2 = rospy.Publisher("/cmd_vel", Twist, queue_size=1)
rate = rospy.Rate(2)
var = Twist()
# the object created is var , and not Twist
# Twist.linear.x = 0.3
var.linear.x = 0.3
# Twist.angular.z = 0.3
var.angular.z = 0.3
while not rospy.is_shutdown():
pub2.publish(var)
Launch file:
<launch>
<node pkg="exercise_2_1" type="simple_topic_publisher_exercise2_1.py" name="twisting" output="screen"/>
</launch>
Why don’t you delete the package and try once again.
Hi
I had already tried deleting the package and it didn’t work. I had tried what I had mentioned in my post and it didn’t work. I had tried what you had suggested, Joseph, and it didn’t work.
Following all this, I left it at that time. I picked it up again today, and deleted the old package and started again. It worked this time.
Also, the code fault you had pointed out was correct; thanks a lot. It was a silly mistake on my part which I made probably during a brain-fade moment. I made the correction, and the simulation is running smoothly. It could be that the code fault was the issue itself.
Whatever be the case, I am grateful for your efforts.
Hope we stay connected.
2 Likes
@tsturbo , I am glad it worked out. Do continue to share any queries with the community.
Happy to help.
Best,
Joseph
1 Like
This topic was automatically closed after 2 days. New replies are no longer allowed.