Skip to content

Commit b673467

Browse files
authored
Merge pull request #2 from project-neon/feat/rsm-abril-2023
Feat/rsm abril 2023
2 parents 34aa51d + 4b3ca0d commit b673467

13 files changed

+53
-35
lines changed
File renamed without changes.

Software/Autonomous/SimpleStrategy3Sensors/SimpleStrategy3Sensors.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ void loop() {
2626
//////////////////////////////Estrategia//////////////////////////////
2727
} else if(stage == 2) {
2828
distanceRead();
29-
if(distC < distAtk or (distL < distAtk and distR < distAtk)) {
29+
if(distC < distAtk/3 and (distL < distAtk/3 or distR < distAtk/3)) {
30+
Serial.print("ATACANDO MAX \t\t");
31+
speedL = speedR = speedAtk;
32+
} else if(distC < distAtk and (distL < distAtk or distR < distAtk)) {
3033
Serial.print("ATACANDO \t\t");
3134
speedL = speedR = speedStandard;
3235
} else if (distL < distAtk or distR < distAtk) {
3336
(distL < distAtk) ? Serial.print("ESQ \t\t") : Serial.print("DIR \t\t");
34-
speedL = (distL < distAtk) ? speedStandard*0.3 : speedStandard;
35-
speedR = (distL < distAtk) ? speedStandard : speedStandard*0.3;
37+
speedL = (distL < distAtk) ? speedStandard*0.9 : speedStandard;
38+
speedR = (distL < distAtk) ? speedStandard : speedStandard*0.9;
3639
flag = (distL < distAtk) ? -1 : 1;
3740
} else {
3841
(flag == -1) ? Serial.print("PROCURANDO ESQ \t\t") : Serial.print("PROCURANDO DIR \t\t");
3942
speedL = (flag == -1) ? -1*searchSpeed : searchSpeed;
4043
speedR = (flag == -1) ? searchSpeed : -1*searchSpeed;
4144
}
42-
43-
motorsOutput();
4445
//////////////////////////////Robo Parou//////////////////////////////
4546
} else {
4647
speedL = speedR = 0;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const int distMax = 600; //Distância máxima permitida como referência para os sensores (em milímetros)
2-
const int distAtk = 400;
2+
const int distAtk = 600;
33
const int distAtkMax = 200;
44

55
const int speedMax = 85; //vel max para ser usada durande o ataque
6-
const int speedStandard = 30; //vel padrão --- Cuidado se abaixar para menos de 30!!!
7-
const int searchSpeed = speedStandard*0.6;//vel de girar no proprio eixo
8-
const int aproxSpeed = speedStandard*0.25;//vel ao se aproximar do oponente
6+
const int speedStandard = 25; //vel padrão --- Cuidado se abaixar para menos de
7+
const int speedAtk = 70; //vel padrão --- Cuidado se abaixar para menos de 30!!!
8+
const int searchSpeed = 10;//vel de girar no proprio eixo
99

1010
int fluctuationsCounter = 0;

Software/Autonomous/SimpleStrategy3Sensors/controller_IR.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ IRrecv irrecv(JCONTROLLER);
4242
decode_results results;
4343

4444
void controllerInit() {
45-
//Iniciando o endereçamento dos sensores
46-
Wire.begin();
4745
irrecv.enableIRIn(); // Start the receiver
4846
pinMode(JCONTROLLER, INPUT);
4947
pinMode(2, OUTPUT);
@@ -75,6 +73,11 @@ void controllerIR() {
7573
Serial.println("MORREU");
7674
stage = -10;
7775
break;
76+
case I4:
77+
Serial.println("LOAD");
78+
stage = 0;
79+
digitalWrite(2, HIGH);
80+
break;
7881
}
7982
irrecv.resume();
8083
}

Software/Autonomous/SimpleStrategy3Sensors/distance_sensors.h

+21-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ int distC; //Valor lido pelo sensor da frente
1111
int distR; //Valor lido pelo sensor da direita
1212

1313
void sensorsInit() {
14+
//Iniciando o endereçamento dos sensores
15+
Wire.begin();
16+
17+
//Desligamos todos os sensores para pode endereçar os sensores
18+
//Pois os sensores podem vir de fábrica com um mesmo endereço
19+
//Então para não dar conflito, vamos de um em um
1420
pinMode(SDIST_L, OUTPUT);
1521
pinMode(SDIST_C, OUTPUT);
1622
pinMode(SDIST_R, OUTPUT);
@@ -19,6 +25,9 @@ void sensorsInit() {
1925
digitalWrite(SDIST_C, LOW);
2026
digitalWrite(SDIST_R, LOW);
2127

28+
//Para não dar conflito, os sensores sao ligados de um em um
29+
//Quando trocamos o valor pra INPUT, o próprio VL530X começa a alimentar
30+
//o XShut com o HIGH. Não é recomendado fazer HIGH com um digitalWrite(SDIST_R, HIGH)
2231
pinMode(SDIST_L, INPUT);
2332
sensorL.init(true);
2433
sensorL.setAddress((uint8_t)0x21); //endereço do sensor da esquerda
@@ -31,16 +40,19 @@ void sensorsInit() {
3140
sensorR.init(true);
3241
sensorR.setAddress((uint8_t)0x25); //endereço do sensor da direita
3342

34-
sensorL.setTimeout(100);
35-
sensorC.setTimeout(100);
36-
sensorR.setTimeout(100);
43+
sensorL.setTimeout(500);
44+
sensorC.setTimeout(500);
45+
sensorR.setTimeout(500);
46+
sensorL.startContinuous();
47+
sensorC.startContinuous();
48+
sensorR.startContinuous();
3749
}
3850

3951
void distanceRead() {
4052
//Armazena os valores lidos nas respectivas variáveis
41-
distL = sensorL.readRangeSingleMillimeters();
42-
distC = sensorC.readRangeSingleMillimeters();
43-
distR = sensorR.readRangeSingleMillimeters();
53+
distL = sensorL.readRangeContinuousMillimeters();
54+
distC = sensorC.readRangeContinuousMillimeters();
55+
distR = sensorR.readRangeContinuousMillimeters();
4456
if(stage == 0){
4557
if((distL > 60000) or (distC > 60000) or (distR > 60000)) {
4658
digitalWrite(2, HIGH);
@@ -49,7 +61,7 @@ void distanceRead() {
4961
}
5062
}
5163

52-
if(distL > 600) distL = 600;
53-
if(distC > 600) distC = 600;
54-
if(distR > 600) distR = 600;
64+
if(distL > 700) distL = 700;
65+
if(distC > 700) distC = 700;
66+
if(distR > 700) distR = 700;
5567
}

Software/Autonomous/StandardStrategy/StandardStrategy.ino

+8-11
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ bool needsToStop(bool newSpeedLPositive, bool newSpeedRPositive ) {
2727
}
2828

2929
fluctuationsCounter++;
30-
if (fluctuationsCounter >= 10) {
30+
if (fluctuationsCounter >= 3) {
3131
speedL = speedR = 0; // APenas para caso a gnt tenha tido flutuacoes seguidas o suficiente. 10 eh o bastante?
3232
motorsOutput();
33-
delay(100); //TODO: Podemos aumentar esse valor p/ ver no codigo mais claramente se ele para antes de mudar a direcao
33+
delay(10); //TODO: Podemos aumentar esse valor p/ ver no codigo mais claramente se ele para antes de mudar a direcao
3434
fluctuationsCounter = 0;
3535
return false; //Retorna falso para o codigo nao fazer um return dentro do loop!
3636
}
@@ -48,35 +48,32 @@ void loop() {
4848
digitalWrite(2, HIGH);
4949
//////////////////////////////Estrategia//////////////////////////////
5050
} else if(stage == 2) {
51-
if(distL < distAtkMax and distR < distAtkMax) {
51+
if(distC < distAtk/3 and (distL < distAtk/3 or distR < distAtk/3)) {
5252
if (needsToStop(true,true)) return;
5353
Serial.print("ATACANDO MÁX \t\t");
54-
speedL = speedR = speedMax;
55-
} else if(distC < 100 or (distL < distAtk and distR < distAtk)) {
54+
speedL = speedR = speedAtk;
55+
} else if(distC < distAtk and (distL < distAtk or distR < distAtk)) {
5656
if (needsToStop(true,true)) return;
5757
Serial.print("ATACANDO \t\t");
5858
speedL = speedR = speedStandard;
5959
} else if (distL < distAtk or distR < distAtk) {
6060
if (needsToStop(true,true)) return;
6161
(distL < distAtk) ? Serial.print("ESQ \t\t") : Serial.print("DIR \t\t");
62-
speedL = (distL < distAtk) ? speedStandard*0.3 : speedStandard;
63-
speedR = (distL < distAtk) ? speedStandard : speedStandard*0.3;
62+
speedL = (distL < distAtk) ? speedStandard*0.9 : speedStandard;
63+
speedR = (distL < distAtk) ? speedStandard : speedStandard*0.9;
6464
flag = (distL < distAtk) ? -1 : 1;
6565
} else {
6666
if (needsToStop(flag != -1, flag == -1)) return;
6767
(flag == -1) ? Serial.print("PROCURANDO ESQ \t\t") : Serial.print("PROCURANDO DIR \t\t");
6868
speedL = (flag == -1) ? -1*searchSpeed : searchSpeed;
6969
speedR = (flag == -1) ? searchSpeed : -1*searchSpeed;
7070
}
71-
72-
motorsOutput();
7371
//////////////////////////////Robo Parou//////////////////////////////
7472
} else {
7573
speedL = speedR = 0;
76-
motorsOutput();
7774
}
7875

79-
76+
motorsOutput();
8077
printSpeed();
8178
printDistances();
8279

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const int distMax = 600; //Distância máxima permitida como referência para os sensores (em milímetros)
2-
const int distAtk = 400;
2+
const int distAtk = 600;
33
const int distAtkMax = 200;
44

55
const int speedMax = 85; //vel max para ser usada durande o ataque
6-
const int speedStandard = 30; //vel padrão --- Cuidado se abaixar para menos de 30!!!
7-
const int searchSpeed = speedStandard*0.6;//vel de girar no proprio eixo
8-
const int aproxSpeed = speedStandard*0.25;//vel ao se aproximar do oponente
6+
const int speedStandard = 25; //vel padrão --- Cuidado se abaixar para menos de
7+
const int speedAtk = 70; //vel padrão --- Cuidado se abaixar para menos de 30!!!
8+
const int searchSpeed = 10;//vel de girar no proprio eixo
99

1010
int fluctuationsCounter = 0;

Software/Autonomous/StandardStrategy/controller_IR.h

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ void controllerIR() {
8181
Serial.println("MORREU");
8282
stage = -10;
8383
break;
84+
case 3:
85+
Serial.println("LOAD");
86+
stage = 0;
87+
digitalWrite(2, HIGH);
88+
break;
8489
}
8590
}
8691
IrReceiver.resume();

0 commit comments

Comments
 (0)