IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> Kerloud 飞车在线控制C++教程 -> 正文阅读

[人工智能]Kerloud 飞车在线控制C++教程

产品简介

在这里插入图片描述Kerloud flying rover是由云讷科技(深圳)有限公司推出的一款面向飞车爱好者的高性价比开发平台,产品设计紧凑,兼具无人机(UAV)、无人车(UGV)模式。平台支持辅助模块扩展(树莓派、英伟达电脑),基于云讷官方提供的开源C++、Python版本SDK,用户可在室内、室外场景下快捷展开应用开发。

本教程完整链接为:https://cloudkerneltech.gitbook.io/kerloud-flyingrover/user-guide-zh/tutorials_zh/offboard_cplus

更多信息请参考官方产品网页:https://cloudkerneltech.gitbook.io/kerloud-flyingrover/

基于ROS C++ API的Offboard控制

本教程将演示如何控制飞车在陆地车、多旋翼模式下实现航路点任务。

(1)环境设置

本教程推荐的环境为Ubuntu18.04系统下ROS melodic。
现成可用的ROS工作区位于机载电脑~/src/catkinws_offboard目录下,该工作区包含我们官方资源库中的软件包,官方在维护的资源库链接如下:

用户可通过如下指令更新到最新版本:

cd ~/src/catkinws_offboard/mavros
git pull origin
git checkout dev_flyingrover

cd ~/src/catkinws_offboard/mavlink
git pull origin
git checkout dev_flyingrover

cd ~/src/catkinws_offboard/offboard_flyingrover
git pull origin
git checkout dev_flyingrover

编译工作区:

cd ~/src/catkinws_offboard
catkin build -j 1 # set j=1 only for raspberry Pi

在树莓派电脑上,此编译过程耗时可能超过十分钟,首次操作时请耐心等待。
可使用如下指令清空工作区:

cd ~/src/catkinws_offboard
catkin clean

(2)代码讲解

例程代码为标准ROS节点形式,用户需熟悉官方ROS教程中发布、订阅节点的编程方法,官方链接为:http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber(c%2B%2B)。 重点指出,offboard_flyingrover节点包含以下几个文件:

  • offboard_flyingrover/launch/off_mission.launch: offboard控制节点的默认启动文件。
  • offboard_flyingrover/launch/waypoints_xyzy.yaml: ENU坐标系下的航路点任务定义文件,包含相应的偏航信息。
  • offboard_flyingrover/src/off_mission_node.cpp: 用于offboard控制的ROS节点文件。

本例程实现的任务描述如下:飞车将先在陆地车模式下走过几个航路点,到达最后一个航路点后切换为多旋翼模式,然后起飞依次走过之前相同的航路点。为清晰起见,我们在此按顺序讲解off_mission_node中的主要功能:

订阅、发布、服务的声明

我们通常在主程序开头处声明ROS的订阅、发布、服务。
通过mavros包中丰富的主题或服务,可轻松实现信息获取或命令发送。例如,若要获取无人机的本地位置信息,则需订阅mavros/setpoint_position/local主题。请注意,所用坐标系为ENU(East-North-Up)。Mavros软件包的标准信息可参见:http://wiki.ros.org/mavros。对于飞车专用的其他主题或服务,请参阅API部分。

/*subscriptions, publications and services*/
ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State>
        ("mavros/state", 5, state_cb);

//subscription for flying rover state
ros::Subscriber extended_state_sub = nh.subscribe<mavros_msgs::ExtendedState>
        ("mavros/extended_state", 2, extendedstate_cb);

//subscription for local position
ros::Subscriber local_pose_sub = nh.subscribe<geometry_msgs::PoseStamped>
        ("mavros/local_position/pose", 5, local_pose_cb);

ros::Subscriber rc_input_sub = nh.subscribe<mavros_msgs::RCIn>
        ("mavros/rc/in", 5, rc_input_cb);

//publication for local position setpoint
ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped>
        ("mavros/setpoint_position/local", 5);

//service for arm/disarm
ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool>
        ("mavros/cmd/arming");

//service for main mode setting
ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode>
        ("mavros/set_mode");

//service for command send
ros::ServiceClient command_long_client = nh.serviceClient<mavros_msgs::CommandLong>
        ("mavros/cmd/command");

服务指令构建

接下来,我们将通过如下方式创建必要的命令来调用上文中所定义的服务。

/*service commands*/
mavros_msgs::SetMode offb_set_mode;
offb_set_mode.request.custom_mode = "OFFBOARD";

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

mavros_msgs::CommandBool disarm_cmd;
disarm_cmd.request.value = false;

//flying rover mode switching commands
mavros_msgs::CommandLong switch_to_mc_cmd;//command to switch to multicopter
switch_to_mc_cmd.request.command = (uint16_t)mavlink::common::MAV_CMD::DO_FLYINGROVER_TRANSITION;
switch_to_mc_cmd.request.confirmation = 0;
switch_to_mc_cmd.request.param1 = (float)mavlink::common::MAV_FLYINGROVER_STATE::MC;

mavros_msgs::CommandLong switch_to_rover_cmd;//command to switch to rover
switch_to_rover_cmd.request.command = (uint16_t)mavlink::common::MAV_CMD::DO_FLYINGROVER_TRANSITION;
switch_to_rover_cmd.request.confirmation = 0;
switch_to_rover_cmd.request.param1 = (float)mavlink::common::MAV_FLYINGROVER_STATE::ROVER;

陆地车、多旋翼模式下的航路点坐标解析

陆地车、多旋翼模式下的航路点坐标信息,会以不同的方式传递到位置设定主题。多旋翼模式下,需要用到3D位置,而且起飞过程需单独处理;陆地车模式下,则可直接将2D位置传递到所需的主题。

if (current_wpindex == 0){

    //use yaw measurement during multicopter takeoff (relative height<1) to avoid rotation, and use relative pose
    if (_flyingrover_mode == FLYINGROVER_MODE::MULTICOPTER){

        //initialize for the 1st waypoint when offboard is triggered
        if (!is_tko_inited_flag && current_state.mode=="OFFBOARD"){

            //reload waypoint from yaml
            initTagetVector(wp_list);

            waypoints.at(0).pose.position.x += current_local_pos.pose.position.x; //set with relative position here
            waypoints.at(0).pose.position.y += current_local_pos.pose.position.y;
            waypoints.at(0).pose.position.z += current_local_pos.pose.position.z;

            tf::Quaternion q = tf::createQuaternionFromYaw(current_yaw);//set with current yaw measurement

            tf::quaternionTFToMsg(q, waypoints.at(0).pose.orientation);

            is_tko_inited_flag = true;
        }

        //update yaw setpoint after tko is finished
        if (is_tko_inited_flag && !is_tko_finished){

            if (current_local_pos.pose.position.z >2.0f){ //reset yaw to wp_list value

                ROS_INFO("Takeoff finished, reset to waypoint yaw");

                XmlRpc::XmlRpcValue data_list(wp_list[0]);

                tf::Quaternion q = tf::createQuaternionFromYaw(data_list[3]);
                tf::quaternionTFToMsg(q, waypoints.at(0).pose.orientation);

                is_tko_finished = true;
            }

        }

    }
    else //rover mode, pass relative update, use loaded waypoints
    {
        waypoints.at(0).pose.position.x += current_local_pos.pose.position.x; //set with relative position here
        waypoints.at(0).pose.position.y += current_local_pos.pose.position.y;
        waypoints.at(0).pose.position.z += current_local_pos.pose.position.z;
    }


    pose = waypoints.at(0);
}
else
    pose = waypoints.at(current_wpindex);

模式切换

本例程的最后一部分内容是处理飞车的模式切换。当飞车在陆地车模式下到达最后一个航路点时,程序将调用模式转换服务将飞车切换到多旋翼模式。一旦切换成功,航路点索引就会被清零,飞车将会起飞并沿相同的航路点飞行。

/*mode switching or disarm after last waypoint*/
if (current_wpindex == waypoints.size()-1 && _flag_last_wp_reached){

    if (_flyingrover_mode == FLYINGROVER_MODE::ROVER){

        //request to switch to multicopter mode
        if( current_extendedstate.flyingrover_state== mavros_msgs::ExtendedState::FLYINGROVER_STATE_ROVER &&
            (ros::Time::now() - last_request > ros::Duration(5.0))){

            if( command_long_client.call(switch_to_mc_cmd) && switch_to_mc_cmd.response.success){

                ROS_INFO("Flyingrover multicopter mode cmd activated");

                //update mode for next round
                _flyingrover_mode = FLYINGROVER_MODE::MULTICOPTER;
                current_wpindex = 0;
                _flag_last_wp_reached = false;

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

        }

    }
    else if (_flyingrover_mode == FLYINGROVER_MODE::MULTICOPTER){

        //disarm when landed and the vehicle is heading for the last waypoint
        if (current_extendedstate.landed_state == mavros_msgs::ExtendedState::LANDED_STATE_LANDING){

            if( current_state.armed &&
                (ros::Time::now() - last_request > ros::Duration(5.0))){

                if( arming_client.call(disarm_cmd) && arm_cmd.response.success){

                    ROS_INFO("Vehicle disarmed");
                    is_tko_inited_flag = false;
                    is_tko_finished = false;
                }
                last_request = ros::Time::now();

            }

        }
    }
}

如何进行实测

现在可以将飞车拿到室外进行实测了。为避免意外,用户需严格按照如下流程操作:

  • 将电池及线固定好,确保在飞行中不会发生脱落。

  • 确保所有开关都处于初始位置,且油门通道已拉到最低。

  • 电池上电。

  • 等待GPS锁定:通常2-3分钟后我们可听到提示音,同时飞控上的LED会变为绿色。

  • 确保飞手已就位,且飞车周围没有人。等待几分钟,机载电脑启动后可通过本地Wi-Fi网络进行远程登录,确认 /src/catkinws_offboard/src/offboard_flyingrover/launch/waypoints_xyzy.yaml目录下的航路点任务,然后通过如下指令启动offboard控制单元:

       # launch a terminal
       cd ~/src/catkinws_offboard
       source devel/setup.bash
       roslaunch mavros px4.launch fcu_url:="/dev/ttyPixhawk:921600"
     
       # launch a new terminal
       cd ~/src/catkinws_offboard
       source devel/setup.bash
       roslaunch offboard_flyingrover off_mission.launch
    
  • 拉低油门摇杆,同时右推偏航摇杆进行机器解锁,将听到一个长音提示。

  • 使用特定的摇杆(例如通道7)切换到offboard模式,飞车将自动启动航路点任务。恭喜飞行成功!

如何购买

Kerloud无人飞车可以在云讷科技的官方淘宝店铺采购获得:

https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-23259098032.16.20804e895t5Ir2&id=654976354925

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2021-09-29 10:15:46  更:2021-09-29 10:18:29 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/21 18:19:50-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码