Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc over ride #1955

Open
naorwaiss opened this issue May 27, 2024 · 0 comments
Open

rc over ride #1955

naorwaiss opened this issue May 27, 2024 · 0 comments

Comments

@naorwaiss
Copy link

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 


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant