update
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
|
||||
Import("env", "projenv")
|
||||
import subprocess
|
||||
|
||||
def dw_stop(*args, **kwargs):
|
||||
print("Disable debugWIRE")
|
||||
tc = env.Dump().find('toolchain-atmelavr')
|
||||
sl = env.Dump().find('/',tc+1)
|
||||
if (sl > tc and sl >= 0 and tc >= 0):
|
||||
toolchain = env.Dump()[tc:sl]
|
||||
else:
|
||||
toolchain = "toolchain-atmelavr-original"
|
||||
gdb = [env['PROJECT_PACKAGES_DIR'] + '/' + toolchain + '/bin/avr-gdb' ]
|
||||
gdb += ["-batch-silent", "-b", "115200", "-ex", "target remote " + \
|
||||
env['UPLOAD_PORT'], "-ex", "monitor dwoff"]
|
||||
try:
|
||||
ret = subprocess.call(gdb, shell=False)
|
||||
print("DWEN fuse disabled")
|
||||
except subprocess.CalledProcessError as exc:
|
||||
print("Call to disable debugWIRE failed with " + str(exc))
|
||||
|
||||
def dw_erase(*args, **kwargs):
|
||||
print("Erase Chip")
|
||||
tc = env.Dump().find('toolchain-atmelavr')
|
||||
sl = env.Dump().find('/',tc+1)
|
||||
if (sl > tc and sl >= 0 and tc >= 0):
|
||||
toolchain = env.Dump()[tc:sl]
|
||||
else:
|
||||
toolchain = "toolchain-atmelavr-original"
|
||||
gdb = [env['PROJECT_PACKAGES_DIR'] + '/' + toolchain + '/bin/avr-gdb' ]
|
||||
gdb += ["-batch-silent", "-b", "115200", "-ex", "target remote " + \
|
||||
env['UPLOAD_PORT'], "-ex", "monitor erase"]
|
||||
try:
|
||||
ret = subprocess.call(gdb, shell=False)
|
||||
print("Chip erased and lockbits reset")
|
||||
except subprocess.CalledProcessError as exc:
|
||||
print("Call to Erease Chip failed with " + str(exc))
|
||||
|
||||
|
||||
|
||||
env.AddCustomTarget(
|
||||
name="dwstop",
|
||||
dependencies=None,
|
||||
actions=[
|
||||
dw_stop
|
||||
],
|
||||
title="DebugWIRE Disable",
|
||||
description="Disables debugWIRE mode and re-enables the reset line"
|
||||
)
|
||||
|
||||
env.AddCustomTarget(
|
||||
name="dwerase",
|
||||
dependencies=None,
|
||||
actions=[
|
||||
dw_erase
|
||||
],
|
||||
title="Erase Chip",
|
||||
description="Erases chip including lock bits"
|
||||
)
|
||||
+44
-5
@@ -7,14 +7,25 @@
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
[platformio]
|
||||
description = Digitally Controlled Full Analog Gain Stage
|
||||
default_envs = uno
|
||||
|
||||
[env:uno]
|
||||
platform = atmelavr
|
||||
board = uno
|
||||
framework = arduino
|
||||
; upload_port = /dev/cu.usbmodem1101
|
||||
monitor_speed = 115200
|
||||
monitor_filters = colorize
|
||||
upload_port = /dev/cu.usbmodem1101
|
||||
platform_packages = [email protected]
|
||||
board_build.mcu = atmega328p
|
||||
board_build.f_cpu = 16000000L
|
||||
debug_build_flags =
|
||||
-DAVR8_BREAKPOINT_MODE=1
|
||||
-Og
|
||||
-g
|
||||
-fno-lto
|
||||
debug_port = /dev/cu.usbmodem1101
|
||||
|
||||
lib_deps =
|
||||
sparkfun/SparkFun MiniMoto@^1.1.0
|
||||
Wire
|
||||
@@ -27,6 +38,34 @@ lib_deps =
|
||||
r-downing/AutoPID @ ^1.0.3
|
||||
dlloydev/QuickPID @ ^3.1.4
|
||||
powerbroker2/FireTimer @ ^1.0.5
|
||||
jdolinay/avr-debugger @ ~1.4
|
||||
|
||||
[env:debug]
|
||||
extends = env:uno
|
||||
build_type = debug
|
||||
extra_scripts = extra_script.py
|
||||
|
||||
platform_packages = [email protected]
|
||||
board_build.mcu = atmega328p
|
||||
board_build.f_cpu = 16000000L
|
||||
|
||||
debug_tool = custom
|
||||
|
||||
debug_load_cmds = load
|
||||
|
||||
debug_init_cmds =
|
||||
define pio_reset_halt_target
|
||||
monitor reset
|
||||
end
|
||||
define pio_reset_run_target
|
||||
monitor reset
|
||||
detach
|
||||
end
|
||||
file "$PROG_PATH"
|
||||
set serial baud 115200
|
||||
target remote $DEBUG_PORT
|
||||
monitor dwconnect
|
||||
load
|
||||
$INIT_BREAK
|
||||
|
||||
|
||||
[platformio]
|
||||
description = Digitally Controlled Full Analog Gain Stage
|
||||
|
||||
+29
-47
@@ -11,11 +11,11 @@ Bounce2::Button const_out_L = Bounce2::Button(); // instance du bouton const_out
|
||||
Bounce2::Button const_out_R = Bounce2::Button(); // instance du bouton const_out_R
|
||||
Bounce2::Button stereo_link = Bounce2::Button(); // instance du bouton stereo_link
|
||||
|
||||
void lecture_switch(); // lecture bouton
|
||||
void bouton_set(); // gestion des boutons
|
||||
void stereo_link_set(); // gestion du bouton stereo_link
|
||||
void const_out_L_set(); // gestion du bouton const_out_L
|
||||
void const_out_R_set(); // gestion du bouton const_out_R
|
||||
void lecture_switch(); // lecture bouton
|
||||
void bouton_set(); // gestion des boutons
|
||||
void stereo_link_set(); // gestion du bouton stereo_link
|
||||
void const_out_L_set(); // gestion du bouton const_out_L
|
||||
void const_out_R_set(); // gestion du bouton const_out_R
|
||||
|
||||
void lecture_switch()
|
||||
{
|
||||
@@ -44,100 +44,82 @@ void bouton_set()
|
||||
if (stereo_link_state_old != stereo_link_state) // si changement d'état du bouton stereo_link
|
||||
{
|
||||
stereo_link_set(); // gestion du bouton stereo_link
|
||||
state_button_change = 1; // il y a changement d'état d'un bouton
|
||||
state_button_change = true; // il y a changement d'état d'un bouton
|
||||
stereo_link_state_old = stereo_link_state; // sauvegarde état bouton stereo_link
|
||||
}
|
||||
if (const_out_L_state_old != const_out_L_state) // si changement d'état du bouton const_out_L
|
||||
{
|
||||
const_out_L_set(); // gestion du bouton const_out_L
|
||||
if (stereo_link_state == 1) // si bouton stereo_link appuyé
|
||||
const_out_L_set(); // gestion du bouton const_out_L
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
const_out_R_state = const_out_L_state; // copie état bouton const_out_L
|
||||
const_out_R_state_old = const_out_L_state; // sauvegarde copie état bouton const_out_R
|
||||
}
|
||||
state_button_change = 1; // il y a changement d'état d'un bouton
|
||||
state_button_change = true; // il y a changement d'état d'un bouton
|
||||
const_out_L_state_old = const_out_L_state; // sauvegarde état bouton const_out_L
|
||||
}
|
||||
if (const_out_R_state_old != const_out_R_state) // si changement d'état du bouton const_out_R
|
||||
{
|
||||
const_out_R_set(); // gestion du bouton const_out_R
|
||||
if (stereo_link_state == 1) // si bouton stereo_link appuyé
|
||||
const_out_R_set(); // gestion du bouton const_out_R
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
const_out_L_state = const_out_R_state; // copie état bouton const_out_R
|
||||
const_out_L_state_old = const_out_R_state; // sauvegarde copie état bouton const_out_L
|
||||
}
|
||||
state_button_change = 1; // il y a changement d'état d'un bouton
|
||||
state_button_change = true; // il y a changement d'état d'un bouton
|
||||
const_out_R_state_old = const_out_R_state; // sauvegarde état bouton const_out_R
|
||||
}
|
||||
|
||||
#ifdef DEBUG_BOUTON // si DEBUG activé
|
||||
if (state_button_change == true)
|
||||
{
|
||||
Log.notice("bouton_change" CR);
|
||||
Log.trace("const_out_L_state = %d" CR, const_out_L_state);
|
||||
Log.trace("const_out_R_state = %d" CR, const_out_R_state);
|
||||
Log.trace("stereo_link_state = %d" CR, stereo_link_state);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void stereo_link_set() // gestion du bouton stereo_link
|
||||
{
|
||||
#ifdef DEBUG_BOUTON // si DEBUG activé
|
||||
Log.notice(F(CR "void stereo_link_set()" CR));
|
||||
#endif
|
||||
if (stereo_link_state == 1) // si bouton stereo_link appuyé
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
if (const_out_L_state == 1 || const_out_R_state == 1) // si bouton const_out_L ou R appuyé
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
if (const_out_L_state == true || const_out_R_state == true) // si bouton const_out_L ou R appuyé
|
||||
{
|
||||
const_out_L_state = 1;
|
||||
const_out_R_state = 1;
|
||||
const_out_L_state = true;
|
||||
const_out_R_state = true;
|
||||
}
|
||||
}
|
||||
else // si bouton stereo_link relaché
|
||||
{
|
||||
digitalWrite(stereo_link_led, LOW); // éteint LED stereo_link
|
||||
if (const_out_L_state == 0)
|
||||
for (int i = 0; i < 3; i++) // pour chaque moteur
|
||||
{
|
||||
motor[0].stop(); // arrêt moteur 0
|
||||
motor[1].stop(); // arrêt moteur 1
|
||||
motor[2].stop(); // arrêt moteur 2
|
||||
motor[3].stop(); // arrêt moteur 3
|
||||
motor[i].stop(); // arrêt moteur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void const_out_L_set() // gestion du bouton const_out_L
|
||||
{
|
||||
#ifdef DEBUG_BOUTON // si DEBUG activé
|
||||
Log.notice(F(CR "void const_out_L_set()" CR));
|
||||
#endif
|
||||
if (const_out_L_state == 1) // si bouton const_out_L appuyé
|
||||
if (const_out_L_state == true) // si bouton const_out_L appuyé
|
||||
{
|
||||
digitalWrite(const_out_L_led, HIGH); // allume LED const_out_L
|
||||
}
|
||||
else // si bouton const_out_L relaché
|
||||
{
|
||||
digitalWrite(const_out_L_led, LOW); // éteint LED const_out_L
|
||||
motor[0].stop(); // arrêt moteur 0
|
||||
motor[1].stop(); // arrêt moteur 1
|
||||
for (int i = 0; i < 1; i++) // pour chaque moteur
|
||||
{
|
||||
motor[i].stop(); // arrêt moteur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void const_out_R_set() // gestion du bouton const_out_R
|
||||
{
|
||||
#ifdef DEBUG_BOUTON // si DEBUG activé
|
||||
Log.notice(F(CR "void const_out_R_set()" CR));
|
||||
#endif
|
||||
if (const_out_R_state == 1) // si bouton const_out_R appuyé
|
||||
if (const_out_R_state == true) // si bouton const_out_R appuyé
|
||||
{
|
||||
digitalWrite(const_out_R_led, HIGH); // allume LED const_out_R
|
||||
}
|
||||
else // si bouton const_out_R relaché
|
||||
{
|
||||
digitalWrite(const_out_R_led, LOW); // éteint LED const_out_R
|
||||
motor[2].stop(); // arrêt moteur 2
|
||||
motor[3].stop(); // arrêt moteur 3
|
||||
for (int i = 2; i < 3; i++) // pour chaque moteur
|
||||
{
|
||||
motor[i].stop(); // arrêt moteur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
|
||||
void consigne_set(); // calcul des consignes
|
||||
void motor_calc(int pot, int motor); // calcul des position de moteurs
|
||||
|
||||
void motor_calc(int pot, int motor) // calcul des consignes de moteurs et du flag de changement de position
|
||||
{
|
||||
lecture_pot(pot); // lecture des potentiomètres
|
||||
lecture_pot(motor); // lecture des potentiomètres
|
||||
position_set[pot] = position_lue[pot]; // set position potentiomètre gain et volume gauche et droit
|
||||
if (position_set[motor] > max_pot || position_set[motor] < min_pot) // si consigne est hors bornes
|
||||
{
|
||||
motor_change[motor] = false; // pas de changement de position du potentiomètre
|
||||
motor_change[pot] = false; // pas de changement de position du potentiomètre
|
||||
position_set[motor] = position_lue[motor];
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint(); // point d'arrêt pour le debug
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
else if (position_set[motor] > (position_lue[motor] + ECART_V_STOP) || position_set[motor] < (position_lue[motor] - ECART_V_STOP)) // si consigne n'est pas hors bornes
|
||||
{
|
||||
motor_change[motor] = true; // il y a changement de position du potentiomètre
|
||||
motor_change[pot] = false; // pas de changement de position du potentiomètre
|
||||
#ifdef PID
|
||||
myPID.SetMode(myPID.Control::timer); // mise du PID en mode automatique
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void consigne_set() // calcul des consignes de moteurs
|
||||
{
|
||||
if (const_out_L_state == true) // si bouton const_out_L appuyé
|
||||
{
|
||||
int gain = 0;
|
||||
int volume = 1;
|
||||
if (position_change[gain] == true) // si changement de position du potentiomètre de gain gauche
|
||||
{
|
||||
position_set[gain] = position_lue[gain];
|
||||
if (position_lue[gain] < position_memory[gain] - ECART_V_STOP)
|
||||
{
|
||||
position_set[volume] = position_memory[volume] + (position_memory[gain] - position_lue[gain]);
|
||||
}
|
||||
else if (position_lue[gain] > position_memory[gain] + ECART_V_STOP)
|
||||
{
|
||||
position_set[volume] = position_memory[volume] - (position_lue[gain] - position_memory[gain]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
motor_calc(gain, volume); // pot, motor
|
||||
}
|
||||
if (position_change[volume] == true) // si changement de position du potentiomètre de gain gauche
|
||||
{
|
||||
position_set[volume] = position_lue[volume];
|
||||
if (position_lue[volume] < position_memory[volume] - ECART_V_STOP)
|
||||
{
|
||||
position_set[gain] = position_memory[gain] + (position_memory[volume] - position_lue[volume]);
|
||||
}
|
||||
else if (position_lue[volume] > position_memory[volume] + ECART_V_STOP)
|
||||
{
|
||||
position_set[gain] = position_memory[gain] - (position_lue[volume] - position_memory[volume]);
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
motor_calc(volume, gain); // pot, motor
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (const_out_R_state == true) // si bouton const_out_R appuyé
|
||||
{
|
||||
}
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
if (const_out_R_state == true || const_out_L_state == true) // si bouton const_out_R ou const_out_L appuyé
|
||||
{
|
||||
}
|
||||
else if (const_out_R_state == true && const_out_L_state == true) // si uniquement stereo_link est appuyé
|
||||
{
|
||||
}
|
||||
else if (const_out_R_state == false && const_out_L_state == false) // si aucun bouton n'est appuyé
|
||||
{
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
-155
@@ -1,155 +0,0 @@
|
||||
|
||||
void diff_set(); // calcul des différences de valeurs
|
||||
void consigne_set(); // calcul des consignes de moteurs
|
||||
void consigne_calc(int pot, int motor, int position_calc); // calcul des consignes de moteurs
|
||||
|
||||
void diff_set() // calcul de la différence entre gain et volume
|
||||
{
|
||||
#ifdef DEBUG_DIFF // si DEBUG activé
|
||||
Log.notice(F("======= void diff set" CR));
|
||||
#endif
|
||||
if (const_out_L_state == 1) // si bouton const_out_L appuyé
|
||||
{
|
||||
for (int i = 0; i <= 1; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_change[i] = false;
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
diff_const_out_L = position_lue[0] - position_lue[1]; // calcul de la différence entre gain et volume gauche
|
||||
}
|
||||
|
||||
if (const_out_R_state == 1) // si bouton const_out_R appuyé
|
||||
{
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_change[i] = false;
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
diff_const_out_R = position_lue[2] - position_lue[3]; // calcul de la différence entre gain et volume droit
|
||||
}
|
||||
|
||||
if (stereo_link_state == 1) // si bouton stereo_link appuyé
|
||||
{
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_change[i] = false;
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
diff_gain = position_lue[0] - position_lue[2]; // calcul de la différence entre gain gauche et droit
|
||||
diff_vol = position_lue[1] - position_lue[3]; // calcul de la différence entre volume gauche et droit
|
||||
}
|
||||
#ifdef DEBUG_DIFF // si DEBUG activé
|
||||
Log.notice(F("diff_const_out_L = %d" CR), diff_const_out_L);
|
||||
Log.notice(F("diff_const_out_R = %d" CR), diff_const_out_R);
|
||||
Log.notice(F("diff_gain = %d" CR), diff_gain);
|
||||
Log.notice(F("diff_vol = %d" CR), diff_vol);
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void consign_calc(int pot, int motor, int position_calc) // calcul des consignes de moteurs
|
||||
{
|
||||
lecture_pot(pot); // lecture des potentiomètres
|
||||
lecture_pot(motor); // lecture des potentiomètres
|
||||
position_set[pot] = position_lue[pot]; // set position potentiomètre gain et volume gauche et droit
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
Log.notice(F("======= void consigne calc" CR));
|
||||
Log.notice(F("pot = %d position_lue[%d] = %d" CR), pot, pot, position_lue[pot]);
|
||||
Log.notice(F("pot = %d position_set[%d] = %d" CR), pot, pot, position_set[pot]);
|
||||
Log.notice(F("pot = %d position_save[%d] = %d" CR), pot, pot, position_save[pot]);
|
||||
Log.notice(F("motor = %d position_lue[%d] = %d" CR), motor, motor, position_lue[motor]);
|
||||
Log.notice(F("motor = %d position_set[%d] = %d" CR), motor, motor, position_set[motor]);
|
||||
Log.notice(F("motor = %d position_save[%d] = %d" CR), motor, motor, position_save[motor]);
|
||||
Log.notice(F("motor_change[%d] = %d" CR), motor, motor_change[motor]);
|
||||
Log.notice(F("pot motor_change[%d] = %d" CR), pot, motor_change[pot]);
|
||||
Log.notice(F("time elapsed= %d" CR), millis() - last_change_time);
|
||||
Log.notice(F("bounce_time_pot = %d" CR), bounce_time_pot);
|
||||
Log.notice(F("position_calc = %d" CR), position_calc);
|
||||
Log.notice(F("position_calc > (position_lue[motor] + ECRART_V_STOP) = %d" CR), position_calc > (position_lue[motor] + ECRART_V_STOP));
|
||||
Log.notice(F("position_calc < (position_lue[motor] - ECRART_V_STOP) = %d" CR), position_calc < (position_lue[motor] - ECRART_V_STOP));
|
||||
#endif
|
||||
// position_calc = 60
|
||||
// ecart +
|
||||
// ecart -
|
||||
// si changement de position du potentiomètre depuis plus de bounce_time_pot et moteur n'est pas entre consigne et ECRART_V_STOP
|
||||
if (motor_change[motor] == false && motor_change[pot] == false)
|
||||
{
|
||||
if (position_calc >= 1023 || position_calc <= 0) // si consigne n'est pas hors bornes
|
||||
{
|
||||
save_pot(pot); // sauvegarde position potentiomètre
|
||||
save_pot(motor); // sauvegarde position potentiomètre
|
||||
position_set[motor] = position_lue[motor];
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
Log.notice(F("======= void consigne HSHSHSHSHSSH calc" CR));
|
||||
Log.notice(F("diff_const_out_L = %d" CR), diff_const_out_L);
|
||||
Log.notice(F("============================> position_calc = %d" CR), position_calc);
|
||||
Log.notice(F("motor = %d" CR), motor);
|
||||
Log.notice(F("position_lue[motor] = %d" CR), position_lue[motor]);
|
||||
Log.notice(F("position_set[motor] = %d" CR), position_set[motor]);
|
||||
Log.notice(F("position_save[motor] = %d" CR), position_save[motor]);
|
||||
Log.notice(F("pot = %d" CR), pot);
|
||||
Log.notice(F("position_lue[pot] = %d" CR), position_lue[pot]);
|
||||
Log.notice(F("position_set[pot] = %d" CR), position_set[pot]);
|
||||
Log.notice(F("position_save[pot] = %d" CR), position_save[pot]);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
else if (position_calc > (position_lue[motor] + ECRART_V_STOP) || position_calc < (position_lue[motor] - ECRART_V_STOP)) // si consigne n'est pas hors bornes
|
||||
{
|
||||
position_set[motor] = position_calc; // set position potentiomètre volume gauche
|
||||
motor_change[motor] = true; // il y a changement de position du potentiomètre de volume gauche
|
||||
myPID.SetMode(myPID.Control::timer); // set PID en mode automatique
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
Log.notice(F("======= void consigne YES YES YES calc" CR));
|
||||
Log.notice(F("position_calc = %d" CR), position_calc);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void consigne_set() // calcul des consignes de moteurs
|
||||
{
|
||||
if (const_out_L_state == true) // si bouton const_out_L appuyé
|
||||
{
|
||||
if (state_pot_change[0] == true && motor_change[0] == false && motor_change[1] == false) // si changement de position du potentiomètre de gain gauche et que pas de moteur en mouvement
|
||||
{
|
||||
int pot = 0;
|
||||
int motor = 1;
|
||||
int position_calc = constrain((position_lue[pot] - diff_const_out_L), 0, 1023); // set position potentiomètre volume gauche
|
||||
consign_calc(pot, motor, position_calc);
|
||||
}
|
||||
if (state_pot_change[1] == true && motor_change[0] == false && motor_change[1] == false) // si changement de position du potentiomètre de volume gauche et que pas de moteur en mouvement
|
||||
{
|
||||
int pot = 1;
|
||||
int motor = 0;
|
||||
int position_calc = constrain((position_lue[pot] + diff_const_out_L), 0, 1023); // set position potentiomètre volume gauche
|
||||
consign_calc(pot, motor, position_calc);
|
||||
}
|
||||
}
|
||||
if (const_out_R_state == true) // si bouton const_out_R appuyé
|
||||
{
|
||||
}
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
if (const_out_R_state == true || const_out_L_state == true) // si bouton const_out_R ou const_out_L appuyé
|
||||
{
|
||||
}
|
||||
else if (const_out_R_state == true && const_out_L_state == true) // si uniquement stereo_link est appuyé
|
||||
{
|
||||
}
|
||||
else if (const_out_R_state == false && const_out_L_state == false) // si aucun bouton n'est appuyé
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
-114
@@ -19,26 +19,11 @@ tableau de valeurs (i) pour les relais, les valeurs de potentiomètre et les val
|
||||
// ******************** // #define DEBUG = INACTIF *******************************************************
|
||||
// ******************** #define DEBUG = ACTIF ************************************************************
|
||||
// *******************************************************************************************************
|
||||
#define DEBUG
|
||||
// #define DEBUG
|
||||
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
#include <ArduinoLog.h>
|
||||
// #define DEBUG_VOID
|
||||
#define DEBUG_LOOP
|
||||
// #define DEBUG_LOOP_HARD
|
||||
// #define DEBUG_POT
|
||||
// #define DEBUG_RELAIS
|
||||
// #define DEBUG_LECTURE
|
||||
// #define DEBUG_BOUTON
|
||||
#define DEBUG_MOTEUR
|
||||
#define DEBUG_MOTEUR_HARD
|
||||
bool count_motor = false;
|
||||
// #define DEBUG_VALEURS
|
||||
#define DEBUG_DIFF
|
||||
#define DEBUG_CONST
|
||||
#define DEBUG_PID
|
||||
|
||||
bool counter = true;
|
||||
#include "avr8-stub.h"
|
||||
#include "app_api.h" // only needed with flash breakpoints
|
||||
#endif
|
||||
|
||||
// *******************************************************************************************************
|
||||
@@ -56,7 +41,7 @@ bool counter = true;
|
||||
#include "bouton.h"
|
||||
#include "relais.h"
|
||||
#include "valeurs.h"
|
||||
#include "const_set.h"
|
||||
#include "consigne.h"
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** boucle setup ***********************************************
|
||||
@@ -64,17 +49,8 @@ bool counter = true;
|
||||
void setup()
|
||||
{
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
Serial.begin(115200);
|
||||
// Pass log level, whether to show log level, and print interface.
|
||||
// Available levels are:
|
||||
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
|
||||
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
|
||||
// this will significantly reduce your project size
|
||||
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
|
||||
Log.notice(F(CR "Hlabs controle de volume et de gain" CR));
|
||||
Log.notice("par Clément SAILLANT" CR);
|
||||
Log.notice("initialisation des variables" CR);
|
||||
Log.notice("--------------------------------------------------" CR);
|
||||
// initialize GDB stub
|
||||
debug_init();
|
||||
#endif
|
||||
|
||||
// set LED output
|
||||
@@ -102,35 +78,12 @@ void setup()
|
||||
motor[i].stop();
|
||||
delay(50);
|
||||
lecture_pot(i); // lecture analogique potentiomètre
|
||||
valeurs_set(i); // controle des valeurs et des relais
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
state_pot_change[i] = true;
|
||||
position_set[i] = position_lue[i];
|
||||
}
|
||||
bouton_set(); // lecture et controle des boutons
|
||||
valeurs_set(); // controle des valeurs et des relais
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
|
||||
#ifdef PID
|
||||
|
||||
myPID.SetMode(myPID.Control::automatic);
|
||||
// myPID.SetMode(myPID.Control::manual);
|
||||
// myPID.SetSampleTimeUs(pid_time);
|
||||
myPID.SetOutputLimits(pid_limit_min, pid_limit_max); // Limit the PID output this is important to get rid of integral windup!
|
||||
// myPID.setBias(pid_bias / 2.0); // Set the bias to 127.5, this is the center of the output range
|
||||
// myPID.SetAntiWindupMode(myPID.iAwMode::iAwCondition); // Set the anti-windup mode to "do nothing"
|
||||
#endif
|
||||
#ifdef AUTOPID
|
||||
myPID.setBangBang(ECRART_V_STOP);
|
||||
myPID.setTimeStep(PID_TimeStep);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
Log.notice(F("FIN DE SETUP" CR));
|
||||
debug();
|
||||
#endif
|
||||
#ifdef DEBUG_CONST
|
||||
Log.notice(F("CONST OUT SET ON" CR));
|
||||
const_out_L_state = true;
|
||||
#endif
|
||||
bouton_set(); // lecture et controle des boutons
|
||||
//pid_setup(); // initialisation des PID
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
@@ -138,80 +91,61 @@ void setup()
|
||||
// *******************************************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
if (last_time >= interval_loop + millis()) // si intervalle de boucle atteint
|
||||
// *******************************************************************************************************
|
||||
// ********************************* boucle de controle des boutons **************************************
|
||||
// *******************************************************************************************************
|
||||
bouton_set(); // lecture et controle des boutons
|
||||
if (state_button_change == true) // si changement d'état d'un bouton
|
||||
{
|
||||
Serial.print(".");
|
||||
Serial.print(debug_count);
|
||||
debug_count++;
|
||||
debug();
|
||||
last_time = millis(); // remise à zéro du compteur de temps
|
||||
button_position_save(); // entregistrement de position des potentiomètres
|
||||
state_button_change = false; // remise à zéro du flag de changement de bouton
|
||||
}
|
||||
#endif
|
||||
|
||||
bouton_set(); // lecture et controle des boutons
|
||||
// *******************************************************************************************************
|
||||
// ********************************* boucle de lecture des potentiomètres ********************************
|
||||
// *******************************************************************************************************
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture analogique potentiomètre avec mise à jour du flag de changement de potentiomètre
|
||||
if (state_pot_change[i] == true) // si changement de position d'un potentiomètre
|
||||
lecture_pot(i); // lecture analogique potentiomètre avec mise à jour du flag de changement de potentiomètre
|
||||
if (position_change[i] == true && motor_change[i] != true) // si changement de position d'un potentiomètre
|
||||
{
|
||||
valeurs_set(); // controle des valeurs et des relais
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ********************************* boucle de controle des moteurs **************************************
|
||||
// *******************************************************************************************************
|
||||
if (stereo_link_state == true || const_out_L_state == true || const_out_R_state == true) // si un des boutons est enfoncé
|
||||
{
|
||||
if (motor_change[i] != state_pot_change[i] && last_change_time + bounce_time_pot >= millis()) // si pas changement de position du moteur en cours et temps depuis changement de position potentiomètre supérieur au temps de rebond
|
||||
if (stereo_link_state != true && const_out_L_state != true && const_out_R_state != true) // si pas de contrôle constant output
|
||||
{
|
||||
#ifdef DEBUG_LOOP // si DEBUG activé
|
||||
Log.warning(F("*** moteur %d nedd to go ***" CR), i);
|
||||
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
|
||||
Log.notice(F("state_pot_change[%d] = %d" CR), i, state_pot_change[i]);
|
||||
Log.notice(F("bounce_time_pot = %d" CR), bounce_time_pot);
|
||||
Log.notice(F("last_change_time = %d" CR), last_change_time);
|
||||
Log.notice(F("last_change_time + bounce_time_pot = %d" CR), last_change_time + bounce_time_pot);
|
||||
Log.notice(F(" millis() = %d" CR), millis());
|
||||
#endif
|
||||
lecture_pot(i); // lecture analogique potentiomètre
|
||||
if (motor_change[0] != true && motor_change[1] != true && motor_change[2] != true && motor_change[3] != true)
|
||||
valeurs_set(i); // controle des valeurs et des relais
|
||||
if (motor_change[i] == true)
|
||||
{
|
||||
consigne_set(); // controle des consignes avec controle des valeurs et des relais
|
||||
moteur_stop(i); // arret du moteur
|
||||
position_set[i] = position_lue[i];
|
||||
motor_change[i] = false;
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
else
|
||||
{
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
}
|
||||
if (motor_change[i] == true) // si changement de position du moteur en cours
|
||||
else // si controle constant output
|
||||
{
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
if (count_motor == true)
|
||||
current_time = millis(); // enregistrement du temps actuel
|
||||
if (motor_change[i] != true)
|
||||
{
|
||||
|
||||
Log.warning(F("*** changement de position du moteur %d ***" CR), i);
|
||||
// pidcontroller.start();
|
||||
consigne_set(); // mise à jour des consignes
|
||||
valeurs_const_set(i); // controle des valeurs et des relais
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (motor_change[i] == true)
|
||||
{
|
||||
if (position_set[i] > position_lue[i] + ECART_V_STOP || position_set[i] < position_lue[i] - ECART_V_STOP)
|
||||
{
|
||||
moteur_set(i); // controle des moteurs
|
||||
}
|
||||
else
|
||||
{
|
||||
moteur_stop(i); // arret du moteur
|
||||
motor_change[i] = false;
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
}
|
||||
// *******************************************************************************************************
|
||||
// ********************************* boucle de controle des boutons **************************************
|
||||
// *******************************************************************************************************
|
||||
if (state_button_change == true) // si changement d'état d'un bouton
|
||||
{
|
||||
#ifdef DEBUG_LOOP // si DEBUG activé
|
||||
Log.warning(F(CR "*** changement de bouton ***" CR));
|
||||
#endif
|
||||
diff_set(); // entregistrement des différences de gain et de volume
|
||||
state_button_change = false; // remise à zéro du flag de changement de bouton
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ********************************* boucle de sauvegarde des potentiomètre ******************************
|
||||
// *******************************************************************************************************
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
}
|
||||
|
||||
+34
-189
@@ -10,227 +10,72 @@ MiniMoto motor[4] = {gain_0_motor, vol_0_motor, gain_1_motor, vol_1_motor};
|
||||
proportional,integral, and derivative controller i have set
|
||||
the gain values with the help of trial and error methods.
|
||||
*/
|
||||
#define ECRART_V_STOP 5 // hystérésie de positionnement potentiomètre
|
||||
#define PID
|
||||
// #define AUTOPID
|
||||
|
||||
#ifdef PID
|
||||
#include "QuickPID.h"
|
||||
// Define the aggressive and conservative and POn Tuning Parameters
|
||||
float aggKp = 2, aggKi = 0.5, aggKd = 0.5;
|
||||
float consKp = 1, consKi = 0.05, consKd = 0.25;
|
||||
|
||||
#define ECRART_V_STOP 5 // hystérésie de positionnement potentiomètre
|
||||
#define pid_windup 10
|
||||
#define pid_limit_min 6
|
||||
#define pid_limit_max 63
|
||||
#define pid_bias 255.0
|
||||
#define pid_time_step 1000
|
||||
#define gap_setpoint 25
|
||||
float pid_input, pid_output, pid_setpoint;
|
||||
QuickPID myPID(&pid_input, &pid_output, &pid_setpoint);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef AUTOPID
|
||||
#include <AutoPID.h>
|
||||
// pid settings and gains
|
||||
#define PID_TimeStep 250 // set PID update interval to 4000ms
|
||||
#define OUTPUT_MIN 100
|
||||
#define OUTPUT_MAX 1000
|
||||
#define KP .12
|
||||
#define KI .0003
|
||||
#define KD 0
|
||||
double motor_read, motor_set, out_speed_value;
|
||||
AutoPID myPID(&motor_read, &motor_set, &out_speed_value, OUTPUT_MIN, OUTPUT_MAX, KP, KI, KD);
|
||||
#endif
|
||||
#define ECART_V_STOP 5 // hystérésie de positionnement potentiomètre
|
||||
#define speed_max 63 // vitesse max moteur
|
||||
#define speed_med 35 // vitesse moyenne moteur
|
||||
#define speed_min 10 // vitesse min moteur
|
||||
|
||||
void moteur_set(int i);
|
||||
void moteur_stop(int i);
|
||||
void pid_set(int i);
|
||||
|
||||
void pid_set(int i)
|
||||
{
|
||||
// #define anal_read
|
||||
|
||||
#ifdef anal_read
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
pid_input = analogRead(gain_0_pot);
|
||||
break;
|
||||
case 1:
|
||||
pid_input = analogRead(vol_0_pot);
|
||||
break;
|
||||
case 2:
|
||||
pid_input = analogRead(gain_1_pot);
|
||||
break;
|
||||
case 3:
|
||||
pid_input = analogRead(vol_1_pot);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifndef anal_read
|
||||
lecture_pot(i);
|
||||
pid_input = float(position_lue[i]);
|
||||
#endif
|
||||
pid_setpoint = float(position_set[i]);
|
||||
float gap = abs(pid_setpoint - pid_input); // distance away from setpoint
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
Log.notice(F("IIIIII = %d" CR), i);
|
||||
Log.notice(F("gap motor = %d" CR), gap);
|
||||
Log.notice(F("pid_setpoint = %d" CR), pid_setpoint);
|
||||
Log.notice(F("pid_input = %d" CR), pid_input);
|
||||
Log.notice(F("abs(pid_setpoint - pid_input) %d" CR), abs(pid_setpoint - pid_input));
|
||||
#endif
|
||||
if (gap < gap_setpoint)
|
||||
{ // we're close to setpoint, use conservative tuning parameters
|
||||
myPID.SetTunings(consKp, consKi, consKd);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're far from setpoint, use aggressive tuning parameters
|
||||
myPID.SetTunings(aggKp, aggKi, aggKd);
|
||||
}
|
||||
myPID.Compute(); // Let the PID compute the value, returns the calculated optimal output
|
||||
}
|
||||
|
||||
void moteur_stop(int i)
|
||||
{
|
||||
#ifdef AUTOPID
|
||||
myPID.stop();
|
||||
#endif
|
||||
#ifdef PID
|
||||
// myPID.stop();
|
||||
myPID.SetMode(myPID.Control::manual);
|
||||
#endif
|
||||
motor[i].stop(); // stop moteur
|
||||
delay(50); // attente 50ms
|
||||
lecture_pot(i); // lecture analogique du potentiomètre
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
motor_change[i] = false; // remise à zéro du flag de changement de position du potentiomètre
|
||||
position_set[i] = position_lue[i]; // remise à zéro de la consigne de position du potentiomètre
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
Log.notice(F("========================== void moteur_stop(%d) ===================================" CR), i);
|
||||
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
|
||||
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]);
|
||||
Log.notice(F("state_pot_change[%d] = %d" CR), i, state_pot_change[i]);
|
||||
count_motor = true; // remise à zéro du compteur de boucle
|
||||
#endif
|
||||
}
|
||||
|
||||
void moteur_set(int i) // fonction de gestion des moteurs
|
||||
{
|
||||
#ifdef PID
|
||||
myPID.SetMode(myPID.Control::automatic);
|
||||
pid_set(i);
|
||||
int motor_speed_value = pid_output; // Let the PID compute the value, returns the calculated optimal output
|
||||
#endif
|
||||
|
||||
#ifdef AUTOPID
|
||||
motor_read = position_lue[i]; // The "goal" the PID controller tries to "reach",
|
||||
motor_set = position_set[i]; // The "goal" the PID controller tries to "reach",
|
||||
myPID.run(); // Let the PID compute the value, returns the calculated optimal output
|
||||
int motor_speed_value = (int)out_speed_value;
|
||||
int map_speed_value = map(motor_speed_value, 100, 1000, -63, 63);
|
||||
int const_speed_value = constrain(motor_speed_value, -63, 63);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
if (count_motor == true)
|
||||
if (position_lue[i] == position_set[i] || position_set[i] > max_pot || position_set[i] < min_pot) // si position lue égale à la consigne ou consigne hors bornes
|
||||
{
|
||||
Log.notice(F("========================= void moteur_set(%d)" CR), i);
|
||||
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
|
||||
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]); // position sauvegardée
|
||||
Log.notice(F("motor_speed_value = %d" CR), motor_speed_value); // valeur de vitesse moteur
|
||||
#ifdef AUTOPID
|
||||
Log.notice(F("out_speed_value = %d" CR), out_speed_value);
|
||||
Log.notice(F("(int) out_speed_value = %d" CR), (int)out_speed_value);
|
||||
Log.notice(F("map_speed_value = %d" CR), map_speed_value);
|
||||
Log.notice(F("const_speed_value = %d" CR), const_speed_value);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef DEBUG_MOTEUR_HARD // si DEBUG activé
|
||||
Log.notice(F("========================= void moteur_set(%d)" CR), i);
|
||||
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
|
||||
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]);
|
||||
Log.notice(F("motor_speed_value = %d" CR), motor_speed_value);
|
||||
#ifdef AUTOPID
|
||||
Log.notice(F("out_speed_value = %d" CR), out_speed_value);
|
||||
Log.notice(F("(int) out_speed_value = %d" CR), (int)out_speed_value);
|
||||
Log.notice(F("map_speed_value = %d" CR), map_speed_value);
|
||||
Log.notice(F("const_speed_value = %d" CR), const_speed_value);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (position_lue[i] == position_set[i] || position_set[i] > 1023 || position_set[i] < 0) // si position lue égale à la consigne ou consigne hors bornes
|
||||
{
|
||||
#ifdef DEBUG_MOTEUR // si DEBUG activé
|
||||
Log.notice(F("MOTEUR[%d] OK" CR), i);
|
||||
#endif
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
count_motor = true;
|
||||
#endif
|
||||
moteur_stop(i);
|
||||
return;
|
||||
}
|
||||
else if (position_lue[i] < (position_set[i] + ECRART_V_STOP) && position_lue[i] > (position_set[i] - ECRART_V_STOP)) // si moteur entre consigne et ECRART_V_STOP
|
||||
else if (position_lue[i] < (position_set[i] + ECART_V_STOP) && position_lue[i] > (position_set[i] - ECART_V_STOP)) // si moteur entre consigne et ECART_V_STOP
|
||||
{
|
||||
#ifdef DEBUG_MOTEUR // si DEBUG activé
|
||||
Log.notice(F("MOTEUR[%d] OK" CR), i);
|
||||
#endif
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
count_motor = true;
|
||||
#endif
|
||||
moteur_stop(i);
|
||||
return;
|
||||
}
|
||||
// *******************************************************************************************************
|
||||
// si moteur doit aller vers la gauche
|
||||
else if (position_lue[i] > (position_set[i] + (ECRART_V_STOP / 2))) // si moteur n'est pas entre consigne et ECRART_V_STOP
|
||||
else if (position_lue[i] > (position_set[i] + ECART_V_STOP)) // si moteur doit aller vers la gauche
|
||||
{
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
if (count_motor == true)
|
||||
{
|
||||
Log.notice(F("========================== MOTEUR[%d] GO RIGHT at speed = %d ============================" CR), i, motor_speed_value);
|
||||
count_motor = false;
|
||||
}
|
||||
#endif
|
||||
motor_change[i] = true;
|
||||
motor[i].drive(-motor_speed_value);
|
||||
if (position_lue[i] > (position_set[i] + (ECART_V_STOP * 4))) // vitesse max si moteur n'est pas entre consigne et ECART_V_STOP * 4
|
||||
{
|
||||
motor[i].drive(-speed_max);
|
||||
}
|
||||
else if (position_lue[i] > (position_set[i] + (ECART_V_STOP * 3))) // vitesse moyenne si moteur n'est pas entre consigne et ECART_V_STOP * 3
|
||||
{
|
||||
motor[i].drive(-speed_med);
|
||||
}
|
||||
else if (position_lue[i] > (position_set[i] + (ECART_V_STOP * 2))) // vitesse min si moteur n'est pas entre consigne et ECART_V_STOP * 2
|
||||
{
|
||||
motor[i].drive(-speed_min);
|
||||
}
|
||||
}
|
||||
else if (position_lue[i] < (position_set[i] - (ECRART_V_STOP / 2))) // si moteur n'est pas entre consigne et ECRART_V_STOP
|
||||
// *******************************************************************************************************
|
||||
if (position_lue[i] < (position_set[i] - ECART_V_STOP)) // si moteur doit aller vers la droite
|
||||
{
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
if (count_motor == true)
|
||||
{
|
||||
Log.notice(F("========================== MOTEUR[%d] GO LEFT at speed = %d ============================" CR), i, motor_speed_value);
|
||||
count_motor = false;
|
||||
}
|
||||
#endif
|
||||
motor_change[i] = true;
|
||||
motor[i].drive(motor_speed_value);
|
||||
if (position_lue[i] < (position_set[i] - (ECART_V_STOP * 4))) // vitesse max si moteur n'est pas entre consigne et ECART_V_STOP * 4
|
||||
{
|
||||
motor[i].drive(speed_max);
|
||||
}
|
||||
else if (position_lue[i] < (position_set[i] - (ECART_V_STOP * 3))) // viteur moyenne si moteur n'est pas entre consigne et ECART_V_STOP * 3
|
||||
{
|
||||
motor[i].drive(speed_med);
|
||||
}
|
||||
else if (position_lue[i] < (position_set[i] - (ECART_V_STOP * 2))) // viteur min si moteur n'est pas entre consigne et ECART_V_STOP * 2
|
||||
{
|
||||
motor[i].drive(speed_min);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_MOTEUR // si DEBUG activé
|
||||
Log.notice(F("MOTEUR[%d] NOK" CR), i);
|
||||
#endif
|
||||
#ifdef DEBUG_CONST // si DEBUG activé
|
||||
count_motor = true;
|
||||
#endif
|
||||
motor[i].brake(); // stop moteur
|
||||
moteur_stop(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,49 @@ ResponsiveAnalogRead vol_0(vol_0_pot, true, amount_easing);
|
||||
ResponsiveAnalogRead gain_1(gain_1_pot, true, amount_easing);
|
||||
ResponsiveAnalogRead vol_1(vol_1_pot, true, amount_easing);
|
||||
|
||||
#define max_pot 1005 // valeur max potentiomètre pour calibrage ADC
|
||||
#define min_pot 0 // valeur min potentiomètre pour calibrage ADC
|
||||
void button_position_save(); // calcul des différences de valeurs
|
||||
void save_pot(int i); // sauvegarde position potentiomètre
|
||||
void lecture_pot(int i); // lecture analogique potentiomètre
|
||||
|
||||
void lecture_pot(int i); // lecture analogique potentiomètre
|
||||
void save_pot(int i); // sauvegarde position potentiomètre
|
||||
void button_position_save() // calcul de la différence entre gain et volume
|
||||
{
|
||||
if (const_out_L_state == 1) // si bouton const_out_L appuyé
|
||||
{
|
||||
for (int i = 0; i <= 1; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (const_out_R_state == 1) // si bouton const_out_R appuyé
|
||||
{
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (stereo_link_state == 1) // si bouton stereo_link appuyé
|
||||
{
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void save_pot(int i)
|
||||
{
|
||||
position_save[i] = position_lue[i]; // sauvegarde position potentiomètre
|
||||
position_change[i] = false; // RAZ flag de changement de position du potentiomètre
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** lecture bouton *********************************************
|
||||
@@ -34,15 +72,14 @@ void lecture_pot(int i)
|
||||
gain_0.update();
|
||||
if (gain_0.hasChanged())
|
||||
{
|
||||
state_pot_change[i] = true; // il y a changement de position du potentiomètre
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_lue[i] = gain_0.getValue();
|
||||
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
|
||||
position_lue[i] = constrain(position_lue[i], 0, max_pot);
|
||||
position_lue[i] = constrain(position_lue[i], 0, 1023);
|
||||
}
|
||||
#else
|
||||
position_lue[0] = 512;
|
||||
position_set[i] = 512;
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
@@ -51,14 +88,13 @@ void lecture_pot(int i)
|
||||
if (vol_0.hasChanged())
|
||||
{
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
state_pot_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_lue[i] = vol_0.getValue();
|
||||
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
|
||||
position_lue[i] = constrain(position_lue[i], 0, 1023);
|
||||
}
|
||||
#else
|
||||
position_lue[i] = 512;
|
||||
position_set[i] = 512;
|
||||
#endif
|
||||
break;
|
||||
case 2:
|
||||
@@ -67,14 +103,13 @@ void lecture_pot(int i)
|
||||
if (gain_1.hasChanged())
|
||||
{
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
state_pot_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_lue[i] = gain_1.getValue();
|
||||
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
|
||||
position_lue[i] = constrain(position_lue[i], 0, 1023);
|
||||
}
|
||||
#else
|
||||
position_lue[i] = 512;
|
||||
position_set[i] = 512;
|
||||
#endif
|
||||
break;
|
||||
case 3:
|
||||
@@ -83,39 +118,14 @@ void lecture_pot(int i)
|
||||
if (vol_1.hasChanged())
|
||||
{
|
||||
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
state_pot_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
position_lue[i] = vol_1.getValue();
|
||||
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
|
||||
position_lue[i] = constrain(position_lue[i], 0, 1023);
|
||||
}
|
||||
#else
|
||||
position_lue[i] = 512;
|
||||
position_set[i] = 512;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_POT // si DEBUG activé
|
||||
if (state_pot_change[i] == true)
|
||||
{
|
||||
Log.notice(F("il y a changement de potentiomètre dans lecture pot %d" CR), i);
|
||||
Log.trace("position_lue[%d] = %d" CR, i, position_lue[i]);
|
||||
Log.trace("position_save[%d] = %d" CR, i, position_save[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void save_pot(int i)
|
||||
{
|
||||
#ifdef DEBUG_POT // si DEBUG activé
|
||||
if (state_pot_change[i] == true)
|
||||
{
|
||||
Log.notice(F("======= void save_pot(%d)" CR), i);
|
||||
}
|
||||
#endif
|
||||
position_save[i] = position_lue[i]; // sauvegarde position potentiomètre
|
||||
if (last_change_time + bounce_time_pot >= millis())
|
||||
{
|
||||
state_pot_change[i] = false; // RAZ flag de changement de position du potentiomètre
|
||||
}
|
||||
// last_change_time = millis(); // sauvegarde du temps du dernier changement de position
|
||||
}
|
||||
|
||||
+28
-63
@@ -9,55 +9,12 @@ PCF8574 PCF_gain_0(gain_0_relais);
|
||||
PCF8574 PCF_vol_1(vol_1_relais);
|
||||
PCF8574 PCF_gain_1(gain_1_relais);
|
||||
|
||||
#define delay_relais 1 // délai entre chaque relais
|
||||
void relais_set(int relais);
|
||||
void relais_send(int relais, int value, int byte_value);
|
||||
void relais_set(int relais); // fonction de mappage des valeur pour envoie sur les cartes relais
|
||||
void relais_send(int relais, int value, int byte_value); // fonction d'envoie de valeur sur les cartes relais
|
||||
|
||||
void relais_send(int relais, int value, int byte_value) // fonction d'envoie de valeur sur relais
|
||||
void relais_set(int relais) // fonction de mappage des valeur pour envoie sur les cartes relais
|
||||
{
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("relais_send(%d, %d, %d)" CR, relais, value, byte_value);
|
||||
#endif
|
||||
|
||||
// PCF.write(const uint8_t pin, const uint8_t value) writes a single pin; pin = 0..7; value is HIGH(1) or LOW (0)
|
||||
// uint8_t write(const uint8_t value) writes all pins; value = 0..255
|
||||
switch (relais)
|
||||
{
|
||||
case 0:
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("PCF_gain_0.write(%d, %d)" CR, byte_value, value);
|
||||
#endif
|
||||
PCF_gain_0.write(byte_value, value); // envoie valeur sur relais volume gauche
|
||||
break;
|
||||
|
||||
case 1:
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("PCF_vol_0.write(%d, %d)" CR, byte_value, value);
|
||||
#endif
|
||||
PCF_vol_0.write(byte_value, value); // envoie valeur sur relais gain gauche
|
||||
break;
|
||||
|
||||
case 2:
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("PCF_gain_1.write(%d, %d)" CR, byte_value, value);
|
||||
#endif
|
||||
PCF_gain_1.write(byte_value, value); // envoie valeur sur relais volume droite
|
||||
break;
|
||||
|
||||
case 3:
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("PCF_vol_1.write(%d, %d)" CR, byte_value, value);
|
||||
#endif
|
||||
PCF_vol_1.write(byte_value, value); // envoie valeur sur relais gain droite
|
||||
break;
|
||||
}
|
||||
delay(delay_relais);
|
||||
}
|
||||
|
||||
|
||||
void relais_set(int relais) // fonction de gestion des relais
|
||||
{
|
||||
// tableau de valeur des relais
|
||||
// mise à jour du tableau de valeur des relais
|
||||
switch (relais)
|
||||
{
|
||||
case 0:
|
||||
@@ -74,21 +31,11 @@ void relais_set(int relais) // fonction de gestion des relais
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
|
||||
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
|
||||
#endif
|
||||
|
||||
if (relais_map[relais] != relais_old[relais]) // si changement de valeur
|
||||
{
|
||||
// si changement en sens montant
|
||||
if (relais_map[relais] > relais_old[relais])
|
||||
{
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("relais UP" CR);
|
||||
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
|
||||
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
|
||||
#endif
|
||||
for (int j = 0; j <= 7; j++)
|
||||
{
|
||||
if (bitRead(relais_map[relais], j) == 1)
|
||||
@@ -104,11 +51,6 @@ void relais_set(int relais) // fonction de gestion des relais
|
||||
// si changement en sens descendant
|
||||
if (relais_map[relais] < relais_old[relais])
|
||||
{
|
||||
#ifdef DEBUG_RELAIS // si DEBUG activé
|
||||
Log.notice("relais DOWN" CR);
|
||||
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
|
||||
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
|
||||
#endif
|
||||
for (int j = 7; j >= 0; j--)
|
||||
{
|
||||
if (bitRead(relais_map[relais], j) == 1)
|
||||
@@ -121,6 +63,29 @@ void relais_set(int relais) // fonction de gestion des relais
|
||||
}
|
||||
}
|
||||
}
|
||||
relais_old[relais] = relais_map[relais]; // sauvegarde valeur
|
||||
relais_old[relais] = relais_map[relais]; // sauvegarde valeur de comparaison
|
||||
}
|
||||
}
|
||||
|
||||
void relais_send(int relais, int value, int byte_value) // fonction d'envoie de valeur sur les cartes relais
|
||||
{
|
||||
// PCF.write(const uint8_t pin, const uint8_t value) writes a single pin; pin = 0..7; value is HIGH(1) or LOW (0)
|
||||
// uint8_t write(const uint8_t value) writes all pins; value = 0..255
|
||||
// envoie I2C des valeur sur les cartes relais
|
||||
switch (relais)
|
||||
{
|
||||
case 0:
|
||||
PCF_gain_0.write(byte_value, value); // carte relais gain gauche
|
||||
break;
|
||||
case 1:
|
||||
PCF_vol_0.write(byte_value, value); // carte relais volume gauche
|
||||
break;
|
||||
case 2:
|
||||
PCF_gain_1.write(byte_value, value); // carte relais gain droit
|
||||
break;
|
||||
case 3:
|
||||
PCF_vol_1.write(byte_value, value); // carte relais volume droit
|
||||
break;
|
||||
}
|
||||
delay(delay_relais);
|
||||
}
|
||||
+54
-61
@@ -1,61 +1,66 @@
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** gestion valeurs ********************************************
|
||||
// *******************************************************************************************************
|
||||
void valeurs_set(int i); // gestion des valeurs
|
||||
void smoothgain_set(int i); // calcul des valeurs lissées de gain et mise à jour des relais
|
||||
void smoothvolume_set(int i); // calcul des valeurs lissées de volume et mise à jour des relais
|
||||
void valeurs_set(int i); // gestion des valeurs
|
||||
void valeurs_const_set(int i); // gestion des valeurs constant ouptut
|
||||
void smoothgain_set(int i); // calcul des valeurs lissées de gain et mise à jour des relais
|
||||
void smoothvolume_set(int i); // calcul des valeurs lissées de volume et mise à jour des relais
|
||||
|
||||
void valeurs_set()
|
||||
void valeurs_set(int i)
|
||||
{
|
||||
#ifdef DEBUG_VALEURS // si DEBUG activé
|
||||
Log.notice(F("*** valeurs_set ***" CR));
|
||||
#endif
|
||||
if (state_pot_change[0] == true && position_lue[0] != position_save[0]) // si changement d'état du potentiomètre de gain gauche
|
||||
if (position_change[i] == true && position_lue[i] != position_save[i]) // si changement d'état du potentiomètre de gain gauche
|
||||
{
|
||||
smoothgain[0] = byte(position_lue[0] / 4);
|
||||
position_change[0] = true; // il y a changement de position du potentiomètre de gain gauche
|
||||
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
|
||||
#ifdef DEBUG_VALEURS
|
||||
Log.notice(F("changement pot gain gauche" CR));
|
||||
Log.trace(F("smoothgain[0] = %d" CR), smoothgain[0]);
|
||||
Log.trace(F("relais_gain_val[0] = %d" CR), relais_gain_val[0]);
|
||||
#endif
|
||||
}
|
||||
if (state_pot_change[1] == true && position_lue[1] != position_save[1]) // si changement d'état du potentiomètre de volume gauche
|
||||
{
|
||||
smoothvol[0] = byte(position_lue[1] / 4) - 1; // 156
|
||||
position_change[1] = true; // il y a changement de position du potentiomètre de volume gauche
|
||||
smoothvolume_set(0);
|
||||
#ifdef DEBUG_VALEURS
|
||||
Log.notice(F("changement pot volume gauche" CR));
|
||||
Log.trace(F("smoothvol[0] = %d" CR), smoothvol[0]);
|
||||
Log.trace(F("relais_vol_val[0] = %d" CR), relais_vol_val[0]);
|
||||
#endif
|
||||
}
|
||||
if (state_pot_change[2] == true && position_lue[2] != position_save[2]) // si changement d'état du potentiomètre de gain droit
|
||||
{
|
||||
smoothgain[1] = byte(position_lue[2] / 4); // 156
|
||||
position_change[2] = true; // il y a changement de position du potentiomètre de gain droitf
|
||||
smoothgain_set(1); // mise à jour de valeur du relais gain droit
|
||||
#ifdef DEBUG_VALEURS
|
||||
Log.notice(F("changement pot gain droit" CR));
|
||||
Log.trace(F("smoothgain[1] = %d" CR), smoothgain[1]);
|
||||
Log.trace(F("relais_gain_val[1] = %d" CR), relais_gain_val[1]);
|
||||
#endif
|
||||
}
|
||||
if (state_pot_change[3] == true && position_lue[3] != position_save[3]) // si changement d'état du potentiomètre de volume droit
|
||||
{
|
||||
smoothvol[1] = byte(position_lue[3] / 4) - 1; // 156
|
||||
position_change[3] = true; // il y a changement de position du potentiomètre de volume droit
|
||||
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
|
||||
#ifdef DEBUG_VALEURS
|
||||
Log.notice(F("changement pot volume droit" CR));
|
||||
Log.trace(F("smoothvol[1] = %d" CR), smoothvol[1]);
|
||||
Log.trace(F("relais_vol_val[1] = %d" CR), relais_vol_val[1]);
|
||||
#endif
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
smoothgain[0] = byte(position_lue[0] / 4);
|
||||
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
|
||||
break;
|
||||
case 1:
|
||||
smoothvol[0] = byte(position_lue[1] / 4) - 1; // 156
|
||||
smoothvolume_set(0);
|
||||
break;
|
||||
case 2:
|
||||
smoothgain[1] = byte(position_lue[2] / 4); // 156
|
||||
smoothgain_set(1); // mise à jour de valeur du relais gain droit
|
||||
break;
|
||||
case 3:
|
||||
smoothvol[1] = byte(position_lue[3] / 4) - 1; // 156
|
||||
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void valeurs_const_set(int i)
|
||||
{
|
||||
if (position_change[i] == true && position_set[i] != position_save[i]) // si changement d'état du potentiomètre de gain gauche
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
smoothgain[0] = byte(position_set[0] / 4); // adaptation de valeur
|
||||
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
|
||||
break;
|
||||
case 1:
|
||||
smoothvol[0] = byte(position_set[1] / 4) - 1; // adaptation de valeur
|
||||
smoothvolume_set(0); // mise à jour de valeur du relais volume gauche
|
||||
break;
|
||||
case 2:
|
||||
smoothgain[1] = byte(position_set[2] / 4); // adaptation de valeur
|
||||
smoothgain_set(1); // mise à jour de valeur du relais gain droit
|
||||
break;
|
||||
case 3:
|
||||
smoothvol[1] = byte(position_set[3] / 4) - 1; // adaptation de valeur
|
||||
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void smoothgain_set(int i)
|
||||
{
|
||||
// lisages manuel des valeurs de gain
|
||||
@@ -355,12 +360,6 @@ void smoothgain_set(int i)
|
||||
{
|
||||
relais_gain_val[i] = smoothgain[i] + 99;
|
||||
}
|
||||
#ifdef DEBUG_RELAIS
|
||||
Log.notice(F(CR "int smoothgain_set()" CR));
|
||||
Log.trace(F("i = %d" CR), i);
|
||||
Log.trace(F("relais_gain_val = %d" CR), relais_gain_val[i]);
|
||||
Log.trace(F("smoothgain = %d" CR), smoothgain[i]);
|
||||
#endif
|
||||
if (i == 0)
|
||||
{
|
||||
relais_set(0); // mise à jour des relais
|
||||
@@ -376,12 +375,6 @@ void smoothvolume_set(int i)
|
||||
smoothvol[i] = map(smoothvol[i], 0, 255, 0, 255); // map de 0 à 255
|
||||
smoothvol[i] = constrain(smoothvol[i], 0, 255); // map de 0 à 255
|
||||
relais_vol_val[i] = smoothvol[i]; // valeur du relais = valeur du volume
|
||||
#ifdef DEBUG_RELAIS
|
||||
Log.notice(F(CR "int smoothvolume_set()" CR));
|
||||
Log.notice(F("i = %d" CR), i);
|
||||
Log.notice(F("relais_vol_val = %d" CR), relais_vol_val[i]);
|
||||
Log.notice(F("smoothvol = %d" CR), smoothvol[i]);
|
||||
#endif
|
||||
if (i == 0)
|
||||
{
|
||||
relais_set(1); // mise à jour des relais
|
||||
|
||||
+15
-68
@@ -25,16 +25,20 @@
|
||||
#define vol_1_motor 0xCA // A0 = 1, A1 = 1
|
||||
|
||||
// variables potentiomètre
|
||||
int consigne[4] = {0, 0, 0, 0}; // tableau de consigne des potentiomètre
|
||||
int position_lue[4] = {0, 0, 0, 0}; // tableau de valeur lus sur les potentiomètre
|
||||
int position_lue[4] = {0, 0, 0, 0}; // tableau des valeur lus sur les potentiomètre
|
||||
int position_save[4] = {0, 0, 0, 0}; // tableau de sauvegarde de valeurs des potentiomètre pour comparaison
|
||||
int position_set[4] = {0, 0, 0, 0}; // tableau de consigne de position des potentiomètre
|
||||
int position_save[4] = {0, 0, 0, 0}; // tableau de sauvegarde de valeurs des potentiomètre
|
||||
bool position_change[4] = {false, false, false, false}; // tableau de flag de positionnement des potentiomètre
|
||||
bool motor_change[4] = {false, false, false, false}; // tableau de flag de changement de positionnement des potentiomètre
|
||||
int position_memory[4] = {0, 0, 0, 0}; // tableau de memorisation de valeur des potentiomètre pour mode constant output
|
||||
bool position_change[4] = {false, false, false, false}; // tableau de flag de changement de position des potentiomètre
|
||||
bool motor_change[4] = {false, false, false, false}; // tableau de flag pour moteurs des potentiomètre
|
||||
byte analog_pot[4] = {gain_0_pot, vol_0_pot, gain_1_pot, vol_1_pot}; // tableau de PIN des potentiomètre
|
||||
#define max_pot 1005 // valeur max potentiomètre pour calibrage ADC
|
||||
#define min_pot 0 // valeur min potentiomètre pour calibrage ADC
|
||||
|
||||
// variable pour gestion du temps
|
||||
unsigned long last_change_time = millis(); // remise à zéro du compteur de temps
|
||||
#define bounce_time_pot 300 // interval de temps entre 2 lecture de l'état du potentiomètre
|
||||
unsigned long current_time = millis(); // variable de temps courant
|
||||
#define bounce_time_pot 150 // interval de temps entre 2 lecture de l'état du potentiomètre
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** relais *****************************************************
|
||||
@@ -45,10 +49,11 @@ unsigned long last_change_time = millis(); // remise à zéro du compteur de tem
|
||||
#define gain_1_relais 0x00
|
||||
#define vol_1_relais 0x00
|
||||
// variables relais
|
||||
byte relais_vol_val[2] = {0, 0}; // tableau de valeur des relais volumes
|
||||
byte relais_gain_val[2] = {0, 0}; // tableau de valeur des relais gain
|
||||
byte relais_vol_val[2] = {0, 0}; // tableau de valeur des relais volumes
|
||||
byte relais_old[4] = {0, 0, 0, 0}; // tableau de comparaison de valeur des relais
|
||||
byte relais_map[4] = {0, 0, 0, 0}; // tableau de mappage des valeur des relais
|
||||
#define delay_relais 1 // temps de commutation entre relais
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** boutton *****************************************************
|
||||
@@ -66,65 +71,7 @@ bool stereo_link_state = false; // variable d'état du bouton stereo_link
|
||||
// *******************************************************************************************************
|
||||
bool state_pot_change[4] = {false, false, false, false}; // variable de changement d'état
|
||||
bool state_button_change = true; // variable de changement d'état
|
||||
int diff_gain; // variable de différence de valeur entre les 2 potentiomètre de gain
|
||||
int diff_vol; // variable de différence de valeur entre les 2 potentiomètre de volume
|
||||
int diff_const_out_L; // variable de différence de valeur du canal gauche
|
||||
int diff_const_out_R; // variable de différence de valeur du canal droite
|
||||
bool const_state = false; // variable d'état d'activtion d'un constant ouptut
|
||||
bool error_motor = false; // variable d'erreur de communication avec le moteur
|
||||
int smoothgain[2] = {0, 0}; // tableau de valeur de lissage du gain
|
||||
int smoothvol[2] = {0, 0}; // tableau de valeur de lissage du volume
|
||||
|
||||
// ******************************************************************************************************
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
unsigned long last_time; // variable de comparaison de temps
|
||||
#define interval_loop 1000 // variable de comparaison de temps
|
||||
unsigned int debug_count = 1; // variable de comptage de boucle
|
||||
|
||||
void debug()
|
||||
{
|
||||
#ifdef DEBUG_LOOP_HARD // si DEBUG activé
|
||||
|
||||
Log.verbose(F("--------------------------------------------------" CR));
|
||||
Log.verbose(F("----------------- DEBUG ------------------------" CR));
|
||||
Log.verbose(F("--------------------------------------------------" CR));
|
||||
Log.verbose(F("millis() = %d" CR), millis());
|
||||
Log.verbose(F("last_time = %d" CR), last_time);
|
||||
Log.verbose(F("interval_loop = %d" CR), interval_loop);
|
||||
Log.verbose(F("state_pot_change = %d" CR), state_pot_change);
|
||||
Log.verbose(F("state_button_change = %d" CR), state_button_change);
|
||||
Log.verbose(F("stereo_link_state = %d" CR), stereo_link_state);
|
||||
Log.verbose(F("const_out_L_state = %d" CR), const_out_L_state);
|
||||
Log.verbose(F("const_out_R_state = %d" CR), const_out_R_state);
|
||||
Log.verbose(F("stereo_link_state_old = %d" CR), stereo_link_state_old);
|
||||
Log.verbose(F("const_out_L_state_old = %d" CR), const_out_L_state_old);
|
||||
Log.verbose(F("const_out_R_state_old = %d" CR CR), const_out_R_state_old);
|
||||
#ifdef DEBUG_LEFT
|
||||
Log.verbose(F("diff_const_out_L = %d" CR), diff_const_out_L);
|
||||
for (int i = 0; i <= 1; i++)
|
||||
{
|
||||
Log.verbose(F("--------< %d >--------" CR), i);
|
||||
Log.verbose(F("position_save[%d] = %d" CR), i, position_save[i]);
|
||||
Log.verbose(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.verbose(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
Log.verbose(F("relais_old[%d] = %d" CR), i, relais_old[i]);
|
||||
Log.verbose(F("relais_map[%d] = %d" CR), i, relais_map[i]);
|
||||
}
|
||||
#ifdef DEBUG_RIGHT
|
||||
Log.verbose(F("diff_const_out_R = %d" CR CR), diff_const_out_R);
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
Log.verbose(F("--------< %d >--------" CR), i);
|
||||
Log.verbose(F("position_save[%d] = %d" CR), i, position_save[i]);
|
||||
Log.verbose(F("position_lue[%d] = %d" CR), i, position_lue[i]);
|
||||
Log.verbose(F("position_set[%d] = %d" CR), i, position_set[i]);
|
||||
Log.verbose(F("relais_old[%d] = %d" CR), i, relais_old[i]);
|
||||
Log.verbose(F("relais_map[%d] = %d" CR), i, relais_map[i]);
|
||||
}
|
||||
#endif
|
||||
last_time = millis(); // remise à zéro du compteur de temps
|
||||
Log.verbose(F("--------------------------------------------------" CR));
|
||||
Log.verbose(F("---------------- END DEBUG ---------------------" CR));
|
||||
Log.verbose(F("--------------------------------------------------" CR));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
int smoothvol[2] = {0, 0}; // tableau de valeur de lissage du volume
|
||||
Reference in New Issue
Block a user