|
|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
|
|
|
|
|
import rclpy
|
|
|
|
|
from rclpy.node import Node
|
|
|
|
|
from rclpy.executors import SingleThreadedExecutor
|
|
|
|
|
from rclpy.executors import SingleThreadedExecutor, MultiThreadedExecutor
|
|
|
|
|
from geometry_msgs.msg import Point, Vector3
|
|
|
|
|
from sensor_msgs.msg import Image, CameraInfo
|
|
|
|
|
from cv_bridge import CvBridge
|
|
|
|
|
@ -63,9 +63,11 @@ class FireExtinguisherEmulatorNode(Node):
|
|
|
|
|
self.tf_listener = TransformListener(self.tf_buffer, self)
|
|
|
|
|
|
|
|
|
|
# Timers and subscriptions
|
|
|
|
|
self.target_timer = self.create_timer(0.01, self.target_timer_cb) # 100 Hz
|
|
|
|
|
self.target_timer = self.create_timer(0.1, self.target_timer_cb) # 10 Hz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.create_subscription(Point, 'target_point', self.target_cb, 10)
|
|
|
|
|
self.create_subscription(CameraInfo, 'camera_info', self.cam_info_cb, 10)
|
|
|
|
|
self.sub_camera_info = self.create_subscription(CameraInfo, 'camera_info', self.cam_info_cb, 10)
|
|
|
|
|
self.create_subscription(Image, 'raw_image', self.raw_image_cb, 10)
|
|
|
|
|
|
|
|
|
|
self.create_service(Trigger, 'fe_burst', self.fe_burst_cb)
|
|
|
|
|
@ -134,6 +136,7 @@ class FireExtinguisherEmulatorNode(Node):
|
|
|
|
|
def target_timer_cb(self):
|
|
|
|
|
"""Smooth movement of crosshair towards target with speed limit"""
|
|
|
|
|
if self.camera_info is None:
|
|
|
|
|
self.get_logger().warning(f"Camera info stil not recieved!")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Calculate target pixels
|
|
|
|
|
@ -161,6 +164,8 @@ class FireExtinguisherEmulatorNode(Node):
|
|
|
|
|
self.current_x += step_x
|
|
|
|
|
self.current_y += step_y
|
|
|
|
|
|
|
|
|
|
#self.get_logger().info(f"Target {self.target_x} {self.target_y} current {self.current_x} {self.current_y}")
|
|
|
|
|
|
|
|
|
|
# Calculate 3D unit vector from camera frame
|
|
|
|
|
if self.fx > 0 and self.fy > 0:
|
|
|
|
|
px = self.current_x
|
|
|
|
|
@ -306,9 +311,12 @@ def main(args=None):
|
|
|
|
|
rclpy.init(args=args)
|
|
|
|
|
node = FireExtinguisherEmulatorNode()
|
|
|
|
|
executor = SingleThreadedExecutor()
|
|
|
|
|
#executor = MultiThreadedExecutor(num_threads=4)
|
|
|
|
|
executor.add_node(node)
|
|
|
|
|
try:
|
|
|
|
|
rclpy.spin(node, executor)
|
|
|
|
|
executor.spin()
|
|
|
|
|
#rclpy.spin(node, executor)
|
|
|
|
|
#rclpy.spin(node)
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
pass
|
|
|
|
|
finally:
|
|
|
|
|
|