build failed: genmsg.base.InvalidMsgSpec: Invalid declaration: ...
```
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