mavlink / mavros

MAVLink to ROS gateway with proxy for Ground Control Station
Other
847 stars 983 forks source link

rc over ride #1955

Open naorwaiss opened 1 month ago

naorwaiss commented 1 month ago

hi i try to run gazebo with px4 drone and use controller that connect to the computer

the node i run ros2 run joy_joy_node mavros main node that connect to the sitl - ros2 run mavros mavros_node --ros-args -p fcu_url:=udp://127.0.0.1:14540@14557 and run a python code:

import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Joy
from mavros_msgs.msg import OverrideRCIn

class JoyToMavros(Node):
    def __init__(self):
        super().__init__('joy_to_mavros')
        self.subscription = self.create_subscription(
            Joy,
            'joy',
            self.joy_callback,
            10)
        self.publisher = self.create_publisher(OverrideRCIn, 'mavros/rc/override', 10)

    def joy_callback(self, msg):
        rc_override = OverrideRCIn()
        # Map joystick axes/buttons to RC channels
        rc_override.channels[0] = self.scale_value(msg.axes[0], -1.0, 1.0, 1100, 1900)  # Roll (Ch1)
        rc_override.channels[1] = self.scale_value(msg.axes[1], -1.0, 1.0, 1100, 1900)  # Pitch (Ch2)
        rc_override.channels[2] = self.scale_value(msg.axes[2], -1.0, 1.0, 1100, 1900)  # Throttle (Ch3)
        rc_override.channels[3] = self.scale_value(msg.axes[3], -1.0, 1.0, 1100, 1900)  # Yaw (Ch4)

        # Debug statements
        self.get_logger().info(f'Joy axes: {msg.axes}')
        self.get_logger().info(f'RC Override: {rc_override.channels}')

        self.publisher.publish(rc_override)

    def scale_value(self, value, min_input, max_input, min_output, max_output):
        return int((value - min_input) / (max_input - min_input) * (max_output - min_output) + min_output)

def main(args=None):
    rclpy.init(args=args)
    node = JoyToMavros()
    rclpy.spin(node)
    node.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()

the code is somthing the chat gpt wirte and it allow me to see the topic /mavros/rc/in /mavros/rc/override

the problem is that the drone not move at all and the /mavros/rc/out not change

can someone help with this

use- ros2 iron