hello everyone, im a beginner and i don't understand this error (concerning the last line) :
Arduino : 1.8.10 (Windows 7), Carte : "Arduino Mega ADK"
programme_test_asservissment:163:2: error: expected declaration before '}' token
}}
^
Plusieurs bibliothèque trouvées pour "Wire.h"
Utilisé : C:\Program
Plusieurs bibliothèque trouvées pour "SparkFunLSM9DS1.h"
Utilisé : C:\Users\vpaulinefr\Documents\Arduino\libraries\SparkFun_LSM9DS1_Arduino_Library-master
Plusieurs bibliothèque trouvées pour "SPI.h"
Utilisé : C:\Program
exit status 1
expected declaration before '}' token
Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.
Here is the code
// Appel des bibliothèques
#include <Wire.h>
#include <SparkFunLSM9DS1.h>
// Déclaration des adresses du module
#define LSM9DS1_M 0x1E
#define LSM9DS1_AG 0x6B
LSM9DS1 imu; // création de l'objet imu
// Configuration du module
#define PRINT_CALCULATED
#define PRINT_SPEED 250
static unsigned long lastPrint = 0;
#define DECLINATION -0.33 // Declinaison (en degrés) pour Paris.
float b = 0.0;
float erreur_precedente = 0.0;
void setup()
{
// put your setup code here, to run once:
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
Serial.begin(115200); // initialisation de la liaison série
imu.settings.device.commInterface = IMU_MODE_I2C; // initialisation du module
imu.settings.device.mAddress = LSM9DS1_M;
imu.settings.device.agAddress = LSM9DS1_AG;
if (!imu.begin())
{
Serial.println("Probleme de communication avec le LSM9DS1.");
while (1);
}
}
void loop()
{
// put your main code here, to run repeatedly:
float a = angle();
if (abs(a) > 160)
{
moteur();
}
Serial.print("roll: "); Serial.print(a, 2);
}
// ON DEFINIT LA FONCTION RETOURNANT L'ANGLE //
float angle()
{
if ( imu.accelAvailable() )
{
imu.readAccel(); // acquisition des données de l'accéléromètre
}
if ( imu.magAvailable() )
{
imu.readMag(); // acquisition du magnétomètre
}
if ((lastPrint + PRINT_SPEED) < millis())
{
float angle = printAttitude(imu.ax, imu.ay, imu.az, -imu.my, -imu.mx, imu.mz);
Serial.println();
lastPrint = millis();
return (angle);
}
}
// ON DEFINIT PRINT ATTITUDE //
float printAttitude(float ax, float ay, float az, float mx, float my, float mz)
{
float roll = atan2(ay, az);
roll *= 180.0 / PI;
return (roll);
}
//
void moteur1(const int a)
{
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
analogWrite(3, 185);
delay(100 * a);
digitalWrite(9, HIGH);
}
void moteur2(const float a)
{
digitalWrite(12, LOW);
digitalWrite(9, LOW);
analogWrite(3, 185);
delay(100 * abs(a));
digitalWrite(9, HIGH);
}
// on definit la fonction moteur //
void moteur()
{
//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
delay(3000);
digitalWrite(9, HIGH); //Eengage the Brake for Channel A
delay(1000);
//backward @ half speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed
delay(3000);
digitalWrite(9, HIGH); //Eengage the Brake for Channel A
delay(1000);
}
//
void asservissement() {
float erreur = angle();
float b = erreur - erreur_precedente;
float theta = 2 * erreur + 2 * b;
if (erreur > 0);
{
moteur1(theta);
}
if (erreur < 0)
{
moteur2(theta);
}
erreur_precedente = erreur;
}}