#include <iostream>
#include <cmath>
// Structure to represent the drone's state
struct DroneState {
double x; // Position in the x-axis
double y; // Position in the y-axis
double vx; // Velocity in the x-axis
double vy; // Velocity in the y-axis
double ax; // Acceleration in the x-axis
double ay; // Acceleration in the y-axis
};
// Function to update the drone's state based on acceleration and time step
void updateDroneState(DroneState& state, double dt) {
// Update velocity based on acceleration
state.vx += state.ax * dt;
state.vy += state.ay * dt;
// Update position based on velocity
state.x += state.vx * dt;
state.y += state.vy * dt;
}
int main() {
// Initial conditions
DroneState drone = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
double dt = 0.1; // Time step (seconds)
int steps = 100; // Number of simulation steps
// Simulate the drone flight
for (int i = 0; i < steps; ++i) {
// Example acceleration input: hovering with slight forward acceleration
if (i < 20) {
drone.ax = 0.0;
drone.ay = 0.1; // Small upward acceleration
} else if (i < 50) {
drone.ax = 0.1; // Forward acceleration
drone.ay = 0.0;
} else {
drone.ax = 0.0;
drone.ay = 0.0; // No acceleration (coasting)
}
// Update drone state
updateDroneState(drone, dt);
// Print the current state of the drone
std::cout << "Time: " << i * dt << " s, "
<< "Position: (" << drone.x << ", " << drone.y << "), "
<< "Velocity: (" << drone.vx << ", " << drone.vy << ")\n";
}
return 0;
}