jetson nano-mavros-px4

Posted XXX_UUU_XXX

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jetson nano-mavros-px4相关的知识,希望对你有一定的参考价值。

ROS:melodic

Ubuntu:18.04

px4:1.11.0

QGC:3.5.6

安装mavros(推荐源码安装)

sudo apt-get install python-catkin-tools python-rosinstall-generator -y
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin init
wstool init src
rosinstall_generator --rosdistro melodic mavlink | tee /tmp/mavros.rosinstall
rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src -j4
rosdep install --from-paths src --ignore-src -y
./src/mavros/mavros/scripts/install_geographiclib_datasets.sh
catkin build
vi ~/.bashrc
# 添加一行
source ~/catkin_ws/devel/setup.bash
cd ~/catkin_ws/src
catkin_create_pkg offboard_pkg roscpp std_msgs geometry_msgs mavros_msgs
cd offboard_pkg/src
vi offboard_node.cpp

 offboard_node.cpp内容如下:

/**
 * @file offb_node.cpp
 * @brief Offboard control example node, written with MAVROS version 0.19.x, PX4 Pro Flight
 * Stack and tested in Gazebo SITL
 */

#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <mavros_msgs/State.h>

mavros_msgs::State current_state;
void state_cb(const mavros_msgs::State::ConstPtr& msg)
    current_state = *msg;


int main(int argc, char **argv)

    ros::init(argc, argv, "offb_node");
    ros::NodeHandle nh;

    ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State>
            ("mavros/state", 10, state_cb);
    ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped>
            ("mavros/setpoint_position/local", 10);
    ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool>
            ("mavros/cmd/arming");
    ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode>
            ("mavros/set_mode");

    //the setpoint publishing rate MUST be faster than 2Hz
    ros::Rate rate(20.0);

    // wait for FCU connection
    while(ros::ok() && !current_state.connected)
        ros::spinOnce();
        rate.sleep();
    

    geometry_msgs::PoseStamped pose;
    pose.pose.position.x = 0;
    pose.pose.position.y = 0;
    pose.pose.position.z = 2;

    //send a few setpoints before starting
    for(int i = 100; ros::ok() && i > 0; --i)
        local_pos_pub.publish(pose);
        ros::spinOnce();
        rate.sleep();
    

    mavros_msgs::SetMode offb_set_mode;
    offb_set_mode.request.custom_mode = "OFFBOARD";

    mavros_msgs::CommandBool arm_cmd;
    arm_cmd.request.value = true;

    ros::Time last_request = ros::Time::now();

    while(ros::ok())
        if( current_state.mode != "OFFBOARD" &&
            (ros::Time::now() - last_request > ros::Duration(5.0)))
            if( set_mode_client.call(offb_set_mode) &&
                offb_set_mode.response.mode_sent)
                ROS_INFO("Offboard enabled");
            
            last_request = ros::Time::now();
         else 
            if( !current_state.armed &&
                (ros::Time::now() - last_request > ros::Duration(5.0)))
                if( arming_client.call(arm_cmd) &&
                    arm_cmd.response.success)
                    ROS_INFO("Vehicle armed");
                
                last_request = ros::Time::now();
            
        

        local_pos_pub.publish(pose);

        ros::spinOnce();
        rate.sleep();
    

    return 0;


~/catkin_ws/src/offboard_pkg/CMakeLists.txt文件添加内容:

add_executable(offboard_node src/offboard_node.cpp)
target_link_libraries(offboard_node $catkin_LIBRARIES)
cd ~/catkin_ws

catkin build

终端1:打开仿真

cd Firmware
make px4_sitl gazebo

终端2:

roscore

终端3:

roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"

终端4:

rosrun offboard_pkg offboard_node

终端5:可查看节点

rosnode list

以上是关于jetson nano-mavros-px4的主要内容,如果未能解决你的问题,请参考以下文章

英伟达jetson系列盒子参数(jetson参数)

在 Jetson Nano 上安装 OpenCV 4.1.2 时出现问题。导入 cv2,没有名为“cv2”的模块

英伟达jetson系列盒子参数(jetson参数)信息

PyTorch for Jetson Nano - version 1.4.0 now available

[jetson]paddlepaddle2.4.0在jetpack5.0.2源码编译流程

jetson-mavros-terminal_control-px4