Create a new message

Steps

  1. Create Message

    roscd thorlabs_linear_actuator/
    mkdir msg
    cd msg
    nano write.msg
    
  2. Paste in the following, save, then close:

    uint8 register
    uint8 value
    
  3. open package.xml

    roscd thorlabs_linear_actuator/
    nano package.xml
    
  4. paste in the following, save, then close:

    <build_depend>message_generation</build_depend>
    <exec_depend>message_runtime</exec_depend>
    
  5. Open CMakeLists.txt in your favorite text editor (rosed from the previous tutorial is a good option).

    1. Add the message_generation dependency to the find_package call which already exists in your CMakeLists.txt so that you can generate messages. You can do this by simply adding message_generation to the list of COMPONENTS such that it looks like this:

      # Do not just add this to your CMakeLists.txt, modify the existing text to add message_generation before the closing parenthesis
      find_package(catkin REQUIRED COMPONENTS
         roscpp
         rospy
         std_msgs
         message_generation
      )
      
    2. Also make sure you export the message runtime dependency.

      catkin_package(
        ...
        CATKIN_DEPENDS message_runtime ...
        ...)
      
    3. Find the following block of code:

      # add_message_files(
      #   FILES
      #   Message1.msg
      #   Message2.msg
      # )
      
    4. Uncomment it by removing the # symbols and then replace the stand in Message*.msg files with your .msg file, such that it looks like this:

      add_message_files(
         FILES
         write.msg
      )
      

      By adding the .msg files manually, we make sure that CMake knows when it has to reconfigure the project after you add other .msg files.

    5. Now we must ensure the generate_messages() function is called.

      For ROS Hydro and later, you need to uncomment these lines:

      # generate_messages(
      #   DEPENDENCIES
      #   std_msgs
      # )
      
  1. Check message

    rosmsg show thorlabs_linear_actuator/write
    
  2. Make

    cd ~/code/code_idealab_ros/
    catkin_make
    #catkin_make install  # (optionally)
    
    # make one thing
    #catkin_make --source my_src
    #catkin_make install --source my_src  # (optionally)