# ROS2 Project topics problem

**URL:** <https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261>\
**Category:** ROSDS Support\
**Created:** [May 9, 2023, 9:20pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261 "2023-05-09T21:20:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![eblady](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/eblady/32/6980_2.png) [@eblady](https://get-help.theconstruct.ai/u/eblady)\
**Post date:** [May 9, 2023, 9:20pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/1 "2023-05-09T21:20:26Z")

</div>

HI,

I am doing the topics project in ROS2 python course. But, the following error happens when I try to subscribe to the /scan or publish in /cmd\_vel:

user:~/ros2\_ws$ ros2 launch wall\_follower start\_wall\_following.launch.py  
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2023-05-09-21-10-12-024513-2\_xterm-24267  
[INFO] [launch]: Default logging verbosity is set to INFO  
[INFO] [wall\_following\_node-1]: process started with pid [24318]  
[wall\_following\_node-1] Traceback (most recent call last):  
[wall\_following\_node-1] File “/home/user/ros2\_ws/install/wall\_follower/lib/wall\_follower/wall\_following\_node”, line 33, in   
[wall\_following\_node-1] sys.exit(load\_entry\_point(‘wall-follower==0.0.0’, ‘console\_scripts’, ‘wall\_following\_node’)())  
[wall\_following\_node-1] File “/home/user/ros2\_ws/install/wall\_follower/lib/python3.8/site-packages/wall\_follower/wall\_following.py”, line 92, in main  
[wall\_following\_node-1] wall\_following\_node = WallFollowing()  
[wall\_following\_node-1] File “/home/user/ros2\_ws/install/wall\_follower/lib/python3.8/site-packages/wall\_follower/wall\_following.py”, line 19, in **init**  
[wall\_following\_node-1] self.publisher\_ = self.create\_publisher(Twist, ‘cmd\_vel’, 2)  
[wall\_following\_node-1] File “/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py”, line 1140, increate\_publisher  
[wall\_following\_node-1] check\_for\_type\_support(msg\_type)  
[wall\_following\_node-1] File “/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type\_support.py”, line 20, in check\_for\_type\_support  
[wall\_following\_node-1] ts = msg\_type. **class**.\_TYPE\_SUPPORT  
[wall\_following\_node-1] AttributeError: type object ‘type’ has no attribute ‘\_TYPE\_SUPPORT’ This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS 2 workspace after your ROS 1 workspace.  
[ERROR] [wall\_following\_node-1]: process has died [pid 24318, exit code 1, cmd ‘/home/user/ros2\_ws/install/wall\_follower/lib/wall\_follower/wall\_following\_node --ros-args’].

The ROS1 is sourced first, then the ROS2. The topics can be viewed using ROS1 and ROS2 command line instructions, but when running the python scripts it does not work.

Please help,

Thanks.

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [May 10, 2023, 6:21am UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/2 "2023-05-10T06:21:23Z")

</div>

Hi @eblady ,

I am assuming that you have not added `geometry_msgs` as a dependency in your package.

If you do not mind sharing your code, please post the python program as a [code-block](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks).  
Along with it, also post your `package.xml` and your `setup.py` as code-clocks.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![eblady](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/eblady/32/6980_2.png) [@eblady](https://get-help.theconstruct.ai/u/eblady)\
**Post date:** [May 10, 2023, 1:57pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/3 "2023-05-10T13:57:07Z")

</div>

Hi,

Thanks for the reply. I included the geometry\_msgs into the package.xml, but same error. This my package.xml and setup.py files:

* * *

package.xml

\<?xml version="1.0"?\> \<?xml-model href="http://download.ros.org/schema/package\_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?\> wall\_follower 0.0.0 TODO: Package description user TODO: License declaration

rclpy  
std\_msgs  
sensor\_msgs  
geometry\_msgs

\<test\_depend\>ament\_copyright\</test\_depend\>  
\<test\_depend\>ament\_flake8\</test\_depend\>  
\<test\_depend\>ament\_pep257\</test\_depend\>  
\<test\_depend\>python3-pytest\</test\_depend\>

 ament\_python 
* * *

setup.py.

from setuptools import setup  
import os  
from glob import glob

package\_name = ‘wall\_follower’

setup(  
name=‘wall\_follower’,  
version=‘0.0.0’,  
packages=[package\_name],  
data\_files=[  
(‘share/ament\_index/resource\_index/packages’,  
[‘resource/’ + package\_name]),  
(‘share/’ + package\_name, [‘package.xml’]),  
(os.path.join(‘share’, package\_name), glob(‘launch/\*.launch.py’))  
],  
install\_requires=[‘setuptools’],  
zip\_safe=True,  
maintainer=‘user’,  
maintainer\_email=‘user@todo.todo’,  
description=‘TODO: Package description’,  
license=‘TODO: License declaration’,  
tests\_require=[‘pytest’],  
entry\_points={  
‘console\_scripts’: [  
‘wall\_following\_node = wall\_follower.wall\_following:main’  
],  
},  
)

* * *

thanks.

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [May 10, 2023, 4:14pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/4 "2023-05-10T16:14:02Z")

</div>

Hi @eblady ,

> [@girishkumar.kannan](#):
>
> If you do not mind sharing your code, please post the python program as a [code-block](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks).

I wanted to check your program for any inconsistencies.

Also I cannot exactly verify the `package.xml` if the contents are not enclosed in “preformatted-text” format.

Please edit your previous post so that your `package.xml` and `setup.py` is properly formatted as a code-block.

Also, don’t forget to post your main code, I believe the error is in your main program.

Please refer here on how to format a text into a code-block.

> **[Extended Syntax | Markdown Guide](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks)**
>
> Advanced features that build on the basic Markdown syntax.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![eblady](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/eblady/32/6980_2.png) [@eblady](https://get-help.theconstruct.ai/u/eblady)\
**Post date:** [May 10, 2023, 4:29pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/5 "2023-05-10T16:29:30Z")

</div>

Hi,

This is the package.xml

```auto
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>wall_follower</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="user@todo.todo">user</maintainer>
  <license>TODO: License declaration</license>

  <depend>rclpy</depend>
  <depend>std_msgs</depend>
  <depend>sensor_msgs</depend>
  <depend>geometry_msgs</depend>

  <test_depend>ament_copyright</test_depend>
  <test_depend>ament_flake8</test_depend>
  <test_depend>ament_pep257</test_depend>
  <test_depend>python3-pytest</test_depend>

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

```

This is the setup.py

```auto
from setuptools import setup
import os
from glob import glob

package_name = 'wall_follower'

setup(
    name='wall_follower',
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name), glob('launch/*.launch.py'))
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='user',
    maintainer_email='user@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'wall_following_node = wall_follower.wall_following:main'
        ],
    },
)

```

An this is the wall\_following.py

```auto
import rclpy
import numpy as np
import math
# import the ROS2 python libraries
from rclpy.node import Node
# import the LaserScan module from sensor_msgs interface
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
# import Quality of Service library, to set the correct profile and reliability to read sensor data.
from rclpy.qos import ReliabilityPolicy, QoSProfile

########################################
class WallFollowing(Node):

    def __init__ (self):
        super(). __init__ ('wall_following_node')
        # publiser
        self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 2)
        # twist
        self.myCMDTwist = Twist()
        self.myCMDTwist.linear.x = 0.0
        self.myCMDTwist.angular.z = 0.0

        self.myFlagFollow = 0

        self.subscriber = self.create_subscription(
            LaserScan,
            'scan',
            self.listener_scan_callback,
            QoSProfile(depth=2, reliability=ReliabilityPolicy.RELIABLE))

    def listener_scan_callback(self, msg):

        minRightDist = min(msg.ranges[90:110])
        minRightFrontDist = min(msg.ranges[125:145])
        minFrontDist = min(msg.ranges[170:190])
        minLeftFrontDist = min(msg.ranges[215:235])
        minLeftDist = min(msg.ranges[250:270])
        minBackDist = min(min(msg.ranges[350:359]), min(msg.ranges[0:9]))

        print("r: %.3f rf: %.3f f: %.4f lf: %.3f l: %.3f b: %.3f fl: %d" % (minRightDist, minRightFrontDist, minFrontDist, minLeftFrontDist, minLeftDist, minBackDist, myFlagFollow))

        # dMin = 0.2 / np.cos(45*np.pi/180)
        # dMax = 0.3 / np.cos(45*np.pi/180)
        # dFront = 0.5
        # linVel = 0.025
        # angVel = 0.15
        # angVelFront = 0.3

        # if self.myFlagFollow == 0 and minRightFrontDist > dMax:
        # self.myFlagFollow = 2 # Follow left wall
        # print('Following left wall...')
        # elif self.myFlagFollow == 0 and minLeftFrontDist > dMax: 
        # self.myFlagFollow = 1 # Follow right wall
        # print('Following right wall...')

        # if self.myFlagFollow == 1:
        # if minFrontDist > dFront and minRightFrontDist > dMin and minRightFrontDist < dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = 0.0
        # elif minFrontDist < dFront and minRightFrontDist > dMin and minRightFrontDist < dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = angVelFront
        # elif minFrontDist > dFront and minRightFrontDist > dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = -angVel
        # elif minFrontDist > dFront and minRightFrontDist < dMin:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = angVel
        # elif self.myFlagFollow == 2:
        # if minFrontDist > dFront and minLeftFrontDist > dMin and minLeftFrontDist < dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = 0.0
        # elif minFrontDist < dFront and minLeftFrontDist > dMin and minLeftFrontDist < dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = -angVelFront
        # elif minFrontDist > dFront and minLeftFrontDist > dMax:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = angVel
        # elif minFrontDist > dFront and minLeftFrontDist < dMin:
        # self.myCMDTwist.linear.x = linVel
        # self.myCMDTwist.angular.z = -angVel

        self.publisher_.publish(self.myCMDTwist)

########################################
def main(args=None):
    # initialize the ROS communication
    rclpy.init(args=args)
    # declare the node constructor topics_quiz_node
    wall_following_node = WallFollowing()
    # pause the program execution, waits for a request to kill the node (ctrl+c)
    rclpy.spin(wall_following_node)
    # Explicity destroy the node
    wall_following_node.destroy_node()
    # shutdown the ROS communication
    rclpy.shutdown()

########################################

if __name__ == ' __main__':
    main()

```

Thanks.

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [May 10, 2023, 4:43pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/6 "2023-05-10T16:43:43Z")

</div>

Hi @eblady ,

Your program and files seems to be correct. Although I believe there are two culprits here.

1. Add the ‘/’ in front of the topic name:

```python
self.publisher_ = self.create_publisher(Twist, '/cmd_vel', 2) # added / before cmd_vel

```

1. Delete the `build`, `install` and `log` folders. Execute the following commands:

```bash
cd ~/ros2_ws
rm -f ./build ./install ./log
cd ~
source /opt/ros/noetic/setup.bash
source /opt/ros/foxy/setup.bash
cd ~/ros2_ws
colcon build --packages-select wall_follower && source install/setup.bash
ros2 launch wall_follower <your_launch_file_name>.launch.py

```

Try this and let me know if this fixed your problem.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![eblady](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/eblady/32/6980_2.png) [@eblady](https://get-help.theconstruct.ai/u/eblady)\
**Post date:** [May 10, 2023, 4:56pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/7 "2023-05-10T16:56:07Z")

</div>

> [@girishkumar.kannan](#):
>
> `source install/setup.bash`

Hi,

Nop, not working:

```auto
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2023-05-10-16-51-28-344162-4_xterm-14759
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [wall_following_node-1]: process started with pid [14824]
[wall_following_node-1] Traceback (most recent call last):
[wall_following_node-1] File "/home/user/ros2_ws/install/wall_follower/lib/wall_follower/wall_following_node", line 33, in <module>
[wall_following_node-1] sys.exit(load_entry_point('wall-follower==0.0.0', 'console_scripts', 'wall_following_node')())
[wall_following_node-1] File "/home/user/ros2_ws/install/wall_follower/lib/python3.8/site-packages/wall_follower/wall_following.py", line 91, in main
[wall_following_node-1] wall_following_node = WallFollowing()
[wall_following_node-1] File "/home/user/ros2_ws/install/wall_follower/lib/python3.8/site-packages/wall_follower/wall_following.py", line 18, in __init__
[wall_following_node-1] self.publisher_ = self.create_publisher(Twist, '/cmd_vel', 2)
[wall_following_node-1] File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1140, in create_publisher
[wall_following_node-1] check_for_type_support(msg_type)
[wall_following_node-1] File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 20, in check_for_type_support
[wall_following_node-1] ts = msg_type. __class__._TYPE_SUPPORT
[wall_following_node-1] AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT'This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS 2 workspace after your ROS 1 workspace.
[ERROR] [wall_following_node-1]: process has died [pid 14824, exit code 1, cmd '/home/user/ros2_ws/install/wall_follower/lib/wall_follower/wall_following_node --ros-args'].

```

In addition, using the command line I try to check publishing in the cmd\_vel:

```auto
user:~/ros2_ws$ ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.1}}"
Traceback (most recent call last):
  File "/opt/ros/foxy/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.9.9', 'console_scripts', 'ros2')()
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/command/topic.py", line 41, in main
    return extension.main(args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 97, in main
    return main(args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 107, in main
    return publisher(
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 131, in publisher
    msg_module = get_message(message_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_runtime_py/utilities.py", line 30, in get_message
    raise ValueError("Expected the full name of a message, got '{}'".format(identifier))
ValueError: Expected the full name of a message, got 'geometry_msgs/msg/Twist'

```

Same happens with the scan topic…

Any ideas?

thanks

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [May 10, 2023, 6:30pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/8 "2023-05-10T18:30:14Z")

</div>

Hi @eblady ,

This post could be the solution: [ROS2 Topics "ros2 topic echo /cmd\_vel" fails - #7 by albertoezquerro](https://get-help.robotigniteacademy.com/t/ros2-topics-ros2-topic-echo-cmd-vel-fails/15030/7)

What you have to do is:

1. Reset all the terminals on the course, that is, by clicking the red X button on every webshell.
2. Then on every webshell that you will be using, you must type in these two commands before executing any other commands:

```bash
source /opt/ros/foxy/setup.bash
source /home/simulations/ros2_sims_ws/install/setup.bash

```

I believe this should definitely fix your problem. Let me know if you still have issues.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![eblady](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/eblady/32/6980_2.png) [@eblady](https://get-help.theconstruct.ai/u/eblady)\
**Post date:** [May 12, 2023, 12:50pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/9 "2023-05-12T12:50:55Z")

</div>

Hi Girish,

Thanks for your advice, it worked !!! I really appreciate your time in solving this.

my best regards,

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [May 17, 2023, 12:51pm UTC](https://get-help.theconstruct.ai/t/ros2-project-topics-problem/24261/10 "2023-05-17T12:51:17Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
