hi i try tu bould some diy optical flow with simple rspi camera
i try to run this mavros ros2 code
import rclpy
from rclpy.node import Node
from std_msgs.msg import Float32MultiArray
from mavros_msgs.msg import OpticalFlowRad
class FCOpticalInherit(Node):
def init(self):
super().init(‘fc_optical_inherit’)
# Subscribe to the topic providing optical flow data
self.subscription = self.create_subscription(
Float32MultiArray,
‘optical_flow_data’,
self.listener_callback,
10
)
# Publisher to MAVROS optical flow topic
self.publisher_ = self.create_publisher(OpticalFlowRad, ‘/mavros/optical_flow/raw/send’, 10)
#self.get_logger().info(‘FC Optical Inherit Node has been started.’)
def listener_callback(self, msg):
if len(msg.data) >= 2:
x_movement = msg.data[0]
y_movement = msg.data[1]
#self.get_logger().info(f'Received Optical Flow Data - X: {x_movement}, Y: {y_movement}')
# Prepare the OpticalFlowRad message
optical_flow = OpticalFlowRad()
optical_flow.integration_time_us = 1000000 # Example value, adjust as needed
optical_flow.integrated_x = x_movement
optical_flow.integrated_y = y_movement
optical_flow.distance = 1.0 # Example distance, adjust as needed
optical_flow.temperature = 0 # Example temperature, adjust as needed
optical_flow.time_delta_distance_us = 0
optical_flow.quality = 255 # Example quality, adjust as needed
#self.get_logger().info(f'Publishing Optical Flow Data: {optical_flow}')
self.publisher_.publish(optical_flow)
else:
self.get_logger().warn('Received optical flow data does not contain enough elements.')
def main(args=None):
rclpy.init(args=args)
controller = FCOpticalInherit()
rclpy.spin(controller)
controller.destroy_node()
rclpy.shutdown()
if name == ‘main’:
main()
i fix the camera to publish topic with the data for the optical flow.
the script i gave here is node that take the data from the camera adn gave it do the flight controler
for somehow i dont get data at the opt at the drone
thanks for help