How do you get the linter working for ros2 libraries in visual studio code for a source ros2 installation?
I'm trying to figure out how to get auto-complete working in vs-code for my source installation of ros2 but position of directories and overall folder structure seems to be different on the source installation from the apt-get install.
E.G:
rlcpy is in /opt/ros/foxy/lib/python3.8/site-packages on the apt-get install method but rlcpy seems to be in (directory you installed it in /ros2_foxy/src/ros2 on the source installation.
launching packages through "ros2 launch <package-name> <package-name-launchfile> works, but when I want to work on a program for my pi nodes in the IDE, the linter fails to import the ros2 libraries because it can't find them, I'm using the settings.json file of:
{
"python.autoComplete.extraPaths": [
"/opt/ros/foxy/lib/python3.8/site-packages",
"~/ros2_foxy/src"
],
}
but this does not work.
I've done both source ~/ros2_foxy/install/setup.sh and (directory of ros2 package) source install/setup.sh, but neither of these fixes imports not showing in the linter.
This is the code im trying to run:
#!/usr/bin/env python
import time
import serial
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('minimal_subscriber')
self.subscription = self.create_subscription(
String,
'topic',
self.listener_callback,
10)
self.subscription # prevent unused variable warning
def listener_callback(self, msg):
self.get_logger().info('I heard: "%s"' % msg.data)
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_subscriber.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Error im getting:
Unable to import 'rclpy.node'
how do i get the vscode workstation working so the linter works?