Reputation: 57
I'm trying to make a publisher for a Ublox GPS sensor, but I'm getting this ROS error:
ubuntu@fieldrover:~/field-rover-gps/gps/gps_pkg$ cd ~/field-rover-gps/gps/gps_pkg/ && colcon build && . install/setup.bash && ros2 run gps_pkg gps
Starting >>> gps_pkg Finished <<< gps_pkg [2.98s]
Summary: 1 package finished [3.49s] Traceback (most recent call last): File "/opt/ros/galactic/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support return importlib.import_module(module_name, package=pkg_name) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 657, in _load_unlocked
File "", line 556, in module_from_spec
File "", line 1166, in create_module File "", line 219, in _call_with_frames_removed ImportError: /opt/ros/galactic/lib/libgeometry_msgs__rosidl_generator_c.so: undefined symbol: std_msgs__msg__Header__copyDuring handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/ubuntu/field-rover-gps/gps/gps_pkg/install/gps_pkg/lib/gps_pkg/gps", line 33, in sys.exit(load_entry_point('gps-pkg==0.0.0', 'console_scripts', 'gps')()) File "/home/ubuntu/field-rover-gps/gps/gps_pkg/install/gps_pkg/lib/python3.8/site-packages/gps_pkg/gps.py", line 49, in main gps_node = GpsNode() File "/home/ubuntu/field-rover-gps/gps/gps_pkg/install/gps_pkg/lib/python3.8/site-packages/gps_pkg/gps.py", line 17, in init self.publisher_ = self.create_publisher(NavSatFix, 'gps/fix', 10) File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/node.py", line 1282, in create_publisher check_is_valid_msg_type(msg_type) File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/type_support.py", line 35, in check_is_valid_msg_type check_for_type_support(msg_type) File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support msg_or_srv_type.class.import_type_support() File "/opt/ros/galactic/lib/python3.8/site-packages/sensor_msgs/msg/_nav_sat_fix.py", line 34, in import_type_support module = import_type_support('sensor_msgs') File "/opt/ros/galactic/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support raise UnsupportedTypeSupport(pkg_name) rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'sensor_msgs'
It seems to have an issue with NavSatFix. I've tested other sensor_msgs types like Image in the same package, and that works fine. Here's the code I tried running.
import rclpy
import os
from rclpy.node import Node
from sensor_msgs.msg import NavSatFix
from sensor_msgs.msg import NavSatStatus
from std_msgs.msg import Header
import serial
from ublox_gps import UbloxGps
port = serial.Serial('/dev/ttyACM0', baudrate=38400, timeout=1)
gps = UbloxGps(port)
class GpsNode(Node):
def __init__(self):
super().__init__('gps_node')
self.publisher_ = self.create_publisher(NavSatFix, 'gps/fix', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
def timer_callback(self):
msg = NavSatFix()
msg.header = Header()
msg.header.stamp = self.get_clock().now().to_msg()
msg.header.frame_id = "gps"
msg.status.status = NavSatStatus.STATUS_FIX
msg.status.service = NavSatStatus.SERVICE_GPS
geo = gps.geo_coords()
# Position in degrees.
msg.latitude = geo.lat
msg.longitude = geo.lon
# Altitude in metres.
#msg.altitude = 1.15
msg.position_covariance[0] = 0
msg.position_covariance[4] = 0
msg.position_covariance[8] = 0
msg.position_covariance_type = NavSatFix.COVARIANCE_TYPE_DIAGONAL_KNOWN
self.publisher_.publish(msg)
self.best_pos_a = None
def main(args=None):
rclpy.init(args=args)
gps_node = GpsNode()
rclpy.spin(gps_node)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
gps_node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Upvotes: 0
Views: 3477
Reputation: 11
I had the same error and following @awied1404's suggestion, I noticed that my dependency sensor_msgs
was missing in the rosidl_generate_interfaces
of CMakeLists.txt. I was trying to build a custom vision message for ROS2. I had to do the following changes and it worked.
find_package(sensor_msgs REQUIRED)
enter code here${msg_files}
DEPENDENCIES std_msgs geometry_msgs sensor_msgs
ADD_LINTER_TESTS)
Upvotes: 0
Reputation: 61
I had the same error and I forgot to add the dependency of the message type I was using in a service in the CMakeLists.txt The dependency was missing in the rosidl_generate_interfaces
Upvotes: 0