IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Homemade Quadcopter/C++ Code sans ARDUINO/MULTIWII


Sujet :

C++

  1. #1
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut Homemade Quadcopter/C++ Code sans ARDUINO/MULTIWII
    Bonjour

    Pour que vous compreniez le sujet et mon intervention, je fait un bref r�capitulatif de ma modeste exp�rience de l'�lectronique:

    J'ai donc d�but� l'�lectronique amateur il y a 1 an, au d�part je ne savais pas � quoi servait un condensateur, je suis donc parti de z�ro.
    J'ai �t� comme un peu tout les amateurs qui ne savent pas par ou commencer au d�part, j'ai t�l�charg� Arduino, puis au bout d'une semaine j'ai voulu savoir ce qu'il y avait derri�re digitalWrite, et 2 ou 3 fonctions que j'avais utilis� au courant de cette semaine d�couverte. J'ai �t� voir la source et j'ai compris qu'il suffisait d'appliquer mes connaissances en programmation C++, de lire les 650 pages du datasheet du 328P (voir ici: http://www.atmel.com/images/Atmel-82...t_Complete.pdf), pour cr�er ma propre biblioth�que et me passer finalement d'Arduino. Voila en gros le r�sum�.

    Photos de quelques projets en �lectronique que j'ai r�alis� durant l'ann�e
    http://sylvainmahe.xyz/forum/


    Ceci �tant dit, la biblioth�que �tant maintenant termin�e, je la met � disposition des internautes dans le but qu'ils puissent cr�er tout comme moi des projets assez complexes tr�s facilement
    Voici donc pour t�l�charger ma biblioth�que (qui n'a pas encore de nom): http://sylvainmahe.xyz/
    (mon site d�di� au projet est encore en construction)

    J'estime le temps de d�veloppement de cette biblioth�que � entre 3000 � 4000 heures durant l'ann�e.

    Cot� performances, ma biblioth�que est plus proche d'avr que d'arduino, par exemple, 1 million de pin toggling donne:
    AVR: 651ms
    ma biblioth�que: 753ms
    Arduino: 4550ms



    Le sujet ici pr�sent: J'ai derni�rement construit un quadricopt�re (chassis/carte pcb/�lectronique/programmation) en utilisant les fonctions de ma biblioth�que (voir lien ci-dessus), j'aimerais partager avec vous cette exp�rience car elle peut �tre int�ressante pour ceux qui souhaitent se lancer dans le quadricopt�re fait maison sans utiliser Arduino/Multiwii


    Le premier test moteur avec h�lices:


    Les premiers tests en vol hier:


    La puissance peut para�tre l�g�re (c'est cens� �tre un quadricopt�re de voltige), mais pour les premiers tests j'ai r�gl� la course des gaz � 50% max pour plus de s�curit�, ceci explique cela Demain j'essayerais avec 100% de gaz.


    Pour commencer, le code source sans ma biblioth�que (le main.cpp), fait seulement 326 lignes, donc sachez qu'un quadricopt�re est en ordre de vol avec seulement 326 lignes dans le main avec ma biblioth�que qui tourne derri�re, c'est tr�s peu, ceci avec toutes les s�curit�s d'avant vol au branchement de la batterie lipo avec buzzer de signalement, � savoir:-v�rification que votre radiocommande est bien calibr�e-v�rification de l'arriv�e du pwm de toutes les voies du r�cepteur-v�rification de l'inter coupure moteur activ� et du manche de gaz inf�rieur � 10%

    Et �galement avec la musique au d�marrage, ce qui n'est pas indispensable vous en conviendrez

    Voila la photo du quadricopt�re:


    La photo de la carte �lectronique:



    Cette carte maison me sert � tous mes projets en �lectronique.Le plan de celle-ci se trouve en bas du sujet.

    La machine pour r�aliser le ch�ssis, si vous le r�alisez en tube aluminium le mieux est d'avoir une fraiseuse sous la main:



    L'id�e de ce topic est de comprendre qu'avec ma biblioth�que on peut en quelques lignes de programmation cr�er des choses plus ou moins complexes beaucoup plus facilement qu'Arduino et avec une plus grande vitesse d'execution et une quantit� de m�moire moindre.

    Exemple/Tuto - Potar + Servo avec ma biblioth�que (sans Arduino):

    Vous devez d�j� savoir programmer et linker une biblioth�que, avoir une petite id�e de pourquoi se passer d'Arduino et qu'il faut AVR (l'architecture AVR de l'atmega328p), mais dans l'id�al, le processus est:

    -t�l�charger la biblioth�que, d�compresser les fichiers
    -avoir une carte arduino uno ou �quivalent
    -avoir un programmateur (vous pouvez utiliser l'usbasp avec mes batchs windows ou linux inclus dans l'archive de la biblioth�que pour compiler)
    -avoir avr c d'install� sur votre ordinateur
    -avoir un servo-moteur et un potentiom�tre sous la main

    J'ai cr�� une vid�o qui vous montre tr�s exactement la proc�dure:


    Je recopie mon exemple ici (main.cpp):
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include "../library/Potentiometer.h"
    #include "../library/Servo.h"
     
    using namespace std;
     
    int main()
    {
    	Servo myServo = Servo (1, 1100, 1900);
    	Potentiometer myPotentiometer = Potentiometer (15);
     
    	Servo::start (250);
     
    	while (true)
    	{
    		myPotentiometer.state();
     
    		myServo.pulse (myPotentiometer.curve (0, 1023, 1100, 1900, 0));
    	}
     
    	return 0;
    }
    En premier, remplacer "library" par le dossier dans l'archive qui contient la biblioth�que, encore une fois je ne suis pas encore s�r du nom que je vais lui donner.

    A la d�claration de l'objet Servo, le premier param�tre est le num�ro de la pin sur la carte (voir ma carte 328P en bas de ce sujet pour conna�tre la distribution des pins sur votre carte Arduino UNO par rapport � la mienne).
    On indique �galement 1100, c'est le d�battement min du servo, et 1900 le max, voyez le datasheet de votre servo-moteur pour conna�tre ces d�battements, ou faites des tests.

    A la d�claration de l'objet Potentiometer, on indique juste le num�ro de la pin, ici la 15 c'est � dire PC0.
    Ensuite on d�marre le servo-moteur avec Servo::start et on indique en param�tre la fr�quence du servo en Hz. Ici c'est un savox qui va jusqu'� 250Hz.

    Dans la boucle principale on r�cup�re l'�tat du potentiom�tre avec state, sa correspond � conna�tre la tension en valeur 10 bit sur la pin PC0.

    Ensuite on indique une position de palonnier de servo-moteur avec pulse, on lui injecte avec la fonction curve du potentiom�tre la tension sous la forme d'une valeur de 10 bit (0 � 1023) interpol� de 1100 � 1900 (les d�battements en us de notre servo-moteur) tout cela avec une courbe lin�aire (le 0 � la fin).


    Ensuite compilation avec le compilateur AVR et upload dans l'Atmega 328P avec le programmateur de votre choix, moi j'utilise l'usbasp, voir ici:
    http://www.fischl.de/usbasp/

    Et normalement �a fonctionne


    Photos pour comprendre la distribution des pins sur ma carte 328P faite maison en relation avec la distribution des pins de ma biblioth�que:




    Ma carte 328P et ma biblioth�que me servent � r�aliser pleins de projets, cette carte n'est pas plus sp�cialis� dans le quadricopt�re qu'autre chose, un exemple d'autre projet avec cette carte:
    Un jeu PONG:



    Voila ce sera tout pour aujourd'hui, n'h�sitez pas si vous avez des interrogations ou des commentaires

  2. #2
    Membre Expert
    Avatar de prgasp77
    Homme Profil pro
    Ing�nieur en syst�mes embarqu�s
    Inscrit en
    Juin 2004
    Messages
    1 306
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 38
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activit� : Ing�nieur en syst�mes embarqu�s
    Secteur : High Tech - �lectronique et micro-�lectronique

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 306
    Par d�faut
    Merci pour ce partage d'information. N'h�site pas � faire un tour dans le forum syst�mes embarqu�s, tu feras des heureux .

  3. #3
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Ok ca marche Tu penses que je peux laisser le lien de ce topic sur le forum des syst�mes embarqu�s?

  4. #4
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Voila apr�s une 30�ne de vols de tests le code source final sans horizon artificiel (pour l'instant):
    Main.cpp
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    #include "../library/Timer.h"
    #include "../library/Delay.h"
    #include "../library/Random.h"
    #include "../library/Math.h"
    #include "../library/Buzzer.h"
    #include "../library/Servo.h"
    #include "../library/Cycle.h"
    #include "../library/Gyroscope.h"
     
    using namespace std;
     
    int main()
    {
    	uint8_t n = 0;
    	Gyroscope mpu6050 = Gyroscope (0);
    	Cycle channelThrottle = Cycle (1, false);
    	uint16_t slowChannelThrottle = 0;
    	uint16_t centerChannelThrottle = 0;
    	Cycle channelPitch = Cycle (2, false);
    	uint16_t centerChannelPitch = 0;
    	Cycle channelRoll = Cycle (3, false);
    	uint16_t centerChannelRoll = 0;
    	Cycle channelYaw = Cycle (4, false);
    	uint16_t centerChannelYaw = 0;
    	Cycle channelHold = Cycle (5, false);
    	uint16_t centerChannelHold = 0;
    	Cycle channelOption = Cycle (6, false);
    	uint16_t centerChannelOption = 0;
    	Servo motor1 = Servo (7, 0, 0, 0);
    	Servo motor2 = Servo (8, 0, 0, 0);
    	Servo motor3 = Servo (9, 0, 0, 0);
    	Servo motor4 = Servo (10, 0, 0, 0);
    	Delay delaySoundStartCondition = Delay (1000, false);
    	uint16_t mixThrottle = 0;
    	int16_t mixThrustPitchGain = 0;
    	int16_t mixThrustRollGain = 0;
    	int16_t mixInertiaYawGain = 0;
    	int16_t mixMinClearancePitch = 0;
    	int16_t mixMaxClearancePitch = 0;
    	int16_t mixMinClearanceRoll = 0;
    	int16_t mixMaxClearanceRoll = 0;
    	int16_t mixMinClearanceYaw = 0;
    	int16_t mixMaxClearanceYaw = 0;
    	const uint16_t SPEED_GYRO = 1000;
    	int16_t speedPitch = 0;
    	int16_t speedRoll = 0;
    	int16_t speedYaw = 0;
    	int16_t mixPitchOffsetGyro = 0;
    	int16_t mixRollOffsetGyro = 0;
    	int16_t mixYawOffsetGyro = 0;
    	uint8_t thrustGainPitch = 0;
    	uint8_t thrustGainRoll = 0;
    	uint8_t inertiaGainYaw = 0;
    	uint16_t gainMinRxGyro = 0;
    	uint16_t gainMaxRxGyro = 0;
    	uint16_t gainMinRyGyro = 0;
    	uint16_t gainMaxRyGyro = 0;
    	uint16_t gainMinRzGyro = 0;
    	uint16_t gainMaxRzGyro = 0;
    	int16_t mixMinRxGyro = 0;
    	int16_t mixMaxRxGyro = 0;
    	int16_t mixMinRyGyro = 0;
    	int16_t mixMaxRyGyro = 0;
    	int16_t mixMinRzGyro = 0;
    	int16_t mixMaxRzGyro = 0;
    	uint16_t mixMotor1 = 0;
    	uint16_t mixMotor2 = 0;
    	uint16_t mixMotor3 = 0;
    	uint16_t mixMotor4 = 0;
    	const uint16_t SETUP_MIN_CHANNEL_THROTTLE = 1000;
    	const uint16_t SETUP_MAX_CHANNEL_THROTTLE = 2000;
    	const uint16_t SETUP_MIN_CHANNEL_PITCH = 1000;
    	const uint16_t SETUP_MAX_CHANNEL_PITCH = 2000;
    	const uint16_t SETUP_MIN_CHANNEL_ROLL = 1000;
    	const uint16_t SETUP_MAX_CHANNEL_ROLL = 2000;
    	const uint16_t SETUP_MIN_CHANNEL_YAW = 1000;
    	const uint16_t SETUP_MAX_CHANNEL_YAW = 2000;
    	const uint16_t SETUP_MIN_CHANNEL_HOLD = 1000;
    	const uint16_t SETUP_MAX_CHANNEL_HOLD = 2000;
    	const uint16_t SETUP_MIN_CHANNEL_OPTION = 1500;
    	const uint16_t SETUP_MAX_CHANNEL_OPTION = 2000;
    	const int16_t SETUP_ZERO_PITCH = 38;
    	const int16_t SETUP_ZERO_ROLL = -11;
    	const int16_t SETUP_ZERO_YAW = -46;
    	const uint16_t SETUP_FREQUENCY_ESC = 100;
    	const uint16_t SETUP_HOLD_ESC = 950;
    	const uint16_t SETUP_MIN_ESC = 1050;
    	const uint16_t SETUP_MAX_ESC = 1950;
    	const uint16_t SETUP_TRAVEL_PITCH = 300;
    	const uint16_t SETUP_TRAVEL_ROLL = 300;
    	const uint16_t SETUP_TRAVEL_YAW = 300;
    	const uint16_t SETUP_SPEED_PITCH = 300;
    	const uint16_t SETUP_SPEED_ROLL = 300;
    	const uint16_t SETUP_SPEED_YAW = 200;
    	const uint8_t SETUP_GAIN_PITCH = 87;
    	const uint8_t SETUP_GAIN_ROLL = 83;
    	const uint8_t SETUP_GAIN_YAW = 92;
    	const uint8_t SETUP_THRUST_PROPELLER = 60;
    	const uint8_t SETUP_INERTIA_PROPELLER = 100;
     
    	Timer::pause (1000);
     
    	slowChannelThrottle = round (double (SETUP_MIN_CHANNEL_THROTTLE) + ((double (SETUP_MAX_CHANNEL_THROTTLE) - double (SETUP_MIN_CHANNEL_THROTTLE)) / double (10)));
    	centerChannelThrottle = round (double (SETUP_MAX_CHANNEL_THROTTLE) - ((double (SETUP_MAX_CHANNEL_THROTTLE) - double (SETUP_MIN_CHANNEL_THROTTLE)) / double (2)));
    	centerChannelPitch = round (double (SETUP_MAX_CHANNEL_PITCH) - ((double (SETUP_MAX_CHANNEL_PITCH) - double (SETUP_MIN_CHANNEL_PITCH)) / double (2)));
    	centerChannelRoll = round (double (SETUP_MAX_CHANNEL_ROLL) - ((double (SETUP_MAX_CHANNEL_ROLL) - double (SETUP_MIN_CHANNEL_ROLL)) / double (2)));
    	centerChannelYaw = round (double (SETUP_MAX_CHANNEL_YAW) - ((double (SETUP_MAX_CHANNEL_YAW) - double (SETUP_MIN_CHANNEL_YAW)) / double (2)));
    	centerChannelHold = round (double (SETUP_MAX_CHANNEL_HOLD) - ((double (SETUP_MAX_CHANNEL_HOLD) - double (SETUP_MIN_CHANNEL_HOLD)) / double (2)));
    	centerChannelOption = round (double (SETUP_MAX_CHANNEL_OPTION) - ((double (SETUP_MAX_CHANNEL_OPTION) - double (SETUP_MIN_CHANNEL_OPTION)) / double (2)));
     
    	Buzzer::pin (11);
     
    	while (centerChannelThrottle == 0 || centerChannelPitch == 0 || centerChannelRoll == 0 || centerChannelYaw == 0 || centerChannelHold == 0 || centerChannelOption == 0)
    	{
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			Buzzer::play (200, 100);
    		}
    	}
     
    	delaySoundStartCondition.reset();
     
    	Cycle::start (100);
     
    	while (channelThrottle.us == 0 || channelPitch.us == 0 || channelRoll.us == 0 || channelYaw.us == 0 || channelHold.us == 0 || channelHold.us == 0)
    	{
    		channelThrottle.state();
    		channelPitch.state();
    		channelRoll.state();
    		channelYaw.state();
    		channelHold.state();
    		channelOption.state();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			Buzzer::key (200, 100);
    			Buzzer::key (0, 100);
    			Buzzer::key (200, 100);
    			Buzzer::playKey();
    		}
    	}
     
    	delaySoundStartCondition.reset();
     
    	while (channelThrottle.us > slowChannelThrottle || channelHold.us < centerChannelHold)
    	{
    		channelThrottle.state();
    		channelHold.state();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			Buzzer::key (200, 100);
    			Buzzer::key (0, 100);
    			Buzzer::key (200, 100);
    			Buzzer::key (0, 100);
    			Buzzer::key (200, 100);
    			Buzzer::playKey();
    		}
    	}
     
    	Random::seed (15);
     
    	for (n = 0; n < 16; n++)
    	{
    		if (n != 0)
    		{
    			Buzzer::key (0, Random::integer (25, 75));
    		}
     
    		Buzzer::key (Random::integer (70, 3000), Random::integer (25, 75));
    	}
     
    	Buzzer::playKey();
     
    	speedPitch = Math::curve (0, SETUP_SPEED_PITCH, SPEED_GYRO, 0, 32767, 0);
    	speedRoll = Math::curve (0, SETUP_SPEED_ROLL, SPEED_GYRO, 0, 32767, 0);
    	speedYaw = Math::curve (0, SETUP_SPEED_YAW, SPEED_GYRO, 0, 32767, 0);
     
    	thrustGainPitch = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_PITCH, 0);
    	gainMinRxGyro = Math::curve (0, thrustGainPitch, 100, 32767, 0, 0);
    	gainMaxRxGyro = Math::curve (0, SETUP_GAIN_PITCH, 100, 32767, 0, 0);
     
    	thrustGainRoll = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_ROLL, 0);
    	gainMinRyGyro = Math::curve (0, thrustGainRoll, 100, 32767, 0, 0);
    	gainMaxRyGyro = Math::curve (0, SETUP_GAIN_ROLL, 100, 32767, 0, 0);
     
    	inertiaGainYaw = Math::curve (0, SETUP_INERTIA_PROPELLER, 100, 0, SETUP_GAIN_YAW, 0);
    	gainMinRzGyro = Math::curve (0, inertiaGainYaw, 100, 32767, 0, 0);
    	gainMaxRzGyro = Math::curve (0, SETUP_GAIN_YAW, 100, 32767, 0, 0);
     
    	mpu6050.setZero (SETUP_ZERO_PITCH, SETUP_ZERO_ROLL, SETUP_ZERO_YAW);
     
    	motor1.hold (SETUP_HOLD_ESC);
    	motor1.min (SETUP_MIN_ESC);
    	motor1.max (SETUP_MAX_ESC);
    	motor2.hold (SETUP_HOLD_ESC);
    	motor2.min (SETUP_MIN_ESC);
    	motor2.max (SETUP_MAX_ESC);
    	motor3.hold (SETUP_HOLD_ESC);
    	motor3.min (SETUP_MIN_ESC);
    	motor3.max (SETUP_MAX_ESC);
    	motor4.hold (SETUP_HOLD_ESC);
    	motor4.min (SETUP_MIN_ESC);
    	motor4.max (SETUP_MAX_ESC);
     
    	motor1.moveHold();
    	motor2.moveHold();
    	motor3.moveHold();
    	motor4.moveHold();
     
    	Servo::start (SETUP_FREQUENCY_ESC);
     
    	while (true)
    	{
    		mpu6050.state();
    		channelThrottle.state();
    		channelPitch.state();
    		channelRoll.state();
    		channelYaw.state();
    		channelHold.state();
    		channelOption.state();
     
    		if (channelHold.us > centerChannelHold)
    		{
    			motor1.moveHold();
    			motor2.moveHold();
    			motor3.moveHold();
    			motor4.moveHold();
    		}
    		else
    		{
    			mixThrottle = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_MIN_ESC, SETUP_MAX_ESC, 0);
     
    			mixMotor1 = mixThrottle;
    			mixMotor2 = mixThrottle;
    			mixMotor3 = mixThrottle;
    			mixMotor4 = mixThrottle;
     
    			mixMinClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_PITCH, 0);
    			mixMaxClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_PITCH, 0, 0);
    			mixPitchOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_PITCH, channelPitch.us, SETUP_MAX_CHANNEL_PITCH, -speedPitch, speedPitch, 0);
    			mixThrustPitchGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRxGyro, gainMinRxGyro, 0);
    			mixMinRxGyro = Math::wurve (-mixThrustPitchGain, mpu6050.rx + mixPitchOffsetGyro, mixThrustPitchGain, -mixMaxClearancePitch, 0, mixMinClearancePitch, 0, 0);
    			mixMaxRxGyro = Math::wurve (-mixThrustPitchGain, mpu6050.rx + mixPitchOffsetGyro, mixThrustPitchGain, -mixMinClearancePitch, 0, mixMaxClearancePitch, 0, 0);
     
    			mixMotor1 -= mixMinRxGyro;
    			mixMotor2 -= mixMinRxGyro;
    			mixMotor3 += mixMaxRxGyro;
    			mixMotor4 += mixMaxRxGyro;
     
    			mixMinClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_ROLL, 0);
    			mixMaxClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_ROLL, 0, 0);
    			mixRollOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_ROLL, channelRoll.us, SETUP_MAX_CHANNEL_ROLL, -speedRoll, speedRoll, 0);
    			mixThrustRollGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRyGyro, gainMinRyGyro, 0);
    			mixMinRyGyro = Math::wurve (-mixThrustRollGain, mpu6050.ry - mixRollOffsetGyro, mixThrustRollGain, -mixMaxClearanceRoll, 0, mixMinClearanceRoll, 0, 0);
    			mixMaxRyGyro = Math::wurve (-mixThrustRollGain, mpu6050.ry - mixRollOffsetGyro, mixThrustRollGain, -mixMinClearanceRoll, 0, mixMaxClearanceRoll, 0, 0);
     
    			mixMotor1 -= mixMinRyGyro;
    			mixMotor2 += mixMaxRyGyro;
    			mixMotor3 -= mixMinRyGyro;
    			mixMotor4 += mixMaxRyGyro;
     
    			mixMinClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_YAW, 0);
    			mixMaxClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_YAW, 0, 0);
    			mixYawOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_YAW, channelYaw.us, SETUP_MAX_CHANNEL_YAW, -speedYaw, speedYaw, 0);
    			mixInertiaYawGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRzGyro, gainMinRzGyro, 0);
    			mixMinRzGyro = Math::wurve (-mixInertiaYawGain, mpu6050.rz + mixYawOffsetGyro, mixInertiaYawGain, -mixMaxClearanceYaw, 0, mixMinClearanceYaw, 0, 0);
    			mixMaxRzGyro = Math::wurve (-mixInertiaYawGain, mpu6050.rz + mixYawOffsetGyro, mixInertiaYawGain, -mixMinClearanceYaw, 0, mixMaxClearanceYaw, 0, 0);
     
    			mixMotor1 -= mixMinRzGyro;
    			mixMotor2 += mixMaxRzGyro;
    			mixMotor3 += mixMaxRzGyro;
    			mixMotor4 -= mixMinRzGyro;
     
    			motor1.pulse (mixMotor1);
    			motor2.pulse (mixMotor2);
    			motor3.pulse (mixMotor3);
    			motor4.pulse (mixMotor4);
    		}
    	}
     
    	return 0;
    }
    Pour quadricopt�re avec:
    Moteur1 = avant gauche
    Moteur2 = avant droit
    Moteur3 = arri�re gauche
    Moteur4 = arri�re droit

    Les param�tres � adapter selon votre quad commencent par le pr�fixe SETUP.
    La gestion des moteurs prends en compte le rendement des h�lices (param�tre THRUST), cette gestion est asym�trique de sorte que vous avez votre plein ralenti et plein gaz avec 100% des ordres pitch/roll/yaw disponible m�me manche de gaz (THROTTLE) en but�e mini ou maxi.

    Le quad est tr�s verrouill� sur ses axes, la voltige passe sans aucune difficult�, j'ai test� pleins de choses: plein gaz vers le bas, boucles carr�s, etc...

    Il y a bien-s�r les trois s�curit�s d'avant d�marrage que j'ai cit� dans ce sujet.

    Ma config actuelle est:
    tiger motors mn2206
    kiss esc 18A
    lipo 4s 2200mAh
    h�lices hq 6x4.5"


    Le code est tr�s robuste, vous pouvez-y aller sans probl�me N'h�sitez pas si vous avez un soucis ou des questions.

  5. #5
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Nouvelle vid�o avec un peu de voltige
    (soyez indulgents c'est pas facile de piloter avec les pouces gel�s :p)



    Nom : DSC01904resized.jpg
Affichages : 3430
Taille : 320,9 Ko
    Nom : DSC01909resized.jpg
Affichages : 3365
Taille : 119,2 Ko

    N'h�sitez pas si vous avez des interrogations cot� r�alisation ou autre.

  6. #6
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Apr�s quelques mois de recherches infructueuses en ce qui concerne le nom et le logo de mon projet cartes+biblioth�que, j'ai finalement r�ussi � en dessiner un qui me convient:



    Module integrated = module int�gr� (pour les non anglophones)
    Module pour modulable, mais aussi pour g�n�ration de signal modul� (pulse width modulation), d�o� la forme du logo (onde carr�e). GPL pour General Public Licence (https://fr.wikipedia.org/wiki/Licenc...%C3%A9rale_GNU).

    J'ai aussi travaill� sur le site aujourd'hui pour que cela soit coh�rent niveau formes et couleurs, mais il me faudra d'autres week-end pour finaliser ce site
    http://sylvainmahe.xyz/


    Encore une fois n'h�sitez pas pour les commentaires et si vous avez des questions pour le fonctionnement de la biblioth�que, et/ou id�es que vous pouvez apporter

  7. #7
    Membre Expert
    Homme Profil pro
    �tudiant
    Inscrit en
    Juin 2012
    Messages
    1 711
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 1 711
    Par d�faut
    J'aime bien la police utilis�e.
    Par contre, j'ai lu "Nodule"

  8. #8
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Oui effectivement �a me le fait aussi

    Je verrais si je met une barre ou quoi pour le M (c'est une police perso)

  9. #9
    Membre �m�rite
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    780
    D�tails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyr�n�es)

    Informations forums :
    Inscription : Mai 2006
    Messages : 780
    Par d�faut
    Comme dans avr-gcc il y a un compilateur C++11, tu peux t'amuser aussi.

    Ya une technique en utilisant des templates pour ne pas avoir � g�rer des pointeurs sur les pins par ex., mais juste changer directement la pin que tu veux. Dans ce doc : http://www.open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf � partir de la page 137. Je l'ai implement�, �a marchait nickel.

    Bon en gros, pour faire simple, sans rentrer dans le d�tail, au lieu d'avoir:

    LED myLed( pinPtr );

    tu aurais plut�t un objet io_pin que tu changerais directement!

    // ici la d�finition g�n�rale de tous tes pins avec juste des typedefs
    typedef io_pin< PortB, 5 > DebugLed;

    et dans le code (dans un objet sp�cifique "LED DE DEBUG" si tu veux aussi: )

    DebugLed::set( true );

    par ex.

    Comme le cablage ne changera pas trop dynamiquement, tu as un pointeur et une indirection en moins. Bon je sais pas si c'est tr�s clair, c'est pas �vident � mettre en place.

    Oui, j'ai une petite id�e de faire une librairie C++ embedded aussi

  10. #10
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Merci *nikko34 pour ton intervention, effectivement je connais cela tr�s bien, mais moi je pr�f�re les objets et ma m�thode, plut�t qu'� la sauce arduino.

    Par contre libre � toi de modifier ma biblioth�que, ou bien de cr�er ta propre biblioth�que

  11. #11
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Mise � jour importante de ma biblioth�que pour l'ATmega328P: http://sylvainmahe.xyz/data/module.zip
    Celle ci est maintenant ind�pendante au sens ou je n'utilise plus aucun include vers des fichiers avr, ou des fichiers couramment utilis�s/admis en langage c/c++, � savoir:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    #include <stdlib.h>
    #include <avr/interrupt.h>
    #include <avr/sleep.h>
    #include <math.h>
    #include <string.h>
    A noter que ces fichiers avaient eux aussi de multiples include...


    Voila � quoi ressemble ma biblioth�que maintenant:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    "../module/GpioRead.h"
    "../module/GpioWrite.h"
    "../module/AnalogRead.h"
    "../module/InterruptRead.h"
    "../module/PwmRead.h"
    "../module/PwmWrite.h"
    "../module/SoundWrite.h"
     
    "../module/Timer.h"
    "../module/Delay.h"
     
    "../module/Math.h"
    "../module/Iteration.h"
    "../module/Average.h"
    "../module/Random.h"
     
    "../module/Max7219.h"
    "../module/Mpu6050.h"
     
    "../module/Network.h"
     
    "../module/Memory.h"
    "../module/Power.h"
    "../module/Tool.h"
    Vous avez � disposition 19 classes pour cr�er vos projets, et selon les composants que j'ach�te j'ajouterais des classes d�di�es � ces composants. Normalement une classes Si4432 devrait bient�t voir le jour pour la communication sans fil.


    Pour ceux int�ress�s par la programmation c/c++ pour l'ATmega328P, voici ma liste des d�claration de registre et vecteurs d'interruption pour l'ATmega328P (c'est dans l'ordre comme indiqu� dans le datasheet):
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    #define _UDR0 (*(volatile unsigned char *)(0xc6))
    #define _UBRR0H (*(volatile unsigned char *)(0xc5))
    #define _UBRR0L (*(volatile unsigned char *)(0xc4))
    #define _UBRR0HL (*(volatile unsigned int *)(0xc4))
    #define _UCSR0C (*(volatile unsigned char *)(0xc2))
    #define _UCSR0B (*(volatile unsigned char *)(0xc1))
    #define _UCSR0A (*(volatile unsigned char *)(0xc0))
    #define _TWAMR (*(volatile unsigned char *)(0xbd))
    #define _TWCR (*(volatile unsigned char *)(0xbc))
    #define _TWDR (*(volatile unsigned char *)(0xbb))
    #define _TWAR (*(volatile unsigned char *)(0xba))
    #define _TWSR (*(volatile unsigned char *)(0xb9))
    #define _TWBR (*(volatile unsigned char *)(0xb8))
    #define _ASSR (*(volatile unsigned char *)(0xb6))
    #define _OCR2B (*(volatile unsigned char *)(0xb4))
    #define _OCR2A (*(volatile unsigned char *)(0xb3))
    #define _TCNT2 (*(volatile unsigned char *)(0xb2))
    #define _TCCR2B (*(volatile unsigned char *)(0xb1))
    #define _TCCR2A (*(volatile unsigned char *)(0xb0))
    #define _OCR1BH (*(volatile unsigned char *)(0x8b))
    #define _OCR1BL (*(volatile unsigned char *)(0x8a))
    #define _OCR1BHL (*(volatile unsigned int *)(0x8a))
    #define _OCR1AH (*(volatile unsigned char *)(0x89))
    #define _OCR1AL (*(volatile unsigned char *)(0x88))
    #define _OCR1AHL (*(volatile unsigned int *)(0x88))
    #define _ICR1H (*(volatile unsigned char *)(0x87))
    #define _ICR1L (*(volatile unsigned char *)(0x86))
    #define _ICR1HL (*(volatile unsigned int *)(0x86))
    #define _TCNT1H (*(volatile unsigned char *)(0x85))
    #define _TCNT1L (*(volatile unsigned char *)(0x84))
    #define _TCNT1HL (*(volatile unsigned int *)(0x84))
    #define _TCCR1C (*(volatile unsigned char *)(0x82))
    #define _TCCR1B (*(volatile unsigned char *)(0x81))
    #define _TCCR1A (*(volatile unsigned char *)(0x80))
    #define _DIDR1 (*(volatile unsigned char *)(0x7f))
    #define _DIDR0 (*(volatile unsigned char *)(0x7e))
    #define _ADMUX (*(volatile unsigned char *)(0x7c))
    #define _ADCSRB (*(volatile unsigned char *)(0x7b))
    #define _ADCSRA (*(volatile unsigned char *)(0x7a))
    #define _ADCH (*(volatile unsigned char *)(0x79))
    #define _ADCL (*(volatile unsigned char *)(0x78))
    #define _ADCHL (*(volatile unsigned int *)(0x78))
    #define _TIMSK2 (*(volatile unsigned char *)(0x70))
    #define _TIMSK1 (*(volatile unsigned char *)(0x6f))
    #define _TIMSK0 (*(volatile unsigned char *)(0x6e))
    #define _PCMSK2 (*(volatile unsigned char *)(0x6d))
    #define _PCMSK1 (*(volatile unsigned char *)(0x6c))
    #define _PCMSK0 (*(volatile unsigned char *)(0x6b))
    #define _EICRA (*(volatile unsigned char *)(0x69))
    #define _PCICR (*(volatile unsigned char *)(0x68))
    #define _OSCCAL (*(volatile unsigned char *)(0x66))
    #define _PRR (*(volatile unsigned char *)(0x64))
    #define _CLKPR (*(volatile unsigned char *)(0x61))
    #define _WDTCSR (*(volatile unsigned char *)(0x60))
    #define _SREG (*(volatile unsigned char *)(0x5f))
    #define _SPH (*(volatile unsigned char *)(0x5e))
    #define _SPL (*(volatile unsigned char *)(0x5d))
    #define _SPHL (*(volatile unsigned int *)(0x5d))
    #define _SPMCSR (*(volatile unsigned char *)(0x57))
    #define _MCUCR (*(volatile unsigned char *)(0x55))
    #define _MCUSR (*(volatile unsigned char *)(0x54))
    #define _SMCR (*(volatile unsigned char *)(0x53))
    #define _ACSR (*(volatile unsigned char *)(0x50))
    #define _SPDR (*(volatile unsigned char *)(0x4e))
    #define _SPSR (*(volatile unsigned char *)(0x4d))
    #define _SPCR (*(volatile unsigned char *)(0x4c))
    #define _GPIOR2 (*(volatile unsigned char *)(0x4b))
    #define _GPIOR1 (*(volatile unsigned char *)(0x4a))
    #define _OCR0B (*(volatile unsigned char *)(0x48))
    #define _OCR0A (*(volatile unsigned char *)(0x47))
    #define _TCNT0 (*(volatile unsigned char *)(0x46))
    #define _TCCR0B (*(volatile unsigned char *)(0x45))
    #define _TCCR0A (*(volatile unsigned char *)(0x44))
    #define _GTCCR (*(volatile unsigned char *)(0x43))
    #define _EEARH (*(volatile unsigned char *)(0x42))
    #define _EEARL (*(volatile unsigned char *)(0x41))
    #define _EEARHL (*(volatile unsigned int *)(0x41))
    #define _EEDR (*(volatile unsigned char *)(0x40))
    #define _EECR (*(volatile unsigned char *)(0x3f))
    #define _GPIOR0 (*(volatile unsigned char *)(0x3e))
    #define _EIMSK (*(volatile unsigned char *)(0x3d))
    #define _EIFR (*(volatile unsigned char *)(0x3c))
    #define _PCIFR (*(volatile unsigned char *)(0x3b))
    #define _TIFR2 (*(volatile unsigned char *)(0x37))
    #define _TIFR1 (*(volatile unsigned char *)(0x36))
    #define _TIFR0 (*(volatile unsigned char *)(0x35))
    #define _PORTD (*(volatile unsigned char *)(0x2b))
    #define _DDRD (*(volatile unsigned char *)(0x2a))
    #define _PIND (*(volatile unsigned char *)(0x29))
    #define _PORTC (*(volatile unsigned char *)(0x28))
    #define _DDRC (*(volatile unsigned char *)(0x27))
    #define _PINC (*(volatile unsigned char *)(0x26))
    #define _PORTB (*(volatile unsigned char *)(0x25))
    #define _DDRB (*(volatile unsigned char *)(0x24))
    #define _PINB (*(volatile unsigned char *)(0x23))
     
    #define _RESET __vector_ ## 0
    #define _INT0 __vector_ ## 1
    #define _INT1 __vector_ ## 2
    #define _PCINT0 __vector_ ## 3
    #define _PCINT1 __vector_ ## 4
    #define _PCINT2 __vector_ ## 5
    #define _WDT __vector_ ## 6
    #define _TIMER2_COMPA __vector_ ## 7
    #define _TIMER2_COMPB __vector_ ## 8
    #define _TIMER2_OVF __vector_ ## 9
    #define _TIMER1_CAPT __vector_ ## 10
    #define _TIMER1_COMPA __vector_ ## 11
    #define _TIMER1_COMPB __vector_ ## 12
    #define _TIMER1_OVF __vector_ ## 13
    #define _TIMER0_COMPA __vector_ ## 14
    #define _TIMER0_COMPB __vector_ ## 15
    #define _TIMER0_OVF __vector_ ## 16
    #define _SPI_STC __vector_ ## 17
    #define _USART_RX __vector_ ## 18
    #define _USART_UDRE __vector_ ## 19
    #define _USART_TX __vector_ ## 20
    #define _ADC __vector_ ## 21
    #define _EE_READY __vector_ ## 22
    #define _ANALOG_COMP __vector_ ## 23
    #define _TWI __vector_ ## 24
    #define _SPM_READY __vector_ ## 25
     
    #define _INTERRUPT_JUMP(vector) extern "C" void vector() __attribute__ ((signal)); void vector()

    Un petit rappel (et mise � jour du code) de ce qu'il faut pour faire voler un quadri-h�licopt�re:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    #include "../module/Timer.h"
    #include "../module/Delay.h"
    #include "../module/Random.h"
    #include "../module/Math.h"
    #include "../module/SoundWrite.h"
    #include "../module/PwmWrite.h"
    #include "../module/PwmRead.h"
    #include "../module/Mpu6050.h"
     
    int main()
    {
    	unsigned char n = 0;
    	Mpu6050 gyroscope = Mpu6050 (0);
    	PwmRead channelThrottle = PwmRead (1, false);
    	unsigned int slowChannelThrottle = 0;
    	unsigned int centerChannelThrottle = 0;
    	PwmRead channelPitch = PwmRead (2, false);
    	unsigned int centerChannelPitch = 0;
    	PwmRead channelRoll = PwmRead (3, false);
    	unsigned int centerChannelRoll = 0;
    	PwmRead channelYaw = PwmRead (4, false);
    	unsigned int centerChannelYaw = 0;
    	PwmRead channelHold = PwmRead (5, false);
    	unsigned int centerChannelHold = 0;
    	PwmRead channelOption = PwmRead (6, false);
    	unsigned int centerChannelOption = 0;
    	PwmWrite motor1 = PwmWrite (8, 0, 0, 0);
    	PwmWrite motor2 = PwmWrite (9, 0, 0, 0);
    	PwmWrite motor3 = PwmWrite (10, 0, 0, 0);
    	PwmWrite motor4 = PwmWrite (11, 0, 0, 0);
    	Delay delaySoundStartCondition = Delay (1000, false);
    	unsigned int mixThrottle = 0;
    	signed int mixThrustPitchGain = 0;
    	signed int mixThrustRollGain = 0;
    	signed int mixInertiaYawGain = 0;
    	signed int mixMinClearancePitch = 0;
    	signed int mixMaxClearancePitch = 0;
    	signed int mixMinClearanceRoll = 0;
    	signed int mixMaxClearanceRoll = 0;
    	signed int mixMinClearanceYaw = 0;
    	signed int mixMaxClearanceYaw = 0;
    	const unsigned int SPEED_GYRO = 1000;
    	signed int speedPitch = 0;
    	signed int speedRoll = 0;
    	signed int speedYaw = 0;
    	signed int mixPitchOffsetGyro = 0;
    	signed int mixRollOffsetGyro = 0;
    	signed int mixYawOffsetGyro = 0;
    	unsigned char thrustGainPitch = 0;
    	unsigned char thrustGainRoll = 0;
    	unsigned char inertiaGainYaw = 0;
    	unsigned int gainMinRxGyro = 0;
    	unsigned int gainMaxRxGyro = 0;
    	unsigned int gainMinRyGyro = 0;
    	unsigned int gainMaxRyGyro = 0;
    	unsigned int gainMinRzGyro = 0;
    	unsigned int gainMaxRzGyro = 0;
    	signed int mixMinRxGyro = 0;
    	signed int mixMaxRxGyro = 0;
    	signed int mixMinRyGyro = 0;
    	signed int mixMaxRyGyro = 0;
    	signed int mixMinRzGyro = 0;
    	signed int mixMaxRzGyro = 0;
    	unsigned int mixMotor1 = 0;
    	unsigned int mixMotor2 = 0;
    	unsigned int mixMotor3 = 0;
    	unsigned int mixMotor4 = 0;
    	const unsigned int SETUP_MIN_CHANNEL_THROTTLE = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_THROTTLE = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_PITCH = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_PITCH = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_ROLL = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_ROLL = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_YAW = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_YAW = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_HOLD = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_HOLD = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_OPTION = 1500;
    	const unsigned int SETUP_MAX_CHANNEL_OPTION = 2000;
    	const signed int SETUP_ZERO_PITCH = 38;
    	const signed int SETUP_ZERO_ROLL = -11;
    	const signed int SETUP_ZERO_YAW = -46;
    	const unsigned int SETUP_FREQUENCY_ESC = 100;
    	const unsigned int SETUP_HOLD_ESC = 950;
    	const unsigned int SETUP_MIN_ESC = 1050;
    	const unsigned int SETUP_MAX_ESC = 1950;
    	const unsigned int SETUP_TRAVEL_PITCH = 250;
    	const unsigned int SETUP_TRAVEL_ROLL = 250;
    	const unsigned int SETUP_TRAVEL_YAW = 400;
    	const unsigned int SETUP_SPEED_PITCH = 320;
    	const unsigned int SETUP_SPEED_ROLL = 320;
    	const unsigned int SETUP_SPEED_YAW = 320;
    	const unsigned char SETUP_GAIN_PITCH = 93;
    	const unsigned char SETUP_GAIN_ROLL = 88;
    	const unsigned char SETUP_GAIN_YAW = 95;
    	const unsigned char SETUP_THRUST_PROPELLER = 55;
    	const unsigned char SETUP_INERTIA_PROPELLER = 100;
     
    	Timer::pause (1000);
     
    	slowChannelThrottle = Math::round (float (SETUP_MIN_CHANNEL_THROTTLE) + ((float (SETUP_MAX_CHANNEL_THROTTLE) - float (SETUP_MIN_CHANNEL_THROTTLE)) / float (10)));
    	centerChannelThrottle = Math::round (float (SETUP_MAX_CHANNEL_THROTTLE) - ((float (SETUP_MAX_CHANNEL_THROTTLE) - float (SETUP_MIN_CHANNEL_THROTTLE)) / float (2)));
    	centerChannelPitch = Math::round (float (SETUP_MAX_CHANNEL_PITCH) - ((float (SETUP_MAX_CHANNEL_PITCH) - float (SETUP_MIN_CHANNEL_PITCH)) / float (2)));
    	centerChannelRoll = Math::round (float (SETUP_MAX_CHANNEL_ROLL) - ((float (SETUP_MAX_CHANNEL_ROLL) - float (SETUP_MIN_CHANNEL_ROLL)) / float (2)));
    	centerChannelYaw = Math::round (float (SETUP_MAX_CHANNEL_YAW) - ((float (SETUP_MAX_CHANNEL_YAW) - float (SETUP_MIN_CHANNEL_YAW)) / float (2)));
    	centerChannelHold = Math::round (float (SETUP_MAX_CHANNEL_HOLD) - ((float (SETUP_MAX_CHANNEL_HOLD) - float (SETUP_MIN_CHANNEL_HOLD)) / float (2)));
    	centerChannelOption = Math::round (float (SETUP_MAX_CHANNEL_OPTION) - ((float (SETUP_MAX_CHANNEL_OPTION) - float (SETUP_MIN_CHANNEL_OPTION)) / float (2)));
     
    	SoundWrite::pin (13);
     
    	while (centerChannelThrottle == 0 || centerChannelPitch == 0 || centerChannelRoll == 0 || centerChannelYaw == 0 || centerChannelHold == 0 || centerChannelOption == 0)
    	{
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			SoundWrite::play (200, 100);
    		}
    	}
     
    	delaySoundStartCondition.reset();
     
    	PwmRead::start (100);
     
    	while (channelThrottle.us == 0 || channelPitch.us == 0 || channelRoll.us == 0 || channelYaw.us == 0 || channelHold.us == 0 || channelOption.us == 0)
    	{
    		channelThrottle.state();
    		channelPitch.state();
    		channelRoll.state();
    		channelYaw.state();
    		channelHold.state();
    		channelOption.state();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::playKey();
    		}
    	}
     
    	delaySoundStartCondition.reset();
     
    	while (channelThrottle.us > slowChannelThrottle || channelHold.us < centerChannelHold)
    	{
    		channelThrottle.state();
    		channelHold.state();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::playKey();
    		}
    	}
     
    	Random::seed (15);
     
    	for (n = 0; n < 16; n++)
    	{
    		if (n != 0)
    		{
    			SoundWrite::key (0, Random::integer (25, 75));
    		}
     
    		SoundWrite::key (Random::integer (70, 3000), Random::integer (25, 75));
    	}
     
    	SoundWrite::playKey();
     
    	speedPitch = Math::curve (0, SETUP_SPEED_PITCH, SPEED_GYRO, 0, 32767, 0);
    	speedRoll = Math::curve (0, SETUP_SPEED_ROLL, SPEED_GYRO, 0, 32767, 0);
    	speedYaw = Math::curve (0, SETUP_SPEED_YAW, SPEED_GYRO, 0, 32767, 0);
     
    	thrustGainPitch = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_PITCH, 0);
    	gainMinRxGyro = Math::curve (0, thrustGainPitch, 100, 32767, 0, 0);
    	gainMaxRxGyro = Math::curve (0, SETUP_GAIN_PITCH, 100, 32767, 0, 0);
     
    	thrustGainRoll = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_ROLL, 0);
    	gainMinRyGyro = Math::curve (0, thrustGainRoll, 100, 32767, 0, 0);
    	gainMaxRyGyro = Math::curve (0, SETUP_GAIN_ROLL, 100, 32767, 0, 0);
     
    	inertiaGainYaw = Math::curve (0, SETUP_INERTIA_PROPELLER, 100, 0, SETUP_GAIN_YAW, 0);
    	gainMinRzGyro = Math::curve (0, inertiaGainYaw, 100, 32767, 0, 0);
    	gainMaxRzGyro = Math::curve (0, SETUP_GAIN_YAW, 100, 32767, 0, 0);
     
    	gyroscope.setZero (SETUP_ZERO_PITCH, SETUP_ZERO_ROLL, SETUP_ZERO_YAW);
     
    	motor1.hold (SETUP_HOLD_ESC);
    	motor1.min (SETUP_MIN_ESC);
    	motor1.max (SETUP_MAX_ESC);
    	motor2.hold (SETUP_HOLD_ESC);
    	motor2.min (SETUP_MIN_ESC);
    	motor2.max (SETUP_MAX_ESC);
    	motor3.hold (SETUP_HOLD_ESC);
    	motor3.min (SETUP_MIN_ESC);
    	motor3.max (SETUP_MAX_ESC);
    	motor4.hold (SETUP_HOLD_ESC);
    	motor4.min (SETUP_MIN_ESC);
    	motor4.max (SETUP_MAX_ESC);
     
    	PwmWrite::start (SETUP_FREQUENCY_ESC);
     
    	while (true)
    	{
    		gyroscope.state();
    		channelThrottle.state();
    		channelPitch.state();
    		channelRoll.state();
    		channelYaw.state();
    		channelHold.state();
    		channelOption.state();
     
    		if (channelHold.us > centerChannelHold)
    		{
    			motor1.moveHold();
    			motor2.moveHold();
    			motor3.moveHold();
    			motor4.moveHold();
    		}
    		else
    		{
    			mixThrottle = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_MIN_ESC, SETUP_MAX_ESC, 0);
     
    			mixMotor1 = mixThrottle;
    			mixMotor2 = mixThrottle;
    			mixMotor3 = mixThrottle;
    			mixMotor4 = mixThrottle;
     
    			mixMinClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_PITCH, 0);
    			mixMaxClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_PITCH, 0, 0);
    			mixPitchOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_PITCH, channelPitch.us, SETUP_MAX_CHANNEL_PITCH, -speedPitch, speedPitch, 0);
    			mixThrustPitchGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRxGyro, gainMinRxGyro, 0);
    			mixMinRxGyro = Math::wurve (-mixThrustPitchGain, gyroscope.rx + mixPitchOffsetGyro, mixThrustPitchGain, -mixMaxClearancePitch, 0, mixMinClearancePitch, 0, 0);
    			mixMaxRxGyro = Math::wurve (-mixThrustPitchGain, gyroscope.rx + mixPitchOffsetGyro, mixThrustPitchGain, -mixMinClearancePitch, 0, mixMaxClearancePitch, 0, 0);
     
    			mixMotor1 -= mixMinRxGyro;
    			mixMotor2 -= mixMinRxGyro;
    			mixMotor3 += mixMaxRxGyro;
    			mixMotor4 += mixMaxRxGyro;
     
    			mixMinClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_ROLL, 0);
    			mixMaxClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_ROLL, 0, 0);
    			mixRollOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_ROLL, channelRoll.us, SETUP_MAX_CHANNEL_ROLL, -speedRoll, speedRoll, 0);
    			mixThrustRollGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRyGyro, gainMinRyGyro, 0);
    			mixMinRyGyro = Math::wurve (-mixThrustRollGain, gyroscope.ry - mixRollOffsetGyro, mixThrustRollGain, -mixMaxClearanceRoll, 0, mixMinClearanceRoll, 0, 0);
    			mixMaxRyGyro = Math::wurve (-mixThrustRollGain, gyroscope.ry - mixRollOffsetGyro, mixThrustRollGain, -mixMinClearanceRoll, 0, mixMaxClearanceRoll, 0, 0);
     
    			mixMotor1 -= mixMinRyGyro;
    			mixMotor2 += mixMaxRyGyro;
    			mixMotor3 -= mixMinRyGyro;
    			mixMotor4 += mixMaxRyGyro;
     
    			mixMinClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_YAW, 0);
    			mixMaxClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_YAW, 0, 0);
    			mixYawOffsetGyro = Math::curve (SETUP_MIN_CHANNEL_YAW, channelYaw.us, SETUP_MAX_CHANNEL_YAW, -speedYaw, speedYaw, 0);
    			mixInertiaYawGain = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRzGyro, gainMinRzGyro, 0);
    			mixMinRzGyro = Math::wurve (-mixInertiaYawGain, gyroscope.rz + mixYawOffsetGyro, mixInertiaYawGain, -mixMaxClearanceYaw, 0, mixMinClearanceYaw, 0, 0);
    			mixMaxRzGyro = Math::wurve (-mixInertiaYawGain, gyroscope.rz + mixYawOffsetGyro, mixInertiaYawGain, -mixMinClearanceYaw, 0, mixMaxClearanceYaw, 0, 0);
     
    			mixMotor1 -= mixMinRzGyro;
    			mixMotor2 += mixMaxRzGyro;
    			mixMotor3 += mixMaxRzGyro;
    			mixMotor4 -= mixMinRzGyro;
     
    			motor1.pulse (mixMotor1);
    			motor2.pulse (mixMotor2);
    			motor3.pulse (mixMotor3);
    			motor4.pulse (mixMotor4);
    		}
    	}
     
    	return 0;
    }
    Vid�o:



    N'h�sitez pas si vous avez des questions ou des id�es

  12. #12
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Dans la nouvelle version de ma biblioth�que j'ai inclus la gestion de 2 nouveaux composants:
    le gyroscope/magn�tom�tre BNO055
    et le barom�tre BMP180

    J'ai cr�� avec ce gyro un mode auto pilote tr�s robuste (horizon artificiel) pour d�butant pour piloter le quadri-h�licopt�re, je le publierais bient�t pour ceux qui veulent une fonction d�butant !

    Je ferais �galement des tests en vol avec le barom�tre pour mesurer l'altitude.

    J'ai d'autres composants � inclure prochainement � la biblioth�que:
    le NRF24L01P pour communiquer en 2.4Ghz

  13. #13
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    (toujours en pure c++)
    BNO055 et BMP180 int�gr�s et fonctionnels
    (j'ai fait plusieurs vols avec ce nouveau gyro)

    Premi�re communication 2.4Ghz r�ussie avec le NRF24L01P

    Je vous tiendrai inform�s de la suite (projet de r�aliser une radiocommande 2.4ghz).

  14. #14
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Exemple de radiocommande une voie avec ma biblioth�que et le composant nrf24l01p ! ^_^

    Imaginons que vous voulez transmettre la valeur d'un potentiom�tre � votre mod�le, �a donne ceci:

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #include "../module/Nrf24L01P.h"
    #include "../module/AnalogRead.h"
     
    int main()
    {
    	Nrf24L01P canal = Nrf24L01P (1);
    	AnalogRead potar = AnalogRead (15);
     
    	Nrf24L01P::start (1, 86400312, true);
     
    	while (true)
    	{
    		potar.state();
     
    		canal.transmit (potar.value);
    	}
     
    	return 0;
    }
    Et � l'autre bout, on fait bouger un servo avec la valeur du potentiom�tre qu'on re�ois par radio:

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    #include "../module/Nrf24L01P.h"
    #include "../module/PwmWrite.h"
     
    int main()
    {
    	Nrf24L01P canal = Nrf24L01P (1);
    	PwmWrite servo = PwmWrite (1, 0, 500, 1000);
     
    	Nrf24L01P::start (1, 86400312, true);
    	PwmWrite::start (50);
     
    	while (true)
    	{
    		canal.receive();
     
    		servo.pulse (canal.value);
    	}
     
    	return 0;
    }
    C'est pas plus compliqu� que �a, mais avec ce modeste code vous avez d�j� une radiocommande 1 voie

    A noter que "86400312" c'est un identifiant unique sur 32 bits (une cl� r�seau si vous voulez), que vous choisissez � votre guise pour s�curiser la communication entre les deux nrf24l01p.

    Les possibilit�s sont vraiment grandes, vous pouvez �mettre, transmettre � la suite dans n'importe quel ordre, j'ai essay� par exemple des configurations un peu d�licates � savoir:
    incr�ment d'une valeur (par exemple le temps qui passe)
    transmission de cette valeur d'un module 1 � un autre module 2
    r�ception de la valeur depuis le module 2 puis �mission vers le module 1
    r��mission de la valeur re�ue du module 1 vers le module 2
    r��mission de la valeur du module 2 vers le module 1
    affichage de la valeur sur un afficheur � leds via le module 1

    Et �a marche vraiment impec sans bugs, avec une latence de l'ordre du milli�me de secondes, et avec une port�e d'au moins 1km bien-s�r

    Les donn�es utiles qui transitent sont sur 32 bits sign�s (+ 8 bit pour le canal ou l'adresse).

    A vous de jouer

  15. #15
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    J'ai bien avanc� dans mon histoire de quadri auto-stable sur l'horizon, j'ai test� hier un nouveau code qui utilise la rapidit� du mpu6050 (le mode de vol normal c'est � dire acrobaties), et la fusion gyro+magn�tom�tre du bno055 pour avoir un pitch/roll verrouill� (le mode de vol horizon).

    On passe de l'un a l'autre avec un inter sur la radio, �a permet de voler en mode d�butant (horizon), c'est vraiment tr�s tr�s facile � piloter pour le coup, et quand on bascule l'inter on peut faire de la voltige (le roll et le pitch ne suivent plus l'horizon et ne sont plus bloqu�s a des angles min/max qu'on pr�d�fini).
    Cet inter permet aussi de sauver le mod�le si jamais on est perdu dans nos manches (ca remet le quadri a plat), j'ai pas encore test� �a en vol, mettre le quadri sur le dos et basculer l'inter horizon, mais �a ne serait tarder.

    J'ai fait une vid�o pour vous montrer ce mode:



    Et une nouveaut� sinon: � la "demande" d'un youtubeur, j'ai cr�� le bout de code qu'il faut pour faire fonctioner le magn�tom�tre Hmc5883L.
    -> https://cdn-shop.adafruit.com/datasheet ... ass_IC.pdf

    C'est maintenant inclus dans ma biblioth�que: http://sylvainmahe.xyz/data/module.zip
    Cela retourne les valeurs en gauss (puisque le datasheet parle de gauss j'ai mi �a dans cette unit�), � noter que 1 gauss = 100 micro tesla.

    Voila pour l'instant (en presque 2 ans de travail en solo) tout ce qui est cr�� comme classes dans ma biblioth�que:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    #include "../module/GpioRead.h"
    #include "../module/GpioWrite.h"
    #include "../module/AnalogRead.h"
    #include "../module/InterruptRead.h"
    #include "../module/PwmRead.h"
    #include "../module/PwmWrite.h"
    #include "../module/SoundWrite.h"
     
    #include "../module/Timer.h"
    #include "../module/Delay.h"
     
    #include "../module/Math.h"
    #include "../module/Iteration.h"
    #include "../module/Average.h"
    #include "../module/Hysteresis.h"
    #include "../module/Random.h"
     
    #include "../module/Max7219.h"
    #include "../module/Mpu6050.h"
    #include "../module/Bno055.h"
    #include "../module/Hmc5883L.h"
    #include "../module/Bmp180.h"
    #include "../module/Nrf24L01P.h"
     
    #include "../module/Network.h"
     
    #include "../module/Memory.h"
    #include "../module/Power.h"
    #include "../module/Tool.h"
    Vous pouvez faire beaucoup de projets avec �a et l'atmega328p-pu.

  16. #16
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut


    Nom : DSC02048resized.jpg
Affichages : 1420
Taille : 510,8 KoNom : DSC02050resized.jpg
Affichages : 1416
Taille : 192,8 Ko

  17. #17
    Membre averti
    Inscrit en
    F�vrier 2006
    Messages
    20
    D�tails du profil
    Informations forums :
    Inscription : F�vrier 2006
    Messages : 20
    Par d�faut
    Bonjour,
    Bravo super boulot.
    Je ne trouve pas ton code complet pour la gestion quadricopt�re, ou alors je suis mal voyant
    J'ai download� le module mais pas vu le code applicatif du drone
    Merci

  18. #18
    Membre confirm�

    Homme Profil pro
    �tudiant
    Inscrit en
    Septembre 2015
    Messages
    14
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Septembre 2015
    Messages : 14
    Par d�faut
    Bonjour theoldisgood, merci pour le commentaire.

    Alors d�sol� pour les liens cass�s, il doit y en avoir beaucoup car j'ai refait (ou fait le mot est plus juste vu ce que c'�tait avant) un nouveau site internet sous la forme d'un blog.

    Du coup je copie colle le code source du quadri ici:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    #include "../module/Delay.h"
    #include "../module/Random.h"
    #include "../module/Math.h"
    #include "../module/Filter.h"
    #include "../module/SoundWrite.h"
    #include "../module/PwmWrite.h"
    #include "../module/PwmRead.h"
    #include "../module/Mpu6050.h"
     
    int main()
    {
    	unsigned char n = 0;
    	Delay delaySoundStartCondition = Delay (1000, false);
    	Mpu6050 gyroscope = Mpu6050 (0x68);
    	PwmRead channelThrottle = PwmRead (1, false);
    	float slowChannelThrottle = 0;
    	PwmRead channelPitch = PwmRead (2, false);
    	PwmRead channelRoll = PwmRead (3, false);
    	PwmRead channelYaw = PwmRead (4, false);
    	PwmRead channelHold = PwmRead (5, false);
    	float centerChannelHold = 0;
    	PwmWrite motor1 = PwmWrite (8, 0, 0, 0);
    	PwmWrite motor2 = PwmWrite (9, 0, 0, 0);
    	PwmWrite motor3 = PwmWrite (10, 0, 0, 0);
    	PwmWrite motor4 = PwmWrite (11, 0, 0, 0);
    	float mixThrottle = 0;
    	float mixThrustPitchGainSpeed = 0;
    	Filter mixLockPitchGainSpeed = Filter (20);
    	float mixThrustRollGainSpeed = 0;
    	Filter mixLockRollGainSpeed = Filter (20);
    	float mixInertiaYawGainSpeed = 0;
    	Filter mixLockYawGainSpeed = Filter (100);
    	float mixMinClearancePitch = 0;
    	float mixMaxClearancePitch = 0;
    	float mixMinClearanceRoll = 0;
    	float mixMaxClearanceRoll = 0;
    	float mixMinClearanceYaw = 0;
    	float mixMaxClearanceYaw = 0;
    	float mixPitchOffsetSpeed = 0;
    	float mixRollOffsetSpeed = 0;
    	float mixYawOffsetSpeed = 0;
    	float thrustGainSpeedPitch = 0;
    	float thrustGainSpeedRoll = 0;
    	float inertiaGainSpeedYaw = 0;
    	float gainMinRxSpeed = 0;
    	float gainMaxRxSpeed = 0;
    	float gainLockRxSpeed = 0;
    	float gainMinRySpeed = 0;
    	float gainMaxRySpeed = 0;
    	float gainLockRySpeed = 0;
    	float gainMinRzSpeed = 0;
    	float gainMaxRzSpeed = 0;
    	float gainLockRzSpeed = 0;
    	float mixMinRxMotor = 0;
    	float mixMaxRxMotor = 0;
    	float mixMinRyMotor = 0;
    	float mixMaxRyMotor = 0;
    	float mixMinRzMotor = 0;
    	float mixMaxRzMotor = 0;
    	float mixMotor1 = 0;
    	float mixMotor2 = 0;
    	float mixMotor3 = 0;
    	float mixMotor4 = 0;
    	const unsigned int SETUP_MIN_CHANNEL_THROTTLE = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_THROTTLE = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_PITCH = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_PITCH = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_ROLL = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_ROLL = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_YAW = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_YAW = 2000;
    	const unsigned int SETUP_MIN_CHANNEL_HOLD = 1000;
    	const unsigned int SETUP_MAX_CHANNEL_HOLD = 2000;
    	const unsigned int SETUP_FREQUENCY_ESC = 125;
    	const unsigned int SETUP_HOLD_ESC = 950;
    	const unsigned int SETUP_MIN_ESC = 1050;
    	const unsigned int SETUP_MAX_ESC = 1950;
    	const unsigned int SETUP_TRAVEL_PITCH = 250;
    	const unsigned int SETUP_TRAVEL_ROLL = 250;
    	const unsigned int SETUP_TRAVEL_YAW = 400;
    	const signed int SETUP_SPEED_PITCH = 320;
    	const signed int SETUP_SPEED_ROLL = 320;
    	const signed int SETUP_SPEED_YAW = 320;
    	const unsigned char SETUP_GAIN_SPEED_PITCH = 95;
    	const unsigned char SETUP_GAIN_SPEED_ROLL = 93;
    	const unsigned char SETUP_GAIN_SPEED_YAW = 96;
    	const unsigned char SETUP_THRUST_PROPELLER = 80;
    	const unsigned char SETUP_INERTIA_PROPELLER = 100;
    	const unsigned char SETUP_LOCK = 60;
     
    	SoundWrite::pin (13);
     
    	PwmRead::start (100);
     
    	while (channelThrottle.us == 0 || channelPitch.us == 0 || channelRoll.us == 0 || channelYaw.us == 0 || channelHold.us == 0)
    	{
    		channelThrottle.read();
    		channelPitch.read();
    		channelRoll.read();
    		channelYaw.read();
    		channelHold.read();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::playKey();
    		}
    	}
     
    	slowChannelThrottle = float (SETUP_MIN_CHANNEL_THROTTLE) + ((float (SETUP_MAX_CHANNEL_THROTTLE) - float (SETUP_MIN_CHANNEL_THROTTLE)) / 10.0);
    	centerChannelHold = Math::center (SETUP_MIN_CHANNEL_HOLD, SETUP_MAX_CHANNEL_HOLD);
     
    	delaySoundStartCondition.reset();
     
    	while (channelThrottle.us > slowChannelThrottle || channelHold.us < centerChannelHold)
    	{
    		channelThrottle.read();
    		channelHold.read();
     
    		delaySoundStartCondition.state();
     
    		if (delaySoundStartCondition.update == true)
    		{
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::key (0, 100);
    			SoundWrite::key (200, 100);
    			SoundWrite::playKey();
    		}
    	}
     
    	thrustGainSpeedPitch = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_SPEED_PITCH, 0);
    	gainMinRxSpeed = Math::curve (0, thrustGainSpeedPitch, 100, 2000, 0, 0);
    	gainMaxRxSpeed = Math::curve (0, SETUP_GAIN_SPEED_PITCH, 100, 2000, 0, 0);
    	gainLockRxSpeed = Math::curve (0, SETUP_LOCK, 100, 1, 0, 0);
     
    	thrustGainSpeedRoll = Math::curve (0, SETUP_THRUST_PROPELLER, 100, 0, SETUP_GAIN_SPEED_ROLL, 0);
    	gainMinRySpeed = Math::curve (0, thrustGainSpeedRoll, 100, 2000, 0, 0);
    	gainMaxRySpeed = Math::curve (0, SETUP_GAIN_SPEED_ROLL, 100, 2000, 0, 0);
    	gainLockRySpeed = Math::curve (0, SETUP_LOCK, 100, 1, 0, 0);
     
    	inertiaGainSpeedYaw = Math::curve (0, SETUP_INERTIA_PROPELLER, 100, 0, SETUP_GAIN_SPEED_YAW, 0);
    	gainMinRzSpeed = Math::curve (0, inertiaGainSpeedYaw, 100, 2000, 0, 0);
    	gainMaxRzSpeed = Math::curve (0, SETUP_GAIN_SPEED_YAW, 100, 2000, 0, 0);
    	gainLockRzSpeed = Math::curve (0, SETUP_LOCK, 100, 1, 0, 0);
     
    	motor1.hold (SETUP_HOLD_ESC);
    	motor1.min (SETUP_MIN_ESC);
    	motor1.max (SETUP_MAX_ESC);
    	motor2.hold (SETUP_HOLD_ESC);
    	motor2.min (SETUP_MIN_ESC);
    	motor2.max (SETUP_MAX_ESC);
    	motor3.hold (SETUP_HOLD_ESC);
    	motor3.min (SETUP_MIN_ESC);
    	motor3.max (SETUP_MAX_ESC);
    	motor4.hold (SETUP_HOLD_ESC);
    	motor4.min (SETUP_MIN_ESC);
    	motor4.max (SETUP_MAX_ESC);
     
    	PwmWrite::start (SETUP_FREQUENCY_ESC);
     
    	motor1.moveHold();
    	motor2.moveHold();
    	motor3.moveHold();
    	motor4.moveHold();
     
    	Random::seed (15);
     
    	for (n = 0; n < 16; n++)
    	{
    		if (n != 0)
    		{
    			SoundWrite::key (0, Random::integer (25, 75));
    		}
     
    		SoundWrite::key (Random::integer (70, 3000), Random::integer (25, 75));
    	}
     
    	SoundWrite::playKey();
     
    	while (true)
    	{
    		channelThrottle.read();
    		channelPitch.read();
    		channelRoll.read();
    		channelYaw.read();
    		channelHold.read();
     
    		if (channelHold.us > centerChannelHold)
    		{
    			motor1.moveHold();
    			motor2.moveHold();
    			motor3.moveHold();
    			motor4.moveHold();
    		}
    		else
    		{
    			gyroscope.readRotation();
     
    			mixThrottle = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_MIN_ESC, SETUP_MAX_ESC, 0);
     
    			mixMotor1 = mixThrottle;
    			mixMotor2 = mixThrottle;
    			mixMotor3 = mixThrottle;
    			mixMotor4 = mixThrottle;
     
    			mixMinClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_PITCH, 0);
    			mixMaxClearancePitch = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_PITCH, 0, 0);
    			mixPitchOffsetSpeed = Math::curve (SETUP_MIN_CHANNEL_PITCH, channelPitch.us, SETUP_MAX_CHANNEL_PITCH, -SETUP_SPEED_PITCH, SETUP_SPEED_PITCH, 0);
    			mixThrustPitchGainSpeed = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRxSpeed, gainMinRxSpeed, 0);
    			mixLockPitchGainSpeed.set (Math::wurve (SETUP_MIN_CHANNEL_PITCH, channelPitch.us, SETUP_MAX_CHANNEL_PITCH, gainLockRxSpeed, 1, gainLockRxSpeed, 0, 0));
    			mixThrustPitchGainSpeed *= mixLockPitchGainSpeed.value;
    			mixMinRxMotor = Math::wurve (-mixThrustPitchGainSpeed, gyroscope.rx + mixPitchOffsetSpeed, mixThrustPitchGainSpeed, -mixMaxClearancePitch, 0, mixMinClearancePitch, 0, 0);
    			mixMaxRxMotor = Math::wurve (-mixThrustPitchGainSpeed, gyroscope.rx + mixPitchOffsetSpeed, mixThrustPitchGainSpeed, -mixMinClearancePitch, 0, mixMaxClearancePitch, 0, 0);
     
    			mixMotor1 -= mixMinRxMotor;
    			mixMotor2 -= mixMinRxMotor;
    			mixMotor3 += mixMaxRxMotor;
    			mixMotor4 += mixMaxRxMotor;
     
    			mixMinClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_ROLL, 0);
    			mixMaxClearanceRoll = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_ROLL, 0, 0);
    			mixRollOffsetSpeed = Math::curve (SETUP_MIN_CHANNEL_ROLL, channelRoll.us, SETUP_MAX_CHANNEL_ROLL, -SETUP_SPEED_ROLL, SETUP_SPEED_ROLL, 0);
    			mixThrustRollGainSpeed = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRySpeed, gainMinRySpeed, 0);
    			mixLockRollGainSpeed.set (Math::wurve (SETUP_MIN_CHANNEL_ROLL, channelRoll.us, SETUP_MAX_CHANNEL_ROLL, gainLockRySpeed, 1, gainLockRySpeed, 0, 0));
    			mixThrustRollGainSpeed *= mixLockRollGainSpeed.value;
    			mixMinRyMotor = Math::wurve (-mixThrustRollGainSpeed, gyroscope.ry - mixRollOffsetSpeed, mixThrustRollGainSpeed, -mixMaxClearanceRoll, 0, mixMinClearanceRoll, 0, 0);
    			mixMaxRyMotor = Math::wurve (-mixThrustRollGainSpeed, gyroscope.ry - mixRollOffsetSpeed, mixThrustRollGainSpeed, -mixMinClearanceRoll, 0, mixMaxClearanceRoll, 0, 0);
     
    			mixMotor1 -= mixMinRyMotor;
    			mixMotor2 += mixMaxRyMotor;
    			mixMotor3 -= mixMinRyMotor;
    			mixMotor4 += mixMaxRyMotor;
     
    			mixMinClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, 0, SETUP_TRAVEL_YAW, 0);
    			mixMaxClearanceYaw = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, SETUP_TRAVEL_YAW, 0, 0);
    			mixYawOffsetSpeed = Math::curve (SETUP_MIN_CHANNEL_YAW, channelYaw.us, SETUP_MAX_CHANNEL_YAW, -SETUP_SPEED_YAW, SETUP_SPEED_YAW, 0);
    			mixInertiaYawGainSpeed = Math::curve (SETUP_MIN_CHANNEL_THROTTLE, channelThrottle.us, SETUP_MAX_CHANNEL_THROTTLE, gainMaxRzSpeed, gainMinRzSpeed, 0);
    			mixLockYawGainSpeed.set (Math::wurve (SETUP_MIN_CHANNEL_YAW, channelYaw.us, SETUP_MAX_CHANNEL_YAW, gainLockRzSpeed, 1, gainLockRzSpeed, 0, 0));
    			mixInertiaYawGainSpeed *= mixLockYawGainSpeed.value;
    			mixMinRzMotor = Math::wurve (-mixInertiaYawGainSpeed, gyroscope.rz + mixYawOffsetSpeed, mixInertiaYawGainSpeed, -mixMaxClearanceYaw, 0, mixMinClearanceYaw, 0, 0);
    			mixMaxRzMotor = Math::wurve (-mixInertiaYawGainSpeed, gyroscope.rz + mixYawOffsetSpeed, mixInertiaYawGainSpeed, -mixMinClearanceYaw, 0, mixMaxClearanceYaw, 0, 0);
     
    			mixMotor1 -= mixMinRzMotor;
    			mixMotor2 += mixMaxRzMotor;
    			mixMotor3 += mixMaxRzMotor;
    			mixMotor4 -= mixMinRzMotor;
     
    			motor1.us (Math::round (mixMotor1));
    			motor2.us (Math::round (mixMotor2));
    			motor3.us (Math::round (mixMotor3));
    			motor4.us (Math::round (mixMotor4));
    		}
    	}
     
    	return 0;
    }
    Les param�tres (SETUP) sont r�gl�s pour mon quadri 400x400mm, moteur mn2206, h�lices 6 pouces.

    Normalement si j'ai le temps, prochainement sur mon blog je devrais faire un article sur le quadri, en gros � la suite du dernier article: http://sylvainmahe.xyz/


    N'h�sites pas si tu as des questions

Discussions similaires

  1. [C# 2.0]Executer du code sans afficher de fen�tre
    Par NicolasJolet dans le forum Windows Forms
    R�ponses: 10
    Dernier message: 20/09/2006, 13h37
  2. Difficult� avec un code sans algo
    Par panda31 dans le forum Algorithmes et structures de donn�es
    R�ponses: 10
    Dernier message: 07/04/2006, 09h43
  3. Profiler du code...sans profiler :s
    Par progfou dans le forum C
    R�ponses: 2
    Dernier message: 29/03/2006, 08h48
  4. [Mail] exit du code sans sortir du html...
    Par sam01 dans le forum Langage
    R�ponses: 4
    Dernier message: 01/03/2006, 23h04
  5. R�ponses: 3
    Dernier message: 27/01/2006, 15h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo