Skip to content

Commit 28690fb

Browse files
committed
remove unnecessary code
1 parent 0735a9b commit 28690fb

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

comm/reciever/reciever.ino

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <WiFi.h>
44

55

6-
//pin definitions
6+
//definição dos pins
77
#define PWMA 19
88
#define PWMB 27
99
#define A1 5
@@ -12,19 +12,16 @@
1212
#define B2 26
1313
#define stby 33
1414

15-
// This is de code for the board that is in robots
16-
float v_l, v_a;
15+
int robot_id = 9;
16+
int id;
1717
int first_mark, second_mark;
1818

19+
float v_l, v_a;
1920

2021
const byte numChars = 64;
2122
char commands[numChars];
2223
char tempChars[numChars];
2324

24-
int robot_id = 0;
25-
int id;
26-
float robot_vl;
27-
float robot_va;
2825

2926
typedef struct struct_message{
3027
char message[64];
@@ -40,6 +37,7 @@ void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len)
4037
strcpy(commands, rcv_commands.message);
4138
}
4239

40+
4341
void motor_R(int speedR) { // se o valor for positivo gira para um lado e se for negativo troca o sentido
4442
if (speedR > 0) {
4543
digitalWrite(A1, 1);
@@ -50,6 +48,8 @@ void motor_R(int speedR) { // se o valor for positivo gira para um lado e se for
5048
}
5149
ledcWrite(1, abs( speedR));
5250
}
51+
52+
5353
void motor_L(int speedL) {
5454
if (speedL > 0) {
5555
digitalWrite(B1, 1);
@@ -61,6 +61,7 @@ void motor_L(int speedL) {
6161
ledcWrite(2, abs( speedL));
6262
}
6363

64+
6465
void motors_control(float linear, float angular) {
6566
angular = pid(angular, - get_theta_speed());
6667

@@ -116,49 +117,38 @@ void setup() {
116117
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
117118
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
118119
ESP_ERROR_CHECK( esp_wifi_start());
119-
ESP_ERROR_CHECK( esp_wifi_set_channel(14, WIFI_SECOND_CHAN_NONE));
120-
// esp_wifi_set_max_tx_power(84);
121-
122-
// ESP_ERROR_CHECK
123-
// WiFi.mode(WIFI_STA);
124-
// esp_wifi_set_channel(14, WIFI_SECOND_CHAN_NONE);
120+
ESP_ERROR_CHECK( esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE));
125121

126122
if (esp_now_init() != ESP_OK)
127123
{
128124
Serial.println("Error initializing ESP-NOW");
129125
return;
130126
}
131127

132-
// esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
133-
134128
esp_now_register_recv_cb(OnDataRecv);
135129

136130
// configuração mpu
137-
138131
mpu_init();
139132
}
140133

134+
141135
void loop() {
142136
second_mark = millis();
143137

144-
strcpy(tempChars, commands);
138+
strcpy(tempChars, commands); // necessário para proteger a informação original
145139
parseData();
146140

147-
v_l = robot_vl;
148-
v_a = robot_va;
149-
150-
151141
if (second_mark - first_mark > 500) {
152142
v_l = 0.00;
153143
v_a = 0.00;
154144
}
155145

156-
157146
motors_control(v_l, v_a); //aplica os valores para os motores
158147
}
159148

149+
160150
void parseData(){
161-
char * strtokIndx; // this is used by strtok() as an index
151+
char * strtokIndx;
162152

163153
strtokIndx = strtok(tempChars, ",");
164154

@@ -167,9 +157,9 @@ void parseData(){
167157

168158
if(id == robot_id){
169159
strtokIndx = strtok(NULL, ",");
170-
robot_vl = atof(strtokIndx);
160+
v_l = atof(strtokIndx);
171161
strtokIndx = strtok(NULL, ",");
172-
robot_va = atof(strtokIndx);
162+
v_a = atof(strtokIndx);
173163
strtokIndx = strtok(NULL, ",");
174164
}
175165

comm/sender/sender.ino

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#include <WiFi.h>
44

55

6-
// This is the code for the board that is connected to PC
7-
8-
// MAC Adress de cada uma das placas que receberao comandos
6+
// MAC Adress genérico para enviar os dados no canal selecionado
97
uint8_t broadcast_adr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
108

119
//==============
@@ -24,34 +22,28 @@ struct_message commands;
2422

2523
//==============
2624

27-
2825
esp_now_peer_info_t peerInfo;
2926

3027
void setup() {
3128
Serial.begin(115200);
3229

33-
esp_netif_init();
34-
esp_event_loop_create_default();
30+
ESP_ERROR_CHECK(esp_netif_init());
31+
ESP_ERROR_CHECK(esp_event_loop_create_default());
3532
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
36-
esp_wifi_init(&cfg);
37-
esp_wifi_set_storage(WIFI_STORAGE_RAM);
38-
esp_wifi_set_mode(WIFI_MODE_STA);
39-
esp_wifi_start();
40-
esp_wifi_set_channel(14, WIFI_SECOND_CHAN_NONE);
33+
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
34+
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
35+
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
36+
ESP_ERROR_CHECK(esp_wifi_start());
37+
ESP_ERROR_CHECK(esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE));
4138
esp_wifi_set_max_tx_power(84);
4239

43-
// ESP_ERROR_CHECK
44-
// WiFi.mode(WIFI_STA);
45-
// esp_wifi_set_channel(14, WIFI_SECOND_CHAN_NONE);
4640

4741
if (esp_now_init() != ESP_OK)
4842
{
4943
Serial.println("Error initializing ESP-NOW");
5044
return;
5145
}
5246

53-
54-
//
5547
memcpy(peerInfo.peer_addr, broadcast_adr, 6);
5648
if (esp_now_add_peer(&peerInfo) != ESP_OK)
5749
{
@@ -66,9 +58,6 @@ void setup() {
6658
void loop() {
6759
recvWithStartEndMarkers();
6860
if (newData == true){
69-
strcpy(tempChars, receivedChars);
70-
// this temporary copy is necessary to protect the original data
71-
// because strtok() used in parseData() replaces the commas with \0
7261
strcpy(commands.message, receivedChars);
7362
sendData();
7463
newData = false;
@@ -85,7 +74,7 @@ void recvWithStartEndMarkers(){
8574
char in;
8675

8776
while (Serial.available()){
88-
// Message format:
77+
// Formato da mensagem::
8978
// <[id1],[v_l1],[v_a1],[id2],[v_l2],[v_a2],[id3],[v_l3],[v_a3]>
9079
in = Serial.read();
9180

0 commit comments

Comments
 (0)