ajustes na firmware direcional v8
This commit is contained in:
parent
205c9508df
commit
161ca0ccab
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -25,7 +25,7 @@
|
||||||
<meta name="viewport" content="width=device-width,
|
<meta name="viewport" content="width=device-width,
|
||||||
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
<style>
|
<style>
|
||||||
#map_2a3d14da3dec6f21186e1667373ce43a {
|
#map_899d5215ba479a9bfa5d8b81cf21d734 {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100.0%;
|
width: 100.0%;
|
||||||
height: 100.0%;
|
height: 100.0%;
|
||||||
|
|
@ -39,14 +39,14 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div class="folium-map" id="map_2a3d14da3dec6f21186e1667373ce43a" ></div>
|
<div class="folium-map" id="map_899d5215ba479a9bfa5d8b81cf21d734" ></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
var map_2a3d14da3dec6f21186e1667373ce43a = L.map(
|
var map_899d5215ba479a9bfa5d8b81cf21d734 = L.map(
|
||||||
"map_2a3d14da3dec6f21186e1667373ce43a",
|
"map_899d5215ba479a9bfa5d8b81cf21d734",
|
||||||
{
|
{
|
||||||
center: [0.0, 0.0],
|
center: [0.0, 0.0],
|
||||||
crs: L.CRS.EPSG3857,
|
crs: L.CRS.EPSG3857,
|
||||||
|
|
@ -60,13 +60,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var tile_layer_f6a6232487eccae056d94768bd7259ef = L.tileLayer(
|
var tile_layer_81423970d7bc452c318d35692d0b5676 = L.tileLayer(
|
||||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||||
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
|
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
tile_layer_f6a6232487eccae056d94768bd7259ef.addTo(map_2a3d14da3dec6f21186e1667373ce43a);
|
tile_layer_81423970d7bc452c318d35692d0b5676.addTo(map_899d5215ba479a9bfa5d8b81cf21d734);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@
|
||||||
}
|
}
|
||||||
trajeto_json_add({"features": []});
|
trajeto_json_add({"features": []});
|
||||||
|
|
||||||
trajeto_json.addTo(map_2a3d14da3dec6f21186e1667373ce43a);
|
trajeto_json.addTo(map_899d5215ba479a9bfa5d8b81cf21d734);
|
||||||
|
|
||||||
function adicionarGeometria(novaGeometria) {
|
function adicionarGeometria(novaGeometria) {
|
||||||
trajeto_json.addData(novaGeometria);
|
trajeto_json.addData(novaGeometria);
|
||||||
|
|
@ -145,7 +145,7 @@
|
||||||
|
|
||||||
var marcadorDinamico = L.marker([0, 0], {
|
var marcadorDinamico = L.marker([0, 0], {
|
||||||
icon: customIcon
|
icon: customIcon
|
||||||
}).addTo(map_2a3d14da3dec6f21186e1667373ce43a);
|
}).addTo(map_899d5215ba479a9bfa5d8b81cf21d734);
|
||||||
|
|
||||||
// Conectar ao broker MQTT
|
// Conectar ao broker MQTT
|
||||||
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
|
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
|
||||||
|
|
@ -184,7 +184,7 @@
|
||||||
marcadorDinamico.setRotationAngle(angulo);
|
marcadorDinamico.setRotationAngle(angulo);
|
||||||
|
|
||||||
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
||||||
map_2a3d14da3dec6f21186e1667373ce43a.setView(novaPosicao, map_2a3d14da3dec6f21186e1667373ce43a.getZoom());
|
map_899d5215ba479a9bfa5d8b81cf21d734.setView(novaPosicao, map_899d5215ba479a9bfa5d8b81cf21d734.getZoom());
|
||||||
});
|
});
|
||||||
|
|
||||||
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Dispositivo: Direcional
|
// Dispositivo: Direcional
|
||||||
// Versão Firmware: 8
|
// Versão Firmware: 8
|
||||||
// Ultima atualização: 09/05/2024
|
// Ultima atualização: 13/05/2024
|
||||||
// Atualização: Inclusão do encoder magnético de posição absoluta
|
// Atualização: Inclusão do encoder magnético de posição absoluta
|
||||||
|
|
||||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
|
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
|
||||||
|
|
@ -17,7 +17,7 @@ bool Conectado = false;
|
||||||
|
|
||||||
int _TaxaAmostragem;
|
int _TaxaAmostragem;
|
||||||
int FrequenciaMaxima = 10000;
|
int FrequenciaMaxima = 10000;
|
||||||
double _Margem = 0.5;
|
double _Margem = 2.0;
|
||||||
|
|
||||||
int dutyCycle = 512;
|
int dutyCycle = 512;
|
||||||
double _frequencia = 4000;
|
double _frequencia = 4000;
|
||||||
|
|
@ -76,7 +76,7 @@ class Motor {
|
||||||
_pinoDIR.Conectar(false);
|
_pinoDIR.Conectar(false);
|
||||||
_pinoEncoder.Conectar();
|
_pinoEncoder.Conectar();
|
||||||
|
|
||||||
encoderKalman = new SimpleKalmanFilter(2, 2, 0.01);
|
encoderKalman = new SimpleKalmanFilter(1, 2, 0.01);
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(&Motor::RampaTaskWrapper, "RampaTask", 5000, this, 20 - _canal, &RampaTaskHandle, tskNO_AFFINITY);
|
xTaskCreatePinnedToCore(&Motor::RampaTaskWrapper, "RampaTask", 5000, this, 20 - _canal, &RampaTaskHandle, tskNO_AFFINITY);
|
||||||
|
|
||||||
|
|
@ -139,8 +139,6 @@ class Motor {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
double _anguloAnterior = 0;
|
|
||||||
|
|
||||||
TaskHandle_t RampaTaskHandle = NULL;
|
TaskHandle_t RampaTaskHandle = NULL;
|
||||||
static void RampaTaskWrapper(void *pvParameters) {
|
static void RampaTaskWrapper(void *pvParameters) {
|
||||||
Motor *motor = static_cast<Motor*>(pvParameters);
|
Motor *motor = static_cast<Motor*>(pvParameters);
|
||||||
|
|
@ -165,6 +163,7 @@ class Motor {
|
||||||
} else {
|
} else {
|
||||||
VerificarAnguloSP();
|
VerificarAnguloSP();
|
||||||
}
|
}
|
||||||
|
|
||||||
Atualizar();
|
Atualizar();
|
||||||
|
|
||||||
// Envia dados via serial em intervalos definidos por _TaxaAmostragem
|
// Envia dados via serial em intervalos definidos por _TaxaAmostragem
|
||||||
|
|
@ -183,60 +182,99 @@ class Motor {
|
||||||
_pinoDIR.set(_Sentido_SP != Antihorario);
|
_pinoDIR.set(_Sentido_SP != Antihorario);
|
||||||
}
|
}
|
||||||
|
|
||||||
int leituras = 0;
|
double _ultimaLeituraValida = 0; // Armazena a última leitura válida do ângulo
|
||||||
|
double _limiarPico = 5; // Define o limiar máximo aceitável para a mudança de ângulo entre leituras
|
||||||
|
int _vezesPico = 0;
|
||||||
|
|
||||||
void AferirPosicao() {
|
void AferirPosicao() {
|
||||||
if (_pinoEncoder.Definido()) {
|
if (_pinoEncoder.Definido()) {
|
||||||
// Lê o valor analógico do pino conectado à saída analógica do AS5600
|
|
||||||
int leitura = _pinoEncoder.get();
|
int leitura = _pinoEncoder.get();
|
||||||
float leituraNormalizada = encoderKalman->updateEstimate(leitura);
|
float leituraNormalizada = encoderKalman->updateEstimate(leitura);
|
||||||
|
|
||||||
// Converte a leitura para ângulo (0V a 3.3V corresponde a 0 a 360 graus)
|
|
||||||
double _angulo = (leituraNormalizada / 4095.0) * 360.0;
|
double _angulo = (leituraNormalizada / 4095.0) * 360.0;
|
||||||
|
double angulo_com_offset = _angulo - _Angulo_Offset;
|
||||||
// Ajusta o ângulo com o offset
|
|
||||||
double angulo_com_offset = _angulo - _Angulo_Offset; // Considerando que o offset pode ser positivo ou negativo
|
|
||||||
|
|
||||||
// Normaliza o ângulo para o intervalo de -180 a 180 graus
|
// Normaliza o ângulo para o intervalo de -180 a 180 graus
|
||||||
while (angulo_com_offset > 180) angulo_com_offset -= 360;
|
while (angulo_com_offset > 180) angulo_com_offset -= 360;
|
||||||
while (angulo_com_offset < -180) angulo_com_offset += 360;
|
while (angulo_com_offset < -180) angulo_com_offset += 360;
|
||||||
|
|
||||||
if (leituras > 700) {
|
// Verifica se a leitura atual é um pico
|
||||||
_Sentido =
|
if (fabs(angulo_com_offset - _ultimaLeituraValida) <= _limiarPico) {
|
||||||
_MotorLigado && angulo_com_offset > _anguloAnterior ? Horario :
|
// Se não for um pico, atualiza a última leitura válida
|
||||||
_MotorLigado && angulo_com_offset < _anguloAnterior ? Antihorario :
|
_ultimaLeituraValida = angulo_com_offset;
|
||||||
Parado;
|
} else {
|
||||||
leituras = 0;
|
_vezesPico++;
|
||||||
_anguloAnterior = angulo_com_offset;
|
|
||||||
|
if (_vezesPico > 20) {
|
||||||
|
_vezesPico = 0;
|
||||||
|
_ultimaLeituraValida = angulo_com_offset;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Se for um pico, utiliza a última leitura válida e ignora a atual
|
||||||
|
angulo_com_offset = _ultimaLeituraValida;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
leituras++;
|
|
||||||
|
|
||||||
_Angulo = angulo_com_offset;
|
_Angulo = angulo_com_offset;
|
||||||
|
|
||||||
|
DefinirSentidoDeGiro();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerificarAnguloSP() {
|
|
||||||
if (_MotorLigado) {
|
double _anguloAnterior = 0;
|
||||||
if (_Angulo_SP > -1) {
|
int leituras = 0;
|
||||||
if (_Sentido_SP == Horario && _Angulo >= _Angulo_SP) {
|
void DefinirSentidoDeGiro() {
|
||||||
_MotorLigado = false;
|
double _anguloAtual = _Angulo;
|
||||||
|
|
||||||
|
if (leituras > 500) {
|
||||||
|
if (_MotorLigado) {
|
||||||
|
if (_anguloAtual > _anguloAnterior) {
|
||||||
|
_Sentido = Horario;
|
||||||
}
|
}
|
||||||
else if (_Sentido_SP == Antihorario && _Angulo <= (_Angulo_SP * -1)) {
|
else if (_anguloAtual < _anguloAnterior) {
|
||||||
_MotorLigado = false;
|
_Sentido = Antihorario;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (false) {
|
else {
|
||||||
if (Referenciado && (_Sentido_SP == Horario && _Angulo >= RefMax)) {
|
_Sentido = Parado;
|
||||||
_MotorLigado = false;
|
}
|
||||||
}
|
|
||||||
else if (Referenciado && (_Sentido_SP == Antihorario && _Angulo <= RefMin)) {
|
_anguloAnterior = _anguloAtual;
|
||||||
_MotorLigado = false;
|
|
||||||
}
|
leituras = 0;
|
||||||
|
}
|
||||||
|
leituras++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long previousMillisCorrecao = millis();
|
||||||
|
void VerificarAnguloSP() {
|
||||||
|
bool ModoSP = (_Angulo_SP > -1);
|
||||||
|
if (_MotorLigado) {
|
||||||
|
double AnguloComparar = ModoSP ? _Angulo_SP : RefMax;
|
||||||
|
if (_Sentido_SP == Horario && _Angulo >= AnguloComparar) {
|
||||||
|
_MotorLigado = false;
|
||||||
|
}
|
||||||
|
else if (_Sentido_SP == Antihorario && _Angulo <= (AnguloComparar * -1)) {
|
||||||
|
_MotorLigado = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (ModoSP) {
|
||||||
if (_Estabilizar && _Sentido_SP == Parado && _Angulo != _Angulo_SP) {
|
if (millis() - previousMillisCorrecao >= 1500) {
|
||||||
_Sentido_SP = _Angulo > _Angulo_SP ? Antihorario : Horario;
|
previousMillisCorrecao = millis();
|
||||||
_MotorLigado = true;
|
|
||||||
|
bool NoRangeZero = (_Angulo >= -_Margem && _Angulo <= _Margem);
|
||||||
|
bool NoRangeSP = (_Angulo >= (_Angulo_SP - _Margem) && _Angulo <= (_Angulo_SP + _Margem));
|
||||||
|
if (_Angulo_SP == 0 && !NoRangeZero && _Estabilizar) {
|
||||||
|
_Sentido_SP = _Angulo > 0 ? Antihorario : Horario;
|
||||||
|
_MotorLigado = true;
|
||||||
|
}
|
||||||
|
else if (!NoRangeSP) {
|
||||||
|
_MotorLigado = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -255,6 +293,8 @@ class Motor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Motor M1("ET");
|
Motor M1("ET");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue