2017-10-17 125 views
-2

我从无人机套件此源代码,我试图进行硬编码特定坐标的特定位置,使我们的无人机起飞,将在同一地点降落。这里要说的是,我与后无人驾驶飞机的武装,并准备去用户可以点击一个按钮选项链接代码。硬编码一个航点到无人机套件

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

什么是你的问题? – Korashen

+0

如何添加如果与坐标功能的语句是活跃的,当用户按下从UI一个按钮来调用无人驾驶飞机去其是上环已经宣布与预定坐标的具体位置? –

+0

如果无人机的武装,起飞,飞向(纬度,经度)和土地 –

回答

0

根据您的最新评论,步骤做会像:

  • 按下按钮,执行ActionA
  • ActionA由多个子行动 的**检查武装
    • 取走
    • 检查当前坐标和验证对目标坐标
      • 如果等号,然后降落
      • 如果不平等,CA lculate矢量并按照矢量

在伪代码,它应该是这样的:

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 
    } 
}