基于ros的通信能够有效帮助UAV之间不同板块的信息发布与获取。其主要有两部分:消息的订阅与发布(subscribe&publisher)还有服务和客户端(service&client)。前者是一个节点(node)发布话题(topic)让另一个节点订阅。后者是客户端向服务发送请求(call request)。其中话题的内容与作用、服务的请求的格式都可以从http://wiki.ros.org/dji_sdk/中查询。
e.g.
/dji_sdk/flight_control_setpoint_generic (sensor_msgs/Joy)控制的flag见(https://blog.csdn.net/banzhuan133/article/details/81434036)
此外也能通过查询获得一些类似flag里面代替数值的代码。
见:https://gitee.com/dji-sdk/Onboard-SDK/blob/3.8/osdk-core/api/inc/dji_control.hpp
里面VERTICAL_VELOCITY = 0x00等就是如此
这是被/dji_sdk订阅的topic。可以在wiki.ros上找到相关介绍如下:
/dji_sdk/flight_control_setpoint_generic (sensor_msgs/Joy)
- General setpoint where axes[0] to axes[3] stores set-point data for the 2 horizontal channels, the vertical channel, and the yaw channel, respectively. The meaning of the set-point data will be interpreted based on the control flag which is stored in axes[4].
所以我们就可以得知,通过发布这类型为<sensor_msgs::Joy>的topic能够通过flag选择相应的控制类型。topic的名称为(”dji_sdk/flight_control_setpoint_generic”),python的类型可能需要再加一个“/”于topic名称的最前面。
具体示例如下:
声明一个pub其类型为<sensor_msgs::Joy>(需要相应头文件"sensor_msgs/Joy.h")
ros::Publisher ctrlBrakePub = nh.advertise<sensor_msgs::Joy>("dji_sdk/flight_control_setpoint_generic", 10);
明确pub的内容
sensor_msgs::Joy controlVelYawRate;
uint8_t flag = (
DJISDK::VERTICAL_VELOCITY |
DJISDK::HORIZONTAL_VELOCITY |
DJISDK::YAW_RATE |
DJISDK::HORIZONTAL_GROUND |
DJISDK::STABLE_ENABLE);
/*flag是一个无符号8位整型数,利用以上符号代替一些十六进制数,通过或运算得到一个flag,
这个flag是唯一的,能够选择性表达不同的控制模式*/
controlVelYawRate.axes.push_back(0);
controlVelYawRate.axes.push_back(0);
controlVelYawRate.axes.push_back(0);
controlVelYawRate.axes.push_back(0);
controlVelYawRate.axes.push_back(flag);//通过vector的push_back()运算控制.axes[0]
//to axes[5] 的value。
ctrlBrakePub.publish(controlVelYawRate);//发布出去
这样消息就能发布出去了。
从wiki和blog中我们能够知道,这个发布最终能够控制无人机的水平速度(vx,vy)垂直速度(vz)and yaw rate of UAV.
If we want to control the altitude of the UAV, we need to change the "DJISDK::HORIZONTAL_VELOCITY" into "DJISDK::VERTICAL_POSITION".
DJISDK::HORIZONTAL_GROUND shows that the position is measured in horizontal frame(ENU) .