1. IA Decision Engine
Roda em loop contínuo. Lê sensores e toma decisões automáticas de plantio ou parada com base em umidade, temperatura e previsão de chuva.
# ai/decision_engine.py
import time
import requests
import random
API_URL = "http://api:8000"
def get_field_data():
# simulação de sensores
return {
"soil_moisture": random.randint(20, 80),
"temperature": random.randint(20, 35),
"rain_forecast": random.choice([True, False])
}
def decision_loop():
while True:
data = get_field_data()
print("DADOS:", data)
# lógica de decisão
if data["soil_moisture"] < 30 and not data["rain_forecast"]:
print("IA DECIDIU: INICIAR PLANTIO")
requests.post(f"{API_URL}/plant?machine_id=tractor_01&depth=5&spacing=0.5")
elif data["soil_moisture"] > 70:
print("IA DECIDIU: PARAR")
requests.post(f"{API_URL}/stop?machine_id=tractor_01")
time.sleep(10)
if __name__ == "__main__":
decision_loop()| Condição | Decisão IA | Ação API |
|---|---|---|
| Umidade < 30% E sem chuva | 🟢 INICIAR PLANTIO | POST /plant |
| Umidade > 70% | 🔴 PARAR TUDO | POST /stop |
| Chuva prevista | ⏸️ AGUARDAR | (nenhuma) |
# Adicionar no docker-compose.yml
ai:
build: ./ai
depends_on:
- api# ai/Dockerfile FROM python:3.11 WORKDIR /app COPY . . RUN pip install requests CMD ["python", "decision_engine.py"]
2. AutoPilot GPS RTK
GPS RTK
u-blox ZED-F9P
Base RTK / NTRIP
Correção diferencial
IMU
Giroscópio 9 eixos
Controlador
ESP32 / Jetson Nano
# autopilot/navigation.py
import math
def calculate_heading(current, target):
lat1, lon1 = current
lat2, lon2 = target
dLon = lon2 - lon1
x = math.sin(dLon) * math.cos(lat2)
y = (math.cos(lat1) * math.sin(lat2)
- math.sin(lat1) * math.cos(lat2) * math.cos(dLon))
heading = math.atan2(x, y)
return math.degrees(heading)
def steering_control(current_heading, target_heading):
error = target_heading - current_heading
# PID simples
Kp = 1.5
steering = Kp * error
return max(min(steering, 30), -30) # limite volante ±30°3. Controle Real da Direção
Conversão ângulo → CAN byte
# autopilot/can_control.py
def send_steering(angle, bus):
# converte ângulo em byte (range: -30 a +30 → 0 a 240)
value = int((angle + 30) * 4)
send_can(0x200, [value], bus)
# CAN ID 0x200 → Controle de direção
# Byte 0 → ângulo codificado (0–240)4. Linhas de Plantio Automáticas
Gera linhas de plantio paralelas automaticamente a partir da largura do talhão e do espaçamento desejado.
# autopilot/path_planner.py
def generate_lines(field_width, spacing):
"""
Gera linhas de plantio paralelas.
field_width: largura do talhão (metros)
spacing: espaçamento entre linhas (metros)
"""
lines = []
x = 0
while x < field_width:
lines.append(x)
x += spacing
return lines
# Exemplo: talhão 100m, espaçamento 0.5m → 200 linhas
lines = generate_lines(100, 0.5)
print(f"Total de linhas: {len(lines)}")5. Loop Completo Autônomo
# Fluxo completo — autopilot_main.py
from decision_engine import get_field_data
from path_planner import generate_lines
from navigation import calculate_heading, steering_control
from can_control import send_steering
def autonomous_loop(bus):
while True:
# 1. IA decide
data = get_field_data()
if data["soil_moisture"] < 30 and not data["rain_forecast"]:
# 2. Gera linhas de plantio
lines = generate_lines(field_width=100, spacing=0.5)
for line_x in lines:
target = (line_x, 0)
current = get_gps_position()
# 3. Autopilot navega
target_hdg = calculate_heading(current, target)
current_hdg = get_imu_heading()
steering = steering_control(current_hdg, target_hdg)
# 4. Gateway envia CAN → máquina executa
send_steering(steering, bus)IA decide plantar
decision_engine.py · umidade < 30%
Gera linhas
path_planner.py · 200 linhas auto
Autopilot navega
navigation.py · RTK + heading
Gateway envia CAN
can_control.py · 0x200 steering
Máquina executa
Firmware ESP32 · atuadores
6. Segurança (OBRIGATÓRIO)
Botão STOP físico
GPIO independente de software. Para tudo imediatamente.
Geofencing
Limite geográfico da fazenda. Bloqueia saída do talhão.
Detecção de obstáculo
LIDAR ou ultrassom. Para antes de colidir.
Fail-safe sem GPS
Perda de sinal → parada automática e alerta.
7. Nível de Autonomia
L0
Manual
L1
Assistido
L2
Parcial
L3
Condicional
L4
Alto / ZONY™
🔥 Você está aqui
🔥 Resultado Final
"A fazenda pensa, decide e se move sozinha."
— ZONY Autonomous Decision + AutoPilot RTK™