Ardupilot Controller Script
This commit is contained in:
@@ -7,12 +7,13 @@ Implement your GPS-denied landing algorithm.
|
||||
1. Edit `drone_controller.py`
|
||||
2. Find `calculate_landing_maneuver()`
|
||||
3. Implement your algorithm
|
||||
4. Test: `python standalone_simulation.py`
|
||||
4. Test with any simulation mode
|
||||
|
||||
## Function to Implement
|
||||
|
||||
```python
|
||||
def calculate_landing_maneuver(self, telemetry, rover_telemetry):
|
||||
# Your logic here
|
||||
return (thrust, pitch, roll, yaw)
|
||||
```
|
||||
|
||||
@@ -38,12 +39,16 @@ if landing_pad:
|
||||
|
||||
| Value | Range | Effect |
|
||||
|-------|-------|--------|
|
||||
| thrust | ±1.0 | Up/down |
|
||||
| thrust | ±1.0 | Up/down (positive = up) |
|
||||
| pitch | ±0.5 | Forward/back |
|
||||
| roll | ±0.5 | Left/right |
|
||||
| yaw | ±0.5 | Rotation |
|
||||
|
||||
## Example Algorithm
|
||||
Note: In ArduPilot mode, these are scaled to velocities:
|
||||
- Thrust → Z velocity
|
||||
- Pitch/Roll → X/Y velocity
|
||||
|
||||
## Example Algorithm (PD Control)
|
||||
|
||||
```python
|
||||
def calculate_landing_maneuver(self, telemetry, rover_telemetry):
|
||||
@@ -51,48 +56,18 @@ def calculate_landing_maneuver(self, telemetry, rover_telemetry):
|
||||
altitude = alt.get('altitude', 5.0)
|
||||
vert_vel = alt.get('vertical_velocity', 0.0)
|
||||
|
||||
vel = telemetry.get('velocity', {})
|
||||
vel_x = vel.get('x', 0.0)
|
||||
vel_y = vel.get('y', 0.0)
|
||||
|
||||
pad = telemetry.get('landing_pad')
|
||||
|
||||
# Altitude PD control
|
||||
thrust = 0.5 * (0 - altitude) - 0.3 * vert_vel
|
||||
thrust = 0.5 * (target_alt - altitude) - 0.3 * vert_vel
|
||||
|
||||
# Horizontal control
|
||||
pad = telemetry.get('landing_pad')
|
||||
if pad:
|
||||
pitch = 0.3 * pad['relative_x'] - 0.2 * vel_x
|
||||
roll = 0.3 * pad['relative_y'] - 0.2 * vel_y
|
||||
pitch = 0.3 * pad['relative_x']
|
||||
roll = 0.3 * pad['relative_y']
|
||||
else:
|
||||
pitch = -0.2 * vel_x
|
||||
roll = -0.2 * vel_y
|
||||
# Hover
|
||||
pitch = 0
|
||||
roll = 0
|
||||
|
||||
return (thrust, pitch, roll, 0.0)
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Easy
|
||||
python standalone_simulation.py --pattern stationary
|
||||
|
||||
# Medium
|
||||
python standalone_simulation.py --pattern circular --speed 0.3
|
||||
|
||||
# Hard
|
||||
python standalone_simulation.py --pattern random --speed 0.5
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Edit `config.py`:
|
||||
|
||||
```python
|
||||
CONTROLLER = {
|
||||
"Kp_z": 0.5,
|
||||
"Kd_z": 0.3,
|
||||
"Kp_xy": 0.3,
|
||||
"Kd_xy": 0.2,
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user