Overriding radio controller

Simulate, build and deploy your algorithms with Erle-Copter

Source code

APM requires setup FCU param SYSID_MYGCS to match mavros system id. Set the parameter SYSID_MYGCS=1`.

NOTE: Be carreful to use in automatic control because lack of safety mechanisms

# Override RC Input
# Currently MAVLink defines override for 8 channel

uint16 CHAN_RELEASE=0
uint16 CHAN_NOCHANGE=65535

uint16[8] channels

Using MAVROS we are going to be able to override a 8 channel RC. Filling the 8 values of the array channels msg_override.channels.

In this code it shows how to override roll, pitch, throttle and yaw channels. The other 4 channels are not going to be override, this mean that this channels will get the value from the RC.

#include <cstdlib>
#include <stdlib.h>     /* atoi */

#include <ros/ros.h>
#include <mavros_msgs/OverrideRCIn.h>

int main(int argc, char **argv)
{
    if(argc<5){
        printf("Usage: rosrun ros_erle_cpp_examples_rc rc pitch roll throttle yaw\n");
        return -1;
    }

    ros::init(argc, argv, "mavros_rc_override");
    ros::NodeHandle n;

    int pitch = atoi(argv[1]);
    int roll = atoi(argv[1]);
    int throttle = atoi(argv[1]);
    int yaw = atoi(argv[1]);

    int rate = 100;
    ros::Rate r(rate);

    ros::Publisher rc_override_pub = n.advertise<mavros_msgs::OverrideRCIn>("/mavros/rc/override", 10);

    mavros_msgs::OverrideRCIn msg_override;

    while (n.ok()){

        msg_override.channels[0] = roll;
        msg_override.channels[1] = pitch;
        msg_override.channels[2] = throttle;
        msg_override.channels[3] = yaw;
        msg_override.channels[4] = 1100;
        msg_override.channels[5] = 1100;
        msg_override.channels[6] = 1100;
        msg_override.channels[7] = 1100;

        rc_override_pub.publish(msg_override);
        ros::spinOnce();
        r.sleep();
    }

    return 0;
}

Remember to publish the message in ROS

rc_override_pub.publish(msg_override);

mkdir -p ~/erle_ws/src
cd ~/erle_ws/src
git clone https://github.com/erlerobot/gazebo_cpp_examples
cd ..
catkin_make --pkg ros_erle_cpp_examples_rc

The two following commands indicate how to change the value of the RC using this ros node. Values must be between 1000 and 2000.

  • Usage:
rosrun ros_erle_cpp_examples_rc rc roll pitch throttle yaw

Modifying the values of the RC:

rosrun ros_erle_cpp_examples_rc rc 1500 1500 1700 1500