[英]hard coding a waypoint into the drone kit
I have this source code from drone kit and i am trying to hard code a specific coordinates for a specific location so that we the drone take off it will land at the same location.我有来自无人机套件的源代码,我正在尝试为特定位置硬编码特定坐标,以便我们无人机起飞时它会降落在同一位置。 here is the code that I am linking with a button option that the user can click after the drone is armed and ready to go.这是我与一个按钮选项链接的代码,用户可以在无人机准备就绪后单击该按钮选项。
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.");
}
});
}
}
Based on your latest comment, the steps to do would be like:根据您的最新评论,执行步骤如下:
In pseudo code, it would look like this:在伪代码中,它看起来像这样:
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.