ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

build failed: genmsg.base.InvalidMsgSpec: Invalid declaration: ...

asked 2021-06-17 03:13:16 -0500

akash12124234 gravatar image

updated 2021-06-17 03:33:10 -0500

gvdhoorn gravatar image
```
   File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/msg_loader.py", line 266, in load_msg_from_string
    field_type, name = _load_field_line(orig_line, package_name)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/msg_loader.py", line 225, in _load_field_line
    raise InvalidMsgSpec("Invalid declaration: %s"%(orig_line))
genmsg.base.InvalidMsgSpec: Invalid declaration: ...
CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
  execute_process(/home/akash/catkin_ws/build/catkin_generated/env_cached.sh
  "/usr/bin/python2" "/usr/bin/empy" "--raw-errors" "-F"
  "/home/akash/catkin_ws/build/service_node/cmake/service_node-genmsg-context.py"
  "-o"
  "/home/akash/catkin_ws/build/service_node/cmake/service_node-genmsg.cmake"
  "/opt/ros/melodic/share/genmsg/cmake/pkg-genmsg.cmake.em") returned error
  code 1
Call Stack (most recent call first):
  /opt/ros/melodic/share/catkin/cmake/em_expand.cmake:25 (safe_execute_process)
  /opt/ros/melodic/share/genmsg/cmake/genmsg-extras.cmake:303 (em_expand)
  service_node/CMakeLists.txt:71 (generate_messages)


-- Configuring incomplete, errors occurred!
See also "/home/akash/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/akash/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:404: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
```

So i am new to ros and i am following a tutorial i created a package named service_node and then i created a srv inside it named AddTwoInts.srv

int64 a
int64 b
...
int64 sum

Then it asked me to created a scripts named client.py

#!/usr/bin/env python
from __future__ import print_function
import sys
import rospy
from service_node.srv import *



def add_two_ints_client(x, y):
    rospy.wait_for_service('add_two_ints')
    try:
        add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
        resp1 = add_two_ints(x, y)
        return resp1.sum
    except rospy.ServiceException as e:
        print("Service call failed: %s"%e)

def usage():
return "%s [x y]"%sys.argv[0]


if __name__ == "__main__":
    if len(sys.argv) == 3:
        x = int(sys.argv[1])
        y = int(sys.argv[2])
    else:
        print(usage())
        sys.exit(1)
    print("Requesting %s+%s"%(x, y))
    print("%s + %s = %s"%(x, y, add_two_ints_client(x, y)))

and a server.py

#!/usr/bin/env python

from __future__ import print_function

from service_node.srv import AddTwoInts,AddTWoIntsResponse
import rospy
def handle_add_two_inst(req):
    print("Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b)))
    return AddTwoIntsResponse(req.a + req.b)
def add_two_ints_server():
    rospy.init_node('add_two_ints_server')
    s= rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
    print("Ready to add two ints.")
    rospy.spin()

if __name__ == "__main__":
    add_two_ints_server()

then i did some changes on cmakelist

such as unindented add_service_files

 add_service_files(
   FILES
   AddTwoInts.srv
#   Service2.srv
 )

and

 generate_messages(
   DEPENDENCIES
   std_msgs
 )

and its my package

find_package(catkin REQUIRED COMPONENTS
  message_generation
  rospy
  std_msgs
)

and inside catkin install

 catkin_install_python(PROGRAMS
   scripts/server.py scripts/client.py
   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

also so i edited the pacakge.xml and unindented the message_runtime

and when i try to run

catkin_make

on catkin_ws workspace it shows this error

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-17 03:19:46 -0500

gvdhoorn gravatar image

updated 2021-06-17 03:20:43 -0500

The problem is your .srv:

int64 a
int64 b
...
int64 sum

The separator is not three dots (.), but three dashes (-).

This is also stated in the error message:

genmsg.base.InvalidMsgSpec: Invalid declaration: ...

The tutorial you mention (Creating a ROS msg and srv - Creating a srv?) copies AddTwoInts.srv from rospy_tutorials, which doesn't contain dots (from here):

int64 a
int64 b
---
int64 sum

Note the three dashes.

edit flag offensive delete link more

Comments

i never imagined 3 dots will ruin my 2 days..... thanks a lot

akash12124234 gravatar image akash12124234  ( 2021-06-17 03:30:27 -0500 )edit

i never imagined 3 dots will ruin my 2 days....

well, this is programming, and compilers / parsers are very strict. Dots don't "mean" the same thing as dashes.

Where did you find the version with the three dots?

gvdhoorn gravatar image gvdhoorn  ( 2021-06-17 03:31:29 -0500 )edit

Traceback (most recent call last): File "/home/akash/catkin_ws/src/service_node/scripts/server.py", line 5, in <module> from service_node.srv import AddTwoInts,AddTWoIntsResponse ImportError: cannot import name AddTWoIntsResponse

now i am getting this error when i tried to run

rosrun service_node server.py

akash12124234 gravatar image akash12124234  ( 2021-06-17 03:57:22 -0500 )edit

That would be an entirely different problem. Please post that as a new question, after you've made sure there are no Q&As already discussing this.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-17 03:59:10 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-06-17 03:13:16 -0500

Seen: 675 times

Last updated: Jun 17 '21