0

I am new to ROS. I tried to make a custom message that has the attributes of an IoT sensor. I followed every step in the tutorials (i.e, making a msg sub-directory, creating and editing the file and updating dependencies) when I run the following command, $ rosmsg show iot_sensor [ros_essentials_cpp/iot_sensor]: int32 id string name float32 temp float32 hum which means that the message has been registered. however, I can't seem to import the custom message in pyhcarm. enter image description here

any help is appreciated! :D

ADI TIWARI
  • 65
  • 1
  • 6
  • Have you checked for example: https://answers.ros.org/question/204326/pycharm-setup/ You probably have only base ROS sourced and not your workspace therefore pycharm can not find it. – maetulj May 11 '20 at 21:05
  • Also check https://stackoverflow.com/questions/61701611/how-to-source-additional-environment-in-pycharm – maetulj May 11 '20 at 21:07

1 Answers1

0

Your python editor will only be able to find the ROS modules for the messages that you created if they are added to your PYTHONPATH environment variable. Sourcing your ROS workspace will correctly set up the environment variables for you, including the PYTHONPATH.

The easiest way to solve your problem would be to open a terminal, source the workspace with your iot_sensor message and then start pycharm from that terminal. I'm not a pycharm user myself, but here seem to be some suggestions on starting pycharm from the terminal, if you don't know yet how to do that.

asparc
  • 136
  • 2
  • thanks for the response,I am new to linux and ros. is the sourcing supposed to ben done via the ~/.bashrc file? here is my PYTHONPATH ```echo $PYTHONPATH /home/aditya/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages ``` – ADI TIWARI May 12 '20 at 19:29
  • I would certainly source the base of your ROS distro (`source /opt/ros/melodic/setup.bash`) in your bashrc file, such that all your ROS commands will become available in every terminal. Sourcing your specific catkin workspace (`source ~/catkin_ws/devel/setup.bash`) in the bashrc is not common practice. If you are only gonna use one catkin workspace, you could consider it. Alternatively, you could make an alias for sourcing your workspace, to reduce the typing. For pycharm, it doesn't matter which approach you choose, as long as pycharm is started from a terminal with the correct PYTHONPATH. – asparc May 13 '20 at 09:40
  • thanks!! starting pycharm from the terminal solved it. I had already sourced the ROS distro and workspace in the .bashrc file. if it's too much trouble can you tell me why it did solve it? thanks again :) – ADI TIWARI May 13 '20 at 14:09
  • That's because the bashrc is only read when you start a bash shell (your terminal). When you start a desktop application, the bashrc is not read. Instead, the .desktop file of the application is executed (see [here](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en)). – asparc May 14 '20 at 20:57