Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
November 2021 Blimp Competition
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shahrul Kamil bin Hassan
November 2021 Blimp Competition
Commits
109f00e2
Commit
109f00e2
authored
3 years ago
by
Zhaoliang Zheng
Browse files
Options
Downloads
Patches
Plain Diff
Test the goal id value
parent
1d7d908b
Branches
Branches containing commit
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/ESP32_communication/test_more_variables/ESP32_slave/ESP32_slave.ino
+99
-0
99 additions, 0 deletions
...unication/test_more_variables/ESP32_slave/ESP32_slave.ino
with
99 additions
and
0 deletions
Code/ESP32_communication/test_more_variables/ESP32_slave/ESP32_slave.ino
0 → 100644
+
99
−
0
View file @
109f00e2
//ESP-NOW: Receiver
//Ref: Random Nerd Tutorials https://randomnerdtutorials.com
//-----------------------------------------------------------
#include
<esp_now.h>
#include
<WiFi.h>
#include
<Wire.h>
//-------------------------------------------------------------------------------------
String
strData
=
""
;
double
valData
=
0.0
;
double
Kpx
=
2
,
Kix
=
0.1
,
Kdx
=
0.25
;
double
Kpy
=
1
,
Kiy
=
0.1
,
Kdy
=
0.25
;
int
g1
=
0
,
g2
=
1
,
g3
=
2
;
int
goal_id
[
3
]
=
{
g1
,
g2
,
g3
};
//-------------------------------------------------------------------------------------
typedef
struct
RxStruct
{
String
StrD
;
double
ValD
;
}
RxStruct
;
RxStruct
receivedData
;
//-------------------------------------------------------------------------------------
void
OnDataRecv
(
const
uint8_t
*
mac
,
const
uint8_t
*
incomingData
,
int
len
)
{
memcpy
(
&
receivedData
,
incomingData
,
sizeof
(
receivedData
));
Serial
.
print
(
"data:"
);
Serial
.
println
(
receivedData
.
StrD
);
Serial
.
println
(
receivedData
.
ValD
);
strData
=
receivedData
.
StrD
;
valData
=
receivedData
.
ValD
;
}
//======================================================================================
void
setup
()
{
Serial
.
begin
(
9600
);
WiFi
.
mode
(
WIFI_STA
);
if
(
esp_now_init
()
!=
ESP_OK
)
{
Serial
.
println
(
"Error initializing ESP-NOW"
);
return
;
}
esp_now_register_recv_cb
(
OnDataRecv
);
}
//======================================================================================
void
loop
()
{
Kpx
=
getDoubleVal
(
strData
,
"kpx"
,
valData
,
Kpx
);
Kix
=
getDoubleVal
(
strData
,
"kix"
,
valData
,
Kix
);
Kdx
=
getDoubleVal
(
strData
,
"kdx"
,
valData
,
Kdx
);
Kpy
=
getDoubleVal
(
strData
,
"kpy"
,
valData
,
Kpy
);
Kiy
=
getDoubleVal
(
strData
,
"kiy"
,
valData
,
Kiy
);
Kdy
=
getDoubleVal
(
strData
,
"kdy"
,
valData
,
Kdy
);
g1
=
getDoubleVal
(
strData
,
"gda"
,
valData
,
goal_id
[
0
]);
g2
=
getDoubleVal
(
strData
,
"gdb"
,
valData
,
goal_id
[
1
]);
g3
=
getDoubleVal
(
strData
,
"gdc"
,
valData
,
goal_id
[
2
]);
goal_id
[
0
]
=
g1
;
goal_id
[
1
]
=
g2
;
goal_id
[
2
]
=
g3
;
Serial
.
print
(
"gid:"
);
Serial
.
print
(
goal_id
[
0
]);
Serial
.
print
(
goal_id
[
1
]);
Serial
.
println
(
goal_id
[
2
]);
/*
Serial.print("Kpx:");
Serial.println(Kpx);
Serial.print("Kix:");
Serial.println(Kix);
Serial.print("Kdx:");
Serial.println(Kdx);
Serial.print("Kdy:");
Serial.println(Kdy);
Serial.print("Kiy:");
Serial.println(Kiy);
Serial.print("Kdy:");
Serial.println(Kdy);
*/
}
double
getDoubleVal
(
String
checkData
,
String
Ans
,
double
val
,
double
ori_val
){
if
(
checkData
==
Ans
){
strData
=
""
;
valData
=
0.0
;
return
val
;
}
else
{
return
ori_val
;
}
}
int
getIntVal
(
String
checkData
,
String
Ans
,
double
val
,
int
ori_val
){
if
(
checkData
==
Ans
){
strData
=
""
;
valData
=
0.0
;
return
(
int
)
val
;
}
else
{
return
ori_val
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment