Commit ef6780b7 authored by Inès EL HADRI's avatar Inès EL HADRI 💤

Add basic node form cam_vision

parent 562e5d33
#!/usr/bin/python3
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image
import numpy as np
import sys, cv2
from cv_bridge import CvBridge
class CameraVision(Node):
def __init__(self, name="cam_vision", timerFreq = 1/60.0):
super().__init__(name) # Create the node
# Initialize subscribers
self.create_subscription(Image, 'cam_rgb', self.rgb_callback, 10)
self.create_subscription(Image, 'cam_depth', self.depth_callback, 10)
self.create_subscription(Image, 'cam_infra_1', self.infra1_callback, 10)
self.create_subscription(Image, 'cam_infra_2', self.infra2_callback, 10)
# Initialize publishers
# self._rgb_publisher = self.create_publisher(Image, 'cam_rgb', 10)
# Initialize a clock for the publisher
self.create_timer(timerFreq, self.loop)
# Initialize a ROS2 Image to CV2 image converter
self._bridge = CvBridge()
# Callbacks
def rgb_callback(self, img):
self._rgb_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
def depth_callback(self, img):
self._depth_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
def infra1_callback(self, img):
self._infra1_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
def infra2_callback(self, img):
self._infra2_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
# Publish functions
# def publish_rgb(self):
# """
# Publish RGB image
# """
# self._rgb_publisher.publish(self._rgb_image)
# return 0
# Node internal loop
def loop(self):
pass
def main():
"""
Main loop
"""
rclpy.init()
rosNode = CameraDriver(timerFreq=1.0/120)
rclpy.spin(rosNode)
rosNode.destroy_node()
rclpy.shutdown()
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment