关键词:OSDK 4.x 避障功能
OSDK 4.x中提供了接口来开启和关闭避障,但是官方提供的sample代码并不能实际关闭或开启避障功能。考虑到官方OSDK 4.x代码的更新较慢,且不少开发者用于已经基于OSDK 4.x实现了大部分应用功能。现将代码修改方式通过此论坛帖提供:
主要修改代码文件:
dji_flight_assistant_module.hpp
将原hashvalue补全:
enum ParamHashValue : uint32_t {
USE_RTK_DATA = 1288992843, /*! Set rtk switch on or off*/
GO_HOME_ALTITUDE = 952919004, /*! Set return home altitude*/
HORIZ_AVOID = 3001460201, /*! Set horiz avoid enable*/
UPWARDS_AVOID = 854709684,
};
修改为:
enum ParamHashValue : uint32_t {
USE_RTK_DATA = 3301673070, /*! Set rtk switch on or off*/
GO_HOME_ALTITUDE = 3581930365, /*! Set return home altitude*/
HORIZ_AVOID = 1076454642, /*! Set horiz avoid enable*/
HORIZ_VISION_AVOID = 1705638792,
HORIZ_RADAR_AVOID = 3350259798,
UPWARDS_AVOID = 854709684,
UPWARDS_VISION_AVOID = 2415881690,
UPWARDS_RADAR_AVOID = 4157105210,
DOWN_AVOID = 901246535, //
};
接口实现代码修改:
dji_flight_assistant_module.cpp
水平方向设置:
ErrorCode::ErrorCodeType FlightAssistant::setCollisionAvoidanceEnabledSync(
AvoidEnable avoidEnable, int timeout) {
ErrorCode::ErrorCodeType ret;
if(ACK::SUCCESS == writeParameterByHashSync(ParamHashValue::HORIZ_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout))
{
ret = writeParameterByHashSync(ParamHashValue::HORIZ_VISION_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout);
}
return ret;
}
上方避障设置:
ErrorCode::ErrorCodeType FlightAssistant::setCollisionAvoidanceEnabledSync(
AvoidEnable avoidEnable, int timeout) {
ErrorCode::ErrorCodeType ret;
if(ACK::SUCCESS == writeParameterByHashSync(ParamHashValue::UPWARDS_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout))
{
ret = writeParameterByHashSync(ParamHashValue::UPWARDS_VISION_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout);
}
return ret;
}
下方避障设置:
ErrorCode::ErrorCodeType FlightAssistant::setCollisionAvoidanceEnabledSync(
AvoidEnable avoidEnable, int timeout) {
return writeParameterByHashSync(ParamHashValue::DOWN_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout);
}
也即对新修改的hashvalue中通过API进行设置即可实现对应方向上的避障开关。下方与水平和上方的避障开关不完全一样,上方和水平需要对两个hashvalue进行设置,完成后调用API即可在Pilot APP上的避障界面进行显示,可查看是否设置成功。
补充getstauts:
ErrorCode::ErrorCodeType FlightAssistant::setHorizCollisionAvoidanceEnabledSync(
AvoidEnable avoidEnable, int timeout) {
ErrorCode::ErrorCodeType ret;
if(ACK::SUCCESS == writeParameterByHashSync(ParamHashValue::HORIZ_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout))
{
ret = writeParameterByHashSync(ParamHashValue::HORIZ_VISION_AVOID,
(void*)&avoidEnable, sizeof(avoidEnable),
timeout);
}
return ret;
}
#if 0
void FlightAssistant::setHorizCollisionAvoidanceEnabledAsync(
FlightAssistant::AvoidEnable avoidEnable,
void (*UserCallBack)(ErrorCode::ErrorCodeType retCode, UserData userData),
UserData userData) {
writeParameterByHashAsync(ParamHashValue::HORIZ_AVOID, (void*)&avoidEnable,
sizeof(avoidEnable), setParameterDecoder,
UserCallBack, userData);
}
#endif
ErrorCode::ErrorCodeType FlightAssistant::getHorizCollisionAvoidanceEnabledSync(
AvoidEnable& avoidEnable, int timeout) {
uint8_t param[MAX_PARAMETER_VALUE_LENGTH];
ErrorCode::ErrorCodeType ret =
readParameterByHashSync(ParamHashValue::HORIZ_VISION_AVOID, param, timeout);
if (ret == ErrorCode::SysCommonErr::Success) {
avoidEnable = *(AvoidEnable*)param;
}
return ret;
}
#if 0
void FlightAssistant::getHorizCollisionAvoidanceEnabledAsync(
void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
AvoidEnable avoidEnable, UserData userData),
UserData userData) {
readParameterByHashAsync<AvoidEnable>(ParamHashValue::HORIZ_AVOID,
getAvoidEnableDecoder, UserCallBack,
userData);
}
#endif
ErrorCode::ErrorCodeType FlightAssistant::setUpwardsAvoidanceEnabledSync(UpwardsAvoidEnable upwardsAvoidEnable, int timeout)
{
ErrorCode::ErrorCodeType ret;
if(ACK::SUCCESS == writeParameterByHashSync(ParamHashValue::UPWARDS_AVOID,
(void*)&upwardsAvoidEnable,
sizeof(upwardsAvoidEnable), timeout))
{
ret = writeParameterByHashSync(ParamHashValue::UPWARDS_VISION_AVOID,
(void*)&upwardsAvoidEnable, sizeof(upwardsAvoidEnable),
timeout);
}
return ret;
}
#if 0
void FlightAssistant::setUpwardsAvoidanceEnabledAsync(
UpwardsAvoidEnable upwardsAvoidEnable,
void (*UserCallBack)(ErrorCode::ErrorCodeType retCode, UserData userData),
UserData userData) {
writeParameterByHashAsync(
ParamHashValue::UPWARDS_AVOID, (void*)&upwardsAvoidEnable,
sizeof(upwardsAvoidEnable), setParameterDecoder, UserCallBack, userData);
}
#endif
ErrorCode::ErrorCodeType FlightAssistant::getUpwardsAvoidanceEnabledSync(
UpwardsAvoidEnable& upwardsAvoidEnable, int timeout) {
uint8_t param[MAX_PARAMETER_VALUE_LENGTH];
ErrorCode::ErrorCodeType ret =
readParameterByHashSync(ParamHashValue::UPWARDS_VISION_AVOID, param, timeout);
if (ret == ErrorCode::SysCommonErr::Success) {
upwardsAvoidEnable = *(UpwardsAvoidEnable*)param;
}
return ret;
}
#if 0
void FlightAssistant::getUpwardsAvoidanceEnabledAsync(
void (*UserCallBack)(ErrorCode::ErrorCodeType retCode,
UpwardsAvoidEnable upwardsEnable, UserData userData),
UserData userData) {
readParameterByHashAsync<UpwardsAvoidEnable>(ParamHashValue::UPWARDS_AVOID,
getUpwardsAvoidEnableDecoder,
UserCallBack, userData);
}
#endif
ErrorCode::ErrorCodeType FlightAssistant::setDownwardsAvoidanceEnabledSync(AvoidEnable avoidEnable, int timeout)
{
return writeParameterByHashSync(ParamHashValue::DOWN_AVOID, (void*)&avoidEnable, sizeof(avoidEnable), timeout);
}
ErrorCode::ErrorCodeType FlightAssistant::getDownwardsAvoidanceEnabledSync(AvoidEnable& avoidEnable, int timeout)
{
uint8_t param[MAX_PARAMETER_VALUE_LENGTH];
ErrorCode::ErrorCodeType ret = readParameterByHashSync(ParamHashValue::DOWN_AVOID, param, timeout);
if (ret == ErrorCode::SysCommonErr::Success) {
avoidEnable = *(AvoidEnable*)param;
}
return ret;
}
评论
0 条评论
请登录写评论。