我有来自无人机套件的这个源代码,我正在尝试对特定位置的特定坐标进行硬编码,以便无人机起飞它将落在同一位置。这是我使用按钮选项链接的代码,用户可以在无人机布防并准备好后点击该按钮选项。
public void onBtnbringmymail(View view) {
State vehicleState = this.drone.getAttribute(AttributeType.STATE);
if (vehicleState.isFlying()) {
// Land
VehicleApi.getApi(this.drone).setVehicleMode(VehicleMode.COPTER_LAND, new SimpleCommandListener() {
@Override
public void onError(int executionError) {
alertUser("Unable to land the vehicle.");
}
@Override
public void onTimeout() {
alertUser("Unable to land the vehicle.");
}
});
} else if (vehicleState.isArmed()) {
// Take off
ControlApi.getApi(this.drone).takeoff(10, new AbstractCommandListener() {
@Override
public void onSuccess() {
alertUser("Taking off...");
}
@Override
public void onError(int i) {
alertUser("Unable to take off.");
}
@Override
public void onTimeout() {
alertUser("Unable to take off.");
}
});
} else if (!vehicleState.isConnected()) {
// Connect
alertUser("Connect to a drone first");
} else {
// Connected but not Armed
VehicleApi.getApi(this.drone).arm(true, false, new SimpleCommandListener() {
@Override
public void onError(int executionError) {
alertUser("Unable to arm vehicle.");
}
@Override
public void onTimeout() {
alertUser("Arming operation timed out.");
}
});
}
}
答案 0 :(得分:0)
根据您的最新评论,要做的步骤如下:
在伪代码中,它看起来像这样:
public class Autopilot
{
// To be called by a button press
public void execute()
{
if(systems.isEngaged() AND systems.isLanded())
{
takeOff();
}
}
public void takeOff()
{
// Execute TakeOff procedures
validateFlightPath();
}
public void validateFlightPath()
{
// Not within some meters to the target.
while(!systems.getGps().getCurrentCoordinates().withinRange(targetCoordinates, coordinateThreshold)
{
flyTo(targetCoordinates);
}
land();
}
public void flyTo(Coordinates coords)
{
Coordinates currentCoords = system.getGps().getCurrentCoordinates();
Vector3 flightVector = coords - currentCoords;
system.getFlightControls()... // Setup your flight controls to follow the flightVector;
}
public void land()
{
// Perform landing procedures
}
}