Académique Documents
Professionnel Documents
Culture Documents
Avionic78
version : Test72_SPORT_3108
Branchements :
Arduino pin | Rx
4 (via 4.7K) | S_PORT
6 (via filtre) | PWM
Vcc | Vcc
GND | GND
Si NiMH avec 4 éléments, alimenter l'Arduino par la broche Vcc plutôt que par la broche RAW (diminue la c
Arduino pin | R1 (2 M)
A0 | R1 (one of the two pins) to be connected to Wire_1
A1 | R1 (the other pin)
Page 1
Feuille1
A1 broche de charge du condensateur
Seules les broches A0 et A1 sont utilisées
*/
FrSkySportSensorFcs fcs; // Create FCS-40A sensor with default ID (use ID8 for FCS-150A)
FrSkySportTelemetry telemetry;
MPU6050 accelgyro;
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
void setup()
{
Serial.begin(115200);
Page 2
Feuille1
initialize_DMP();
initialize_capa();
//calibration();
//printData_calibration(); // offset et capacité parasite de calibration à indiquer dans config.h
initialize_sport();
}
void loop()
{
//t_initial = millis();
//capa_value(); // pour debug
angle_value();
test_angle();
sport_output();
//pwm_output();
//printData_capa(); // pour debug
//printData_DMP(); // pour debug
//delay(10); // pour debug (mettre à 500 pour mesure de capacités sinon 10 maxi pour mesure d'angles)
//t_final = millis();
//time_loop();
}
void initialize_DMP()
{
Wire.begin(); //I2C bus
while (!Serial) {;}// wait for serial port to connect. Needed for native USB (LEONARDO)
// initialize device
accelgyro.initialize();
}
void initialize_capa()
{
TCCR1A = 0; // Timer 1 en mode compteur
TCCR1B = 1; // prédiviseur du timer 1 à 1
pinMode(A1, OUTPUT);
}
void calibration()
{
float offset;
offset = mesure(65536L);
offset /= 16;
capa_fil = offset / (float) R1 * K;
}
void initialize_sport()
{
// Configure the telemetry serial port and sensors (remember to use & to specify a pointer to sensor)
telemetry.begin(FrSkySportSingleWireSerial::SOFT_SERIAL_PIN_4, &fcs); // sortie SPORT sur la pin 4
}
void angle_value()
{
Page 3
Feuille1
static float angleX = 0.;
static float angleY = 0.;
static float currentTime = 0.;
float previousTime = 0.;
float elapsedTime = 0.;
const float elapsed_time = 5000.;
const float conv_rad_deg = 180./PI;
previousTime = currentTime;
currentTime = millis();
elapsedTime = (currentTime - previousTime)/1000.;
void capa_value()
{
const float elapsed_time = 5000.;
const float tension_ini = 3.3;
const float coef = tension_max / capa_max;
const unsigned imax = 2048;
const unsigned jmax = 4; // on séquence le calcul pour les contraintes de temps réel de la boucle principale
const int kmax = imax/jmax;
static int k = 1;
static long cumul = 0;
static float tension_pic = 0.; // tension avec le niveau de carburant en phase d'initialisation qui ne peut qu
long tt = mesure(jmax);
if (k < kmax)
{
cumul += tt;
k++;
}
else
{
tt = cumul;
tt <<= 1; // décalage à gauche de 1 pour imax = 2048, ce qui revient à multiplier par 2
capa = tt / (float) R1 * K - capa_fil;
cumul = 0;
k = 0;
Page 4
Feuille1
}
if (tension_pic < 0)
{
tension_pic = 0.;
}
if (tension_pic > tension_max)
{
tension_pic = tension_max;
}
}
else
{
//tension_sortie = capa * coef; // tension de sortie pour debug
tension_sortie = tension_max * (capa - capa_min) / (capa_max - capa_min); // tension de sor
if (tension_sortie < 0)
{
tension_sortie = 0.;
}
pinMode(A0, OUTPUT);
delayMicroseconds(100); // décharge le condensateur
for (long j = 0; j < jmax; j++) // on répète la mesure afin d'améliorer la précision
{
Page 5
Feuille1
pinMode(A0, INPUT);
byte oldSREG = SREG;
cli();
bitSet(PORTC, 1); // broche A1 HIGH
TCNT1 = 0;
asm volatile( "rjmp boucle\
n
);
t = TCNT1;
SREG = oldSREG;
digitalWrite(A1, LOW); // décharge le condensateur
pinMode(A0, OUTPUT);
tt += t / 3;
}
pinMode(A0, INPUT);
return tt;
}
void test_angle()
{
attitude = 0;
const float angleMax = 30.;
Page 6
Feuille1
void sport_output()
{
fcs.setData(attitude,tension_sortie); // Tension de sortie
telemetry.send(); // Send the telemetry data, note that the data will only be sent for sensors that are being p
}
void pwm_output()
{
float tension_alim = 5.;
byte duty_cycle = 0;
void printData_calibration()
{
void printData_capa()
{
Serial.print(F("Attitude = "));
Serial.print(attitude);
Serial.println();
Page 7
Feuille1
void printData_DMP()
{
Serial.print(F("Angles (deg) : "));
Serial.print(F("angleInitialX = "));
Serial.print(angleInitialX);
Serial.print(F(", "));
Serial.print(F("angleInitialY = "));
Serial.print(angleInitialY);
Serial.println();
Serial.print(F("angleResultX = "));
Serial.print(angleResultX);
Serial.print(F(", "));
Serial.print(F("angleResultY = "));
Serial.println(angleResultY);
Serial.println();
}
Page 8
Feuille1
à l'entrée A2 du récepteur
vion et mesurer le niveau du carburant dans la plage d'inclinaisons autorisées
ement des données du S_PORT (timing critique)
ons : calibration, PWM, S_PORT et debug : affichage, delay, mesure non séquencée de la capacité, temps de boucle
.wordpress.com/ pour visualiser le niveau de carburant testé sur une Taranis X9D Plus
&hilit=openxsensor#p145190
t-telemetry-library-easy-to-use-and-configurable
Page 9
Feuille1
Page 10
Feuille1
LEONARDO)
Page 11
Feuille1
temps réel de la boucle principale (mettre à 2048 pour debug capacité sinon 4)
Page 12
Feuille1
Page 13
Feuille1
Page 14
Feuille1
emps de boucle
Page 15