Initial commit
This commit is contained in:
978
src/main.cpp
Normal file
978
src/main.cpp
Normal file
@@ -0,0 +1,978 @@
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
/*
|
||||
* This code is an archive of the original code running on the V1 wiring harness
|
||||
* for the Murphy prototype.
|
||||
*
|
||||
* This code is unmaintained and is only to be used as a reference to understand
|
||||
* undocumented wiring and functioning of the V1 wiring harness.
|
||||
*/
|
||||
|
||||
// Importation des bibliothèques
|
||||
// ****************************************************************************
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <LoRa.h>
|
||||
#include <SPI.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include <TinyGPS.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
#include <max6675.h>
|
||||
|
||||
// Déclaration des variables
|
||||
// ********************************************************************************
|
||||
// Ecran LCD
|
||||
#define rs 31
|
||||
#define e 33
|
||||
#define d4 27
|
||||
#define d5 25
|
||||
#define d6 23
|
||||
#define d7 29
|
||||
// Thermocouple
|
||||
#define MAX6675_CS A1
|
||||
#define MAX6675_SO A0
|
||||
#define MAX6675_SCK A2
|
||||
MAX6675 thermocouple(MAX6675_SCK, MAX6675_CS, MAX6675_SO);
|
||||
// LoRa
|
||||
#define DIO0 2
|
||||
#define rst 36
|
||||
#define NSS 53
|
||||
// Autre
|
||||
#define capt_roue A4 // 21
|
||||
#define inter_test 10
|
||||
#define injection 37
|
||||
#define Relais_LED A10
|
||||
#define frein_av A5
|
||||
#define frein_ar A6
|
||||
|
||||
float vout = 0.0;
|
||||
float Tbat = 0.0;
|
||||
float Tcarte = 0.0;
|
||||
float R1 = 30000.0;
|
||||
float R2 = 7500.0;
|
||||
float R3 = 100.0;
|
||||
float R4 = 220.0;
|
||||
int valeur = 0;
|
||||
unsigned long tps = 0;
|
||||
unsigned long T;
|
||||
unsigned long tThermo = 0;
|
||||
unsigned long tTour = 0;
|
||||
unsigned long mTour = 0;
|
||||
unsigned long sTour = 0;
|
||||
unsigned long msTour = 0;
|
||||
unsigned long mTourFait = 0;
|
||||
unsigned long sTourFait = 0;
|
||||
unsigned long msTourFait = 0;
|
||||
unsigned long tMoy = 0;
|
||||
unsigned long tgps = 0;
|
||||
unsigned long IndMoy = 0;
|
||||
unsigned long TempsDepart = 0;
|
||||
#define p 10
|
||||
long P_of_10[p] = {1, 10, 100, 1000, 10000,
|
||||
100000, 1000000, 10000000, 100000000, 1000000000};
|
||||
float f;
|
||||
float Vi;
|
||||
float Vmoy = 0.0;
|
||||
float perimetre_roue = 1.62;
|
||||
float Tmot;
|
||||
float distance = 0.0;
|
||||
float DistanceTot = 0.0;
|
||||
float DistTourFait = 0.0;
|
||||
int Nb_tour_roue = 0;
|
||||
uint16_t va;
|
||||
long longitudeTest; // degré décimaux 10^-5
|
||||
long latitudeTest; // degré décimaux 10^-5
|
||||
long latitude = 999999; // degré décimaux 10^-5
|
||||
long longitude = 999999; // degré décimaux 10^-5
|
||||
long vieux_latitude = 999999; // degré décimaux 10^-5
|
||||
long vieux_longitude = 999999; // degré décimaux 10^-5
|
||||
int nbr_tour = 1;
|
||||
int Nb_boucle = 0;
|
||||
bool cercle = false;
|
||||
int injec;
|
||||
bool demarage = false;
|
||||
int choix = 4; // Le choix se fait entre 0-ParkingPolytechLigneDroite,
|
||||
// 1-ParkingPolytechBoucle, 2-CircuitMer, 3-Maison, 4-Circuit
|
||||
// Paul Armagnac de Nogaro, 5-DunoisKart.
|
||||
bool lora = true;
|
||||
|
||||
// Caractéristiques des différentes pistes
|
||||
|
||||
// ParkingPolytechLigneDroite
|
||||
float LatParkingPolytechLigneDepartdebut = 47844095.0; // degré décimaux 10^-5
|
||||
float LongParkingPolytechLigneDepartdebut = 1937724.0; // degré décimaux 10^-5
|
||||
float LatParkingPolytechLigneDepartfin = 47844064.0; // degré décimaux 10^-5
|
||||
float LongParkingPolytechLigneDepartfin = 1937810.0; // degré décimaux 10^-5
|
||||
long LatParkingPolytechLigneDepartmilieu =
|
||||
(LatParkingPolytechLigneDepartdebut + LatParkingPolytechLigneDepartfin) / 2;
|
||||
long LongParkingPolytechLigneDepartmilieu =
|
||||
(LongParkingPolytechLigneDepartdebut + LongParkingPolytechLigneDepartfin) /
|
||||
2;
|
||||
long LongeurLigneDepartParkingPolytechDeg = sqrt(
|
||||
pow((LatParkingPolytechLigneDepartdebut - LatParkingPolytechLigneDepartfin),
|
||||
2) +
|
||||
pow((LongParkingPolytechLigneDepartdebut -
|
||||
LongParkingPolytechLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartParkingPolytechMetre = 11; // distance en metre
|
||||
|
||||
// ParkingPolytechBoucle
|
||||
float LatParkingPolytechBoucleLigneDepartdebut =
|
||||
47844287.0; // degré décimaux 10^-5
|
||||
float LongParkingPolytechBoucleLigneDepartdebut =
|
||||
1938343.0; // degré décimaux 10^-5
|
||||
float LatParkingPolytechBoucleLigneDepartfin =
|
||||
47844345.0; // degré décimaux 10^-5
|
||||
float LongParkingPolytechBoucleLigneDepartfin =
|
||||
1938382.0; // degré décimaux 10^-5
|
||||
long LatParkingPolytechBoucleLigneDepartmilieu =
|
||||
(LatParkingPolytechBoucleLigneDepartdebut +
|
||||
LatParkingPolytechBoucleLigneDepartfin) /
|
||||
2;
|
||||
long LongParkingPolytechBoucleLigneDepartmilieu =
|
||||
(LongParkingPolytechBoucleLigneDepartdebut +
|
||||
LongParkingPolytechBoucleLigneDepartfin) /
|
||||
2;
|
||||
long LongeurLigneDepartParkingPolytechBoucleDeg =
|
||||
sqrt(pow((LatParkingPolytechBoucleLigneDepartdebut -
|
||||
LatParkingPolytechBoucleLigneDepartfin),
|
||||
2) +
|
||||
pow((LongParkingPolytechBoucleLigneDepartdebut -
|
||||
LongParkingPolytechBoucleLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartParkingPolytechBoucleMetre = 6; // distance en metre
|
||||
|
||||
// Circuit de Mer (CapKarting)
|
||||
float LatCircuitMerLigneDepartdebut = 47728053.0; // degré décimaux 10^-5
|
||||
float LongCircuitMerLigneDepartdebut = 1488901.0; // degré décimaux 10^-5
|
||||
float LatCircuitMerLigneDepartfin = 47728097.0; // degré décimaux 10^-5
|
||||
float LongCircuitMerLigneDepartfin = 1489006.0; // degré décimaux 10^-5
|
||||
long LatCircuitMerLigneDepartmilieu =
|
||||
(LatCircuitMerLigneDepartdebut + LatCircuitMerLigneDepartfin) / 2;
|
||||
long LongCircuitMerLigneDepartmilieu =
|
||||
(LongCircuitMerLigneDepartdebut + LongCircuitMerLigneDepartfin) / 2;
|
||||
long LongeurLigneDepartCircuitMerDeg =
|
||||
sqrt(pow((LatCircuitMerLigneDepartdebut - LatCircuitMerLigneDepartfin), 2) +
|
||||
pow((LongCircuitMerLigneDepartdebut - LongCircuitMerLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartCircuitMerMetre = 10; // distance en metre
|
||||
|
||||
// Circuit de Maison (test)
|
||||
float LatCircuitMaisonLigneDepartdebut = 47938637.0; // degré décimaux 10^-5
|
||||
float LongCircuitMaisonLigneDepartdebut = 1811129.0; // degré décimaux 10^-5
|
||||
float LatCircuitMaisonLigneDepartfin = 47938680.0; // degré décimaux 10^-5
|
||||
float LongCircuitMaisonLigneDepartfin = 1811203.0; // degré décimaux 10^-5
|
||||
long LatCircuitMaisonLigneDepartmilieu =
|
||||
(LatCircuitMaisonLigneDepartdebut + LatCircuitMaisonLigneDepartfin) / 2;
|
||||
long LongCircuitMaisonLigneDepartmilieu =
|
||||
(LongCircuitMaisonLigneDepartdebut + LongCircuitMaisonLigneDepartfin) / 2;
|
||||
long LongeurLigneDepartCircuitMaisonDeg = sqrt(
|
||||
pow((LatCircuitMaisonLigneDepartdebut - LatCircuitMaisonLigneDepartfin),
|
||||
2) +
|
||||
pow((LongCircuitMaisonLigneDepartdebut - LongCircuitMaisonLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartCircuitMaisonMetre = 7; // distance en metre
|
||||
|
||||
// Circuit de Paul Armagnac (Nogaro)
|
||||
float LatCircuitNogaroLigneDepartdebut = 43770616.0;
|
||||
float LongCircuitNogaroLigneDepartdebut = -40627.0; // attention nombre négatif
|
||||
float LatCircuitNogaroLigneDepartfin = 43770691.0;
|
||||
float LongCircuitNogaroLigneDepartfin = -40463.0; // attention nombre négatif
|
||||
long LatCircuitNogaroLigneDepartmilieu =
|
||||
(LatCircuitNogaroLigneDepartdebut + LatCircuitNogaroLigneDepartfin) / 2;
|
||||
long LongCircuitNogaroLigneDepartmilieu =
|
||||
(LongCircuitNogaroLigneDepartdebut + LongCircuitNogaroLigneDepartfin) / 2;
|
||||
long LongeurLigneDepartCircuitNogaroDeg = sqrt(
|
||||
pow((LatCircuitNogaroLigneDepartdebut - LatCircuitNogaroLigneDepartfin),
|
||||
2) +
|
||||
pow((LongCircuitNogaroLigneDepartdebut - LongCircuitNogaroLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartCircuitNogaroMetre = 15; // distance en metre
|
||||
|
||||
// Circuit de karting Dunois (Dunois Kart)
|
||||
float LatCircuitDunoisKartLigneDepartdebut = 48052815.0;
|
||||
float LongCircuitDunoisKartLigneDepartdebut =
|
||||
1427610.0; // attention nombre négatif
|
||||
float LatCircuitDunoisKartLigneDepartfin = 48052898.0;
|
||||
float LongCircuitDunoisKartLigneDepartfin =
|
||||
1427644.0; // attention nombre négatif
|
||||
long LatCircuitDunoisKartLigneDepartmilieu =
|
||||
(LatCircuitDunoisKartLigneDepartdebut +
|
||||
LatCircuitDunoisKartLigneDepartfin) /
|
||||
2;
|
||||
long LongCircuitDunoisKartLigneDepartmilieu =
|
||||
(LongCircuitDunoisKartLigneDepartdebut +
|
||||
LongCircuitDunoisKartLigneDepartfin) /
|
||||
2;
|
||||
long LongeurLigneDepartCircuitDunoisKartDeg =
|
||||
sqrt(pow((LatCircuitDunoisKartLigneDepartdebut -
|
||||
LatCircuitDunoisKartLigneDepartfin),
|
||||
2) +
|
||||
pow((LongCircuitDunoisKartLigneDepartdebut -
|
||||
LongCircuitDunoisKartLigneDepartfin),
|
||||
2)); // distance en degré 10^-5
|
||||
long LongeurLigneDepartCircuitDunoisKartMetre = 10; // distance en metre
|
||||
|
||||
// Piste Choisie
|
||||
float LatLigneDepartdebut[] = {
|
||||
LatParkingPolytechLigneDepartdebut,
|
||||
LatParkingPolytechBoucleLigneDepartdebut,
|
||||
LatCircuitMerLigneDepartdebut,
|
||||
LatCircuitMaisonLigneDepartdebut,
|
||||
LatCircuitNogaroLigneDepartdebut,
|
||||
LatCircuitDunoisKartLigneDepartdebut}; // degré décimaux 10^-5
|
||||
float LongLigneDepartdebut[] = {
|
||||
LongParkingPolytechLigneDepartdebut,
|
||||
LongParkingPolytechBoucleLigneDepartdebut,
|
||||
LongCircuitMerLigneDepartdebut,
|
||||
LongCircuitMaisonLigneDepartdebut,
|
||||
LongCircuitNogaroLigneDepartdebut,
|
||||
LongCircuitDunoisKartLigneDepartdebut}; // degré décimaux 10^-5
|
||||
float LatLigneDepartfin[] = {
|
||||
LatParkingPolytechLigneDepartfin,
|
||||
LatParkingPolytechBoucleLigneDepartfin,
|
||||
LatCircuitMerLigneDepartfin,
|
||||
LatCircuitMaisonLigneDepartfin,
|
||||
LatCircuitNogaroLigneDepartfin,
|
||||
LatCircuitDunoisKartLigneDepartfin}; // degré décimaux 10^-5
|
||||
float LongLigneDepartfin[] = {
|
||||
LongParkingPolytechLigneDepartfin,
|
||||
LongParkingPolytechBoucleLigneDepartfin,
|
||||
LongCircuitMerLigneDepartfin,
|
||||
LongCircuitMaisonLigneDepartfin,
|
||||
LongCircuitNogaroLigneDepartfin,
|
||||
LongCircuitDunoisKartLigneDepartfin}; // degré décimaux 10^-5
|
||||
float AngleLigneDepartDeg =
|
||||
atan(2 * (LatLigneDepartfin[choix] - LatLigneDepartdebut[choix]) /
|
||||
(LongLigneDepartfin[choix] - LongLigneDepartdebut[choix])) *
|
||||
360 / (2 * 3.14159);
|
||||
long LatLigneDepartmilieu[] = {LatParkingPolytechLigneDepartmilieu,
|
||||
LatParkingPolytechBoucleLigneDepartmilieu,
|
||||
LatCircuitMerLigneDepartmilieu,
|
||||
LatCircuitMaisonLigneDepartmilieu,
|
||||
LatCircuitNogaroLigneDepartmilieu,
|
||||
LatCircuitDunoisKartLigneDepartmilieu};
|
||||
long LongLigneDepartmilieu[] = {LongParkingPolytechLigneDepartmilieu,
|
||||
LongParkingPolytechBoucleLigneDepartmilieu,
|
||||
LongCircuitMerLigneDepartmilieu,
|
||||
LongCircuitMaisonLigneDepartmilieu,
|
||||
LongCircuitNogaroLigneDepartmilieu,
|
||||
LongCircuitDunoisKartLigneDepartmilieu};
|
||||
long LongeurLigneDepartDeg[] = {LongeurLigneDepartParkingPolytechDeg,
|
||||
LongeurLigneDepartParkingPolytechBoucleDeg,
|
||||
LongeurLigneDepartCircuitMerDeg,
|
||||
LongeurLigneDepartCircuitMaisonDeg,
|
||||
LongeurLigneDepartCircuitNogaroDeg,
|
||||
LongeurLigneDepartCircuitDunoisKartDeg};
|
||||
long LongeurLigneDepartMetre[] = {LongeurLigneDepartParkingPolytechMetre,
|
||||
LongeurLigneDepartParkingPolytechBoucleMetre,
|
||||
LongeurLigneDepartCircuitMerMetre,
|
||||
LongeurLigneDepartCircuitMaisonMetre,
|
||||
LongeurLigneDepartCircuitNogaroMetre,
|
||||
LongeurLigneDepartCircuitDunoisKartMetre};
|
||||
int signe[] = {1, 1, 1, 1, 1, 1};
|
||||
|
||||
long DistanceProto_LdD;
|
||||
float AngleProtoDeg;
|
||||
long AncienneDistanceProto_LdD;
|
||||
float AncienAngleProtoDegDeg;
|
||||
bool passage = false;
|
||||
|
||||
const int taille_message_test = 6;
|
||||
int message_test[taille_message_test] = {
|
||||
0, 0, 0, 0,
|
||||
0, 0}; // #vitesse,vitesse moyenne,tension batterie,tension
|
||||
// carte,température moteur,accélération$
|
||||
const int taille_message_piste = 15;
|
||||
long message_piste[taille_message_piste] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0}; // #latitude,latitude,latitude,longitude,longitude,longitude,vitesse,vitesse
|
||||
// moyenne,tension batterie,tension carte,température
|
||||
// moteur,nombre de tour,accélération,frein
|
||||
// avant,frein arrière$
|
||||
|
||||
String NomCircuit[] = {"Parking Polytech", "Polytech Boucle",
|
||||
"Cap Karting", "Maison",
|
||||
"Nogaro Paul Armagnac", "Dunois Kart"};
|
||||
char temp;
|
||||
#define bt_lenmax 150
|
||||
int bt_ind;
|
||||
int bt_v;
|
||||
int bt_rxok;
|
||||
|
||||
// Variable de défaut
|
||||
int k = 0;
|
||||
int Tk = 0;
|
||||
int Tkmot = 0;
|
||||
bool InitGPSFailed = false;
|
||||
bool PerteGPSAff = false;
|
||||
bool PerteGPS = false;
|
||||
bool GPSRetrouveAff = false;
|
||||
int Perte = 0;
|
||||
bool TFaibleAff = false;
|
||||
bool TmotAff = false;
|
||||
float TlimitLow = 12.3;
|
||||
int TmotlimitLow = 65;
|
||||
int TmotlimitHigh = 95;
|
||||
|
||||
// Déclaration des
|
||||
// objets************************************************************************************
|
||||
LiquidCrystal_I2C lcd(0x27, 20, 4);
|
||||
LiquidCrystal_I2C *_display = new LiquidCrystal_I2C(0x27, 20, 4);
|
||||
TinyGPS gps;
|
||||
|
||||
// Déclaration des sous programmes
|
||||
// **************************************************************************
|
||||
|
||||
void LCD() {
|
||||
if (Nb_boucle > 50) {
|
||||
lcd.clear();
|
||||
Nb_boucle = 0;
|
||||
}
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Vi=");
|
||||
lcd.setCursor(3, 0);
|
||||
if (Vi < 10) {
|
||||
lcd.print("0");
|
||||
lcd.setCursor(4, 0);
|
||||
}
|
||||
lcd.print(Vi);
|
||||
lcd.setCursor(10, 0);
|
||||
lcd.print("Vmoy=");
|
||||
lcd.setCursor(15, 0);
|
||||
if (Vmoy < 10) {
|
||||
lcd.print("0");
|
||||
lcd.setCursor(16, 0);
|
||||
}
|
||||
lcd.print(Vmoy);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Tmot=");
|
||||
lcd.setCursor(5, 1);
|
||||
lcd.print(Tmot);
|
||||
if (Tmot < TmotlimitLow && TmotAff == true) {
|
||||
TmotAff = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! DEFAUT !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!! Tempe. moteur !!");
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print(" !!! Faible !!! ");
|
||||
delay(2500);
|
||||
lcd.clear();
|
||||
}
|
||||
if (Tmot > TmotlimitHigh && TmotAff == true) {
|
||||
TmotAff = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! DEFAUT !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!! Tempe. moteur !!");
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print(" !!! Haute !!! ");
|
||||
delay(2500);
|
||||
lcd.clear();
|
||||
}
|
||||
lcd.setCursor(15, 1);
|
||||
lcd.print("GPS:");
|
||||
lcd.setCursor(19, 1);
|
||||
if (InitGPSFailed == true) {
|
||||
if (latitude == longitude) {
|
||||
lcd.print("X");
|
||||
} else {
|
||||
InitGPSFailed = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Initialisation Proto");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. GPS: Ok!");
|
||||
Serial.println("Init. GPS: Ok!");
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
}
|
||||
} else {
|
||||
if (PerteGPSAff) {
|
||||
PerteGPSAff = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! DEFAUT !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!!! GPS Perdu !!!");
|
||||
Serial.println("!!! GPS Perdu !!!");
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
}
|
||||
if (GPSRetrouveAff) {
|
||||
GPSRetrouveAff = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! DEFAUT !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!!! GPS OK !!!");
|
||||
Serial.println("!!! GPS OK !!!");
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
}
|
||||
if (PerteGPS) {
|
||||
lcd.print("X");
|
||||
} else {
|
||||
lcd.print("V");
|
||||
}
|
||||
}
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Tour=00");
|
||||
lcd.setCursor(5, 2);
|
||||
if (nbr_tour < 10) {
|
||||
lcd.setCursor(6, 2);
|
||||
}
|
||||
lcd.print(nbr_tour);
|
||||
if (passage) {
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! INFO !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!! Tour Effectue !!");
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("t/Tour=0m00s0");
|
||||
lcd.setCursor(7, 2);
|
||||
lcd.print(mTourFait);
|
||||
lcd.setCursor(9, 2);
|
||||
if (sTour < 10) {
|
||||
lcd.setCursor(10, 2);
|
||||
}
|
||||
lcd.print(sTourFait);
|
||||
lcd.setCursor(12, 2);
|
||||
lcd.print(msTourFait);
|
||||
lcd.setCursor(0, 3);
|
||||
lcd.print("Dist=");
|
||||
lcd.setCursor(5, 3);
|
||||
lcd.print(Nb_tour_roue); // DistTourFait);
|
||||
delay(4500);
|
||||
lcd.clear();
|
||||
}
|
||||
lcd.setCursor(9, 2);
|
||||
lcd.print("Tbat=00.00V");
|
||||
if (Tbat < 10) {
|
||||
lcd.setCursor(15, 2);
|
||||
lcd.print(Tbat);
|
||||
}
|
||||
if (Tbat >= 10) {
|
||||
lcd.setCursor(14, 2);
|
||||
lcd.print(Tbat);
|
||||
}
|
||||
if (Tbat < TlimitLow && TFaibleAff == true) {
|
||||
TFaibleAff = false;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" !!! DEFAUT !!!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("!! Tension Faible !!");
|
||||
delay(2500);
|
||||
lcd.clear();
|
||||
}
|
||||
lcd.setCursor(0, 3);
|
||||
lcd.print("t/Tour=0m00s0");
|
||||
if (demarage == true) {
|
||||
mTour = (millis() - tTour) / 60000;
|
||||
sTour = ((millis() - tTour) / 1000) % 60;
|
||||
msTour = (millis() - tTour) % 1000 / 100;
|
||||
lcd.setCursor(7, 3);
|
||||
lcd.print(mTour);
|
||||
lcd.setCursor(9, 3);
|
||||
if (sTour < 10) {
|
||||
lcd.setCursor(10, 3);
|
||||
}
|
||||
lcd.print(sTour);
|
||||
lcd.setCursor(12, 3);
|
||||
lcd.print(msTour);
|
||||
}
|
||||
lcd.setCursor(17, 3);
|
||||
lcd.print("L=");
|
||||
lcd.setCursor(19, 3);
|
||||
lcd.print(lora);
|
||||
}
|
||||
|
||||
void tension_batterie() {
|
||||
valeur = analogRead(A3);
|
||||
vout = (valeur * 5.0) / 1023.0; // see text
|
||||
Tbat = (vout * (10000.0 + 33000.0)) / 10000.0;
|
||||
if (Tbat < TlimitLow) {
|
||||
Tk++;
|
||||
}
|
||||
if (Tk > 99) {
|
||||
Tk = 0;
|
||||
TFaibleAff = true;
|
||||
} else {
|
||||
TFaibleAff = false;
|
||||
}
|
||||
|
||||
// Serial.print("valeur =");
|
||||
// Serial.print(valeur);
|
||||
// Serial.print(" vout =");
|
||||
// Serial.print(vout);
|
||||
// Serial.print(" Tbat =");
|
||||
// Serial.println(Tbat);
|
||||
}
|
||||
|
||||
void tension_carte() {
|
||||
valeur = analogRead(A4);
|
||||
vout = (valeur * 5.0) / 1023.0; // see text
|
||||
Tcarte = vout / (10000.0 / (10000.0 + 27000.0));
|
||||
// Serial.print(" valeur =");
|
||||
// Serial.print(valeur);
|
||||
// Serial.print(" vout =");
|
||||
// Serial.print(vout);
|
||||
// Serial.print(" Tcarte =");
|
||||
// Serial.println(Tcarte);
|
||||
}
|
||||
|
||||
void vitesse() {
|
||||
if (micros() - tps > 50000) {
|
||||
T = micros() - tps;
|
||||
tps = micros();
|
||||
f = 1000000.0 / T;
|
||||
|
||||
Vi = f * perimetre_roue * 3.6;
|
||||
if (Vi > 45) {
|
||||
Vi = 45;
|
||||
}
|
||||
Serial.print(f);
|
||||
Serial.print(", ");
|
||||
Serial.println(Vi);
|
||||
distance = distance + perimetre_roue;
|
||||
DistanceTot = DistanceTot + perimetre_roue;
|
||||
Nb_tour_roue++;
|
||||
}
|
||||
}
|
||||
|
||||
void tempmot() {
|
||||
if (micros() - tThermo >= 2000000) {
|
||||
float TmotThermo;
|
||||
TmotThermo = thermocouple.readCelsius() - 2; //-12;
|
||||
Tmot = TmotThermo; //*0.7995759526+17.1336552466;
|
||||
tThermo = micros();
|
||||
if (Tmot < TmotlimitLow || Tmot > TmotlimitHigh) {
|
||||
if (Tkmot == 0) {
|
||||
TmotAff = true;
|
||||
} else {
|
||||
TmotAff = false;
|
||||
}
|
||||
Tkmot++;
|
||||
}
|
||||
if (Tkmot > 49) {
|
||||
Tkmot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void message() {
|
||||
int Distance = distance * 100;
|
||||
if (digitalRead(inter_test)) // envoi de la trame par liaison Série
|
||||
{ // #vitesse,vitesse moyenne,tension batterie,tension carte,température
|
||||
// moteur,accélération$
|
||||
message_test[0] = Vi * 100;
|
||||
message_test[1] = Vmoy * 100;
|
||||
message_test[2] = Tbat * 100;
|
||||
message_test[3] = Tcarte * 100;
|
||||
message_test[4] = Tmot * 100;
|
||||
message_test[5] = Nb_tour_roue / 1000;
|
||||
message_test[6] = Nb_tour_roue - message_test[5] * 1000;
|
||||
// message_test[7]=int(Distance-message_test[5]*1000000-message_test[6]*1000);
|
||||
Serial1.print('#');
|
||||
Serial1.print(message_test[0]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[1]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[2]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[3]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[4]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[5]);
|
||||
Serial1.print(",");
|
||||
Serial1.print(message_test[6]);
|
||||
Serial1.print(
|
||||
","); // Serial1.print(message_test[7]);Serial1.print(",");//Serial1.print(message_test[5]);Serial1.print(",");
|
||||
Serial1.println('$');
|
||||
Serial.print('#');
|
||||
Serial.print(message_test[0]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[1]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[2]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[3]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[4]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[5]);
|
||||
Serial.print(",");
|
||||
Serial.print(message_test[6]);
|
||||
Serial.print(
|
||||
","); // Serial.print(message_test[7]);Serial.print(",");//Serial.print(message_test[5]);Serial.print(",");
|
||||
Serial.println('$');
|
||||
// Serial.println("message test envoyé");
|
||||
}
|
||||
if (!digitalRead(inter_test) &&
|
||||
lora) // envoi de la trame par onde radio via le Lora
|
||||
{ // #latitude,latitude,latitude,longitude,longitude,longitude,vitesse,vitesse
|
||||
// moyenne,tension batterie,tension carte,température moteur,nombre de
|
||||
// tour,accélération,frein avant,frein arrière$
|
||||
message_piste[0] = latitude / 1000000;
|
||||
message_piste[1] = (latitude - message_piste[0] * 1000000) / 1000;
|
||||
message_piste[2] =
|
||||
latitude - message_piste[0] * 1000000 - message_piste[1] * 1000;
|
||||
message_piste[3] = longitude / 1000000;
|
||||
message_piste[4] = (longitude - message_piste[3] * 1000000) / 1000;
|
||||
message_piste[5] =
|
||||
longitude - message_piste[3] * 1000000 - message_piste[4] * 1000;
|
||||
message_piste[6] = Vi * 100;
|
||||
message_piste[7] = Vmoy * 100;
|
||||
message_piste[8] = Tbat * 100;
|
||||
message_piste[9] = Tcarte * 100;
|
||||
message_piste[10] = Tmot * 100;
|
||||
message_piste[10] = nbr_tour;
|
||||
message_piste[11] = injec;
|
||||
message_piste[12] = digitalRead(frein_av);
|
||||
message_piste[13] = digitalRead(frein_ar);
|
||||
LoRa.beginPacket();
|
||||
LoRa.print('#');
|
||||
LoRa.print(message_piste[0]);
|
||||
LoRa.print(message_piste[1]);
|
||||
LoRa.print(message_piste[2]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[3]);
|
||||
LoRa.print(message_piste[4]);
|
||||
LoRa.print(message_piste[5]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[6]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[7]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[8]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[9]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[10]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[11]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[12]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(message_piste[13]);
|
||||
LoRa.print(",");
|
||||
LoRa.print(mTour);
|
||||
LoRa.print(",");
|
||||
LoRa.print(sTour);
|
||||
LoRa.print(",");
|
||||
LoRa.print(msTour);
|
||||
LoRa.print(",");
|
||||
LoRa.print(int((distance / 1000)));
|
||||
LoRa.print(",");
|
||||
LoRa.print(int((distance) - (int(distance / 1000) * 1000)));
|
||||
LoRa.print(",");
|
||||
LoRa.print(int((distance * 1000) - (int(distance) * 1000)));
|
||||
LoRa.print(","); //;LoRa.print(message_piste[14]);LoRa.print(",")
|
||||
LoRa.print('$');
|
||||
LoRa.endPacket();
|
||||
// Serial.println(int((distance*100)/1000));
|
||||
// Serial.print('#');
|
||||
// Serial.print(message_piste[0]);Serial.print(message_piste[1]);Serial.print(message_piste[2]);Serial.print(",");Serial.print(message_piste[3]);Serial.print(message_piste[4]);Serial.print(message_piste[5]);Serial.print(",");Serial.print(message_piste[6]);Serial.print(",");Serial.print(message_piste[7]);Serial.print(",");Serial.print(message_piste[8]);Serial.print(",");Serial.print(message_piste[9]);Serial.print(",");Serial.print(message_piste[10]);Serial.print(",");Serial.print(message_piste[11]);Serial.print(",");Serial.print(message_piste[12]);Serial.print(",");Serial.print(message_piste[13]);Serial.print(",");Serial.print(mTour);Serial.print(",");Serial.print(sTour);Serial.print(",");Serial.print(msTour);Serial.print(",");Serial.print(int((distance/1000)));Serial.print(",");Serial.print(int((distance)-(int(distance/1000)*1000)));Serial.print(",");Serial.print(int((distance*1000)-(int(distance)*1000)));Serial.print(",");//;LoRa.print(message_piste[14]);LoRa.print(",")
|
||||
// Serial.println('$');
|
||||
}
|
||||
}
|
||||
void frein() {
|
||||
if (digitalRead(frein_av) || digitalRead(frein_ar)) {
|
||||
digitalWrite(Relais_LED, HIGH);
|
||||
}
|
||||
if (!digitalRead(frein_av) && !digitalRead(frein_ar)) {
|
||||
digitalWrite(Relais_LED, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void Injection() {
|
||||
if (digitalRead(injection)) {
|
||||
injec = 1;
|
||||
}
|
||||
if (!digitalRead(injection)) {
|
||||
injec = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Nbr_tour() {
|
||||
if ((sqrt(pow((LatLigneDepartmilieu[choix] - latitude), 2) +
|
||||
pow((LongLigneDepartmilieu[choix] - longitude), 2)) <=
|
||||
1.25 * LongeurLigneDepartDeg[choix] &&
|
||||
sqrt(pow((LatLigneDepartmilieu[choix] - vieux_latitude), 2) +
|
||||
pow((LongLigneDepartmilieu[choix] - vieux_longitude), 2)) <=
|
||||
1.25 * LongeurLigneDepartDeg[choix] &&
|
||||
passage == false)) //|| mTour>0)
|
||||
{
|
||||
AngleProtoDeg = atan(2 * (latitude - LatLigneDepartdebut[choix]) /
|
||||
(longitude - LongLigneDepartdebut[choix])) *
|
||||
360 / (2 * 3.14159);
|
||||
AncienAngleProtoDegDeg =
|
||||
atan(2 * (vieux_latitude - LatLigneDepartdebut[choix]) /
|
||||
(vieux_longitude - LongLigneDepartdebut[choix])) *
|
||||
360 / (2 * 3.14159);
|
||||
cercle = true;
|
||||
if ((signe[choix] * (AncienAngleProtoDegDeg - AngleLigneDepartDeg) <= 0 &&
|
||||
signe[choix] * (AngleProtoDeg - AngleLigneDepartDeg) >
|
||||
0)) //|| mTour>0)
|
||||
{
|
||||
nbr_tour++;
|
||||
passage = true;
|
||||
tTour = millis();
|
||||
mTourFait = mTour;
|
||||
sTourFait = sTour;
|
||||
msTourFait = msTour;
|
||||
DistTourFait = distance;
|
||||
mTour = 0;
|
||||
sTour = 0;
|
||||
msTour = 0;
|
||||
distance = 0;
|
||||
}
|
||||
}
|
||||
// if(sqrt(pow((LatLigneDepartmilieu[choix]-latitude),2)+pow((LongLigneDepartmilieu[choix]-longitude),2))>LongeurLigneDepartDeg[choix]
|
||||
// ||
|
||||
// sqrt(pow((LatLigneDepartmilieu[choix]-vieux_latitude),2)+pow((LongLigneDepartmilieu[choix]-vieux_longitude),2))>LongeurLigneDepartDeg[choix])
|
||||
else {
|
||||
cercle = false;
|
||||
passage = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Vmoyenne() {
|
||||
if (demarage == true) {
|
||||
// Vmoy=(Vmoy*(IndMoy)+Vi)/(IndMoy+1);
|
||||
// IndMoy++;
|
||||
Vmoy = (DistanceTot / (millis() - TempsDepart)) * 3.6;
|
||||
}
|
||||
}
|
||||
|
||||
void GPS() {
|
||||
unsigned long chars;
|
||||
unsigned short sentences, failed;
|
||||
bool newdata = false;
|
||||
// float lat;
|
||||
// float lon;
|
||||
latitudeTest = latitude;
|
||||
longitudeTest = longitude;
|
||||
while (Serial2.available()) {
|
||||
char c = Serial2.read();
|
||||
// Serial.write(c); // uncomment this line if you want to see the GPS data
|
||||
// flowing
|
||||
if (gps.encode(c)) {
|
||||
vieux_latitude = latitude;
|
||||
vieux_longitude = longitude;
|
||||
gps.get_position(&latitude, &longitude);
|
||||
if (vieux_latitude == latitude && vieux_longitude == longitude) {
|
||||
Perte++;
|
||||
if (Perte > 3) {
|
||||
if (PerteGPS) {
|
||||
PerteGPSAff = false;
|
||||
} else {
|
||||
PerteGPSAff = true;
|
||||
}
|
||||
PerteGPS = true;
|
||||
}
|
||||
} else {
|
||||
Perte = 0;
|
||||
if (PerteGPS) {
|
||||
GPSRetrouveAff = true;
|
||||
}
|
||||
PerteGPS = false;
|
||||
PerteGPSAff = false;
|
||||
}
|
||||
Serial.println(" Aqui GPS");
|
||||
// Serial.print(" lati=");
|
||||
// Serial.print(latitude);
|
||||
// Serial.print(" long=");
|
||||
// Serial.println(longitude);
|
||||
// Serial.print(" latiTest=");
|
||||
// Serial.print(latitudeTest);
|
||||
// Serial.print(" longTest=");
|
||||
// Serial.println(longitudeTest);
|
||||
}
|
||||
}
|
||||
// Serial.println(" ");
|
||||
// Serial.print(" lati=");
|
||||
// Serial.print(latitude);
|
||||
// Serial.print(" long=");
|
||||
// Serial.println(longitude);
|
||||
// Serial.print(" latiVieux=");
|
||||
// Serial.print(vieux_latitude);
|
||||
// Serial.print(" longVieux=");
|
||||
// Serial.println(vieux_longitude);
|
||||
// Serial.print(" Perte=");
|
||||
// Serial.println(Perte);
|
||||
|
||||
Vmoyenne();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//************************************************************************************
|
||||
//Initialisation Proto
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Initialisation Proto");
|
||||
delay(1000);
|
||||
//************************************************************************************
|
||||
//Initialisation des ports COM
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. Port COM ...");
|
||||
Serial.begin(9600);
|
||||
Serial1.begin(9600);
|
||||
Serial2.begin(9600);
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Init. Port COM: Ok!");
|
||||
delay(1000);
|
||||
tgps = millis();
|
||||
tTour = millis();
|
||||
pinMode(capt_roue, INPUT_PULLUP);
|
||||
pinMode(injection, INPUT);
|
||||
pinMode(Relais_LED, OUTPUT);
|
||||
pinMode(MAX6675_CS, OUTPUT);
|
||||
pinMode(MAX6675_SO, INPUT);
|
||||
pinMode(MAX6675_SCK, OUTPUT);
|
||||
attachInterrupt(1, vitesse, FALLING);
|
||||
//************************************************************************************
|
||||
//Initialisation LoRa
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Initialisation Proto");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. LoRa ...");
|
||||
delay(1000);
|
||||
LoRa.setPins(NSS, rst, DIO0); // NSS, NRESET, and DIO0 pins can be changed by
|
||||
// using LoRa.setPins(ss, reset, dio0).
|
||||
LoRa.begin(433E6);
|
||||
LoRa.setTxPower(20);
|
||||
if (!LoRa.begin(433E6)) // porteuse de 433MHz
|
||||
{
|
||||
Serial.println("Starting LoRa failed!");
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Init. LoRa failed!");
|
||||
delay(1000);
|
||||
lora = false;
|
||||
lcd.clear();
|
||||
} else {
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Init. LoRa: Ok!");
|
||||
delay(1000);
|
||||
}
|
||||
LoRa.setSpreadingFactor(7);
|
||||
// LoRa.setSignalBandwidth(41.7E3);
|
||||
// LoRa.crc();
|
||||
// Serial.println("LoRa Initializing OK!");
|
||||
//************************************************************************************
|
||||
//Initialisation GPS
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Initialisation Proto");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. GPS: .");
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Lat:");
|
||||
lcd.setCursor(6, 2);
|
||||
lcd.print(latitude);
|
||||
lcd.setCursor(0, 3);
|
||||
lcd.print("Long:");
|
||||
lcd.setCursor(6, 3);
|
||||
lcd.print(longitude);
|
||||
delay(500);
|
||||
|
||||
while (latitude == longitude && InitGPSFailed == false) {
|
||||
GPS();
|
||||
if (k == 3) {
|
||||
k = 0;
|
||||
}
|
||||
if (k == 0) {
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. GPS: .. ");
|
||||
} else if (k == 1) {
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. GPS: ...");
|
||||
} else if (k == 2) {
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Init. GPS: . ");
|
||||
}
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print("Lat:");
|
||||
lcd.setCursor(6, 2);
|
||||
lcd.print(latitude);
|
||||
lcd.setCursor(0, 3);
|
||||
lcd.print("Long:");
|
||||
lcd.setCursor(6, 3);
|
||||
lcd.print(longitude);
|
||||
lcd.setCursor(15, 3);
|
||||
lcd.print(millis() - tgps);
|
||||
delay(500);
|
||||
k++;
|
||||
if (millis() - tgps > 25000) {
|
||||
InitGPSFailed = true;
|
||||
}
|
||||
}
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Initialisation Proto");
|
||||
lcd.setCursor(0, 1);
|
||||
if (InitGPSFailed == true) {
|
||||
lcd.print("Init. GPS: Failed!");
|
||||
} else {
|
||||
lcd.print("Init. GPS: Ok!");
|
||||
}
|
||||
delay(1000);
|
||||
//************************************************************************************
|
||||
//Initialisation Piste
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Piste selectionnee :");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(NomCircuit[choix]);
|
||||
lcd.setCursor(0, 2);
|
||||
lcd.print(AngleLigneDepartDeg);
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
LCD();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (LoRa.begin(433E6)) {
|
||||
lora = true;
|
||||
}
|
||||
if (!LoRa.begin(433E6)) {
|
||||
lora = false;
|
||||
}
|
||||
if (digitalRead(injection) == 1 &&
|
||||
demarage == false) // Initialise le démarrage des chronos au premier appui
|
||||
// sur le bouton d'injection.
|
||||
{
|
||||
demarage = true;
|
||||
tTour = millis();
|
||||
tMoy = millis();
|
||||
TempsDepart = millis() / 1000;
|
||||
}
|
||||
if (micros() - tps > 4000000) {
|
||||
Vi = 0.0;
|
||||
}
|
||||
LCD();
|
||||
tension_batterie();
|
||||
tension_carte();
|
||||
tempmot();
|
||||
// frein();
|
||||
Injection();
|
||||
Nbr_tour();
|
||||
message();
|
||||
GPS();
|
||||
// Serial.print(" lati=");
|
||||
// Serial.print(latitude);
|
||||
// Serial.print(" long=");
|
||||
// Serial.println(longitude);
|
||||
// Serial.println(digitalRead(capt_roue));
|
||||
Nb_boucle++;
|
||||
}
|
||||
Reference in New Issue
Block a user