ROS下的控制指令依旧通过发布话题和订阅话题来完成
M100通过发布sensor_msgs::Joy来完成控制命令,例如
ctrlBrakePub = nh.advertise<sensor_msgs::Joy>("dji_sdk/flight_control_setpoint_generic", 10);
具体如下
sensor_msgs::Joy controlVelYawRate;
uint8_t flag = (DJISDK::VERTICAL_VELOCITY |
DJISDK::HORIZONTAL_VELOCITY |
DJISDK::YAW_RATE |
DJISDK::HORIZONTAL_GROUND |
DJISDK::STABLE_ENABLE);
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);
ctrlBrakePub.publish(controlVelYawRate);
这里的关键在这个FLAG上,FLAG是个8位整形数
1:水平控制模式
enum HorizontalLogic
{
/*!
- Set the control-mode to control pitch & roll
angle of the vehicle.
- Need to be referenced to either the ground or
body frame by HorizontalCoordinate setting.
- Limit: 35 degree
*/
HORIZONTAL_ANGLE = 0x00,
/*!
- Set the control-mode to control horizontal
vehicle velocities.
- Need to be referenced to either the ground
or body frame by HorizontalCoordinate setting.
- Limit: 30 m/s
*/
HORIZONTAL_VELOCITY = 0x40,
/*!
- Set the control-mode to control position
offsets of pitch & roll directions
- Need to be referenced to either the ground
or body frame by HorizontalCoordinate setting.
- Limit: N/A
*/
HORIZONTAL_POSITION = 0x80,
/*!
- Set the control-mode to control rate of
change of the vehicle's attitude
- Need to be referenced to either the ground
or body frame by HorizontalCoordinate setting.
- Limit: 150.0 deg/s
*/
HORIZONTAL_ANGULAR_RATE = 0xC0
};
2:控制垂直模式
enum VerticalLogic
{
/*!
- Set the control-mode to control the vertical
speed of UAV, upward is positive
- Limit: -5 to 5 m/s
*/
VERTICAL_VELOCITY = 0x00,
/*!
- Set the control-mode to control the height of UAV
- Limit: 0 to 120 m
*/
VERTICAL_POSITION = 0x10,
/*!
- Set the control-mode to directly control the thrust
- Range: 0% to 100%
*/
VERTICAL_THRUST = 0x20,
};
3:控制YAW
enum YawLogic
{
/*!
- Set the control-mode to control yaw angle.
- Yaw angle is referenced to the ground frame.
- In this control mode, Ground frame is enforeced in Autopilot.
*/
YAW_ANGLE = 0x00,
/*!
- Set the control-mode to control yaw angular velocity.
- Same reference frame as YAW_ANGLE.
- Limite: 150 deg/s
*/
YAW_RATE = 0x08
};
4:参考系选择
enum HorizontalCoordinate
{
/*! Set the x-y of ground frame as the horizontal frame (NEU) */
HORIZONTAL_GROUND = 0x00,
/*! Set the x-y of body frame as the horizontal frame (FRU) */
HORIZONTAL_BODY = 0x02
};
其中1为东北天参考系,2为机体参考系
5:自动悬停选择
enum StableMode
{
STABLE_DISABLE = 0x00, /*!< Disable the stable mode */
STABLE_ENABLE = 0x01 /*!< Enable the stable mode */
};