-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
Base on maven in io.dronefleet.mavlink,version 1.1.9
Now I user the AcFly , I am attempting to switch the mode using the MAV_CMD_DO_SET_MODE method, as mentioned in my documentation. It mentions the "hold position mode" with the following code:
public void setUavMode(String sn, Integer mode) throws IOException {
float modeValue = 0;
UavDataCacheManager cacheManager = UavDataCacheManager.getInstance();
switch (mode) {
case 1:
// Guided mode
modeValue = 0x60000;
break;
case 2:
// Hold position mode
modeValue = 0x30000;
break;
case 3:
// Auto mode
modeValue = 0x4000000;
break;
default:
break;
}
boolean exists = cacheManager.hasUavData(sn);
if (exists) {
Map<String, Object> uavData = cacheManager.getUavDataBySn(sn);
Object cachedModeNum = uavData.get("modeNum");
if (cachedModeNum instanceof Float && (Float) cachedModeNum == modeValue) {
return;
}
}
sendCommand(
sn,
MavCmd.MAV_CMD_DO_SET_MODE,
1,
modeValue,
0, 0, 0, 0, 0
);
}
Here are the respective mode commands for switching between modes:
Hold position mode:
COMMAND_LONG {target_system: 1, target_component: 1, command: 176, confirmation: 0, param1: 1, param2: 0x30000, param3: 0.0, param4: 0, param5: 0.0, param6: 0.0, param7: 0.0}
Altitude hold mode:
COMMAND_LONG {target_system: 1, target_component: 1, command: 176, confirmation: 0, param1: 1, param2: 0x20000, param3: 0.0, param4: 0, param5: 0.0, param6: 0.0, param7: 0.0}
Mission mode:
COMMAND_LONG {target_system: 1, target_component: 1, command: 176, confirmation: 0, param1: 1, param2: 0x4000000, param3: 0.0, param4: 0, param5: 0.0, param6: 0.0, param7: 0.0}
Return to home mode:
COMMAND_LONG {target_system: 1, target_component: 1, command: 176, confirmation: 0, param1: 1, param2: 0x5000000, param3: 0.0, param4: 0, param5: 0.0, param6: 0.0, param7: 0.0}
However, when I attempt to switch the mode, I get an error. Here are the logs:
2025-06-06 10:23:46.966 - [MQTT Call: re4d3f6a7cc42f0aac8015a1d68913fecd][] INFO com.yuefei.uav.mavlink.service.MavlinkService - The mode value to be switched is 393216.0
2025-06-06 10:23:46.967 - [MQTT Call: re4d3f6a7cc42f0aac8015a1d68913fecd][] INFO com.yuefei.uav.mavlink.service.MavlinkService - The sent command is CommandLong{targetSystem=6, targetComponent=1, command=EnumValue{value=176, entry=MAV_CMD_DO_SET_MODE}, confirmation=0, param1=1.0, param2=393216.0, param3=0.0, param4=0.0, param5=0.0, param6=0.0, param7=0.0}
2025-06-06 10:23:47.010 - [Thread-8][] ERROR com.yuefei.uav.mavlink.service.MavlinkService - Command rejected: MAV_RESULT_DENIED, FROM: MAV_CMD_DO_SET_MODE
2025-06-06 10:23:47.417 - [Thread-8][] INFO com.yuefei.uav.mavlink.service.MavlinkService - baseMode value is EnumValue{value=209, entry=null}
2025-06-06 10:23:47.420 - [Thread-8][] INFO com.yuefei.uav.mavlink.service.MavlinkService - customMode value is 196608
The question is whether the issue is because I'm passing a value that is not in the 0x60000 hexadecimal format. Currently, I am unable to perform the mode switch operation. How should I proceed?
Metadata
Metadata
Assignees
Labels
No labels