Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE 445 UI repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aliceg3
ECE 445 UI repo
Commits
aaccef05
Commit
aaccef05
authored
2 years ago
by
aliceg3
Browse files
Options
Downloads
Patches
Plain Diff
push code
parent
994f976c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arduino_code/test_webpage_sensors/test_webpage_sensors.ino
+88
-39
88 additions, 39 deletions
arduino_code/test_webpage_sensors/test_webpage_sensors.ino
with
88 additions
and
39 deletions
arduino_code/test_webpage_sensors/test_webpage_sensors.ino
+
88
−
39
View file @
aaccef05
...
@@ -20,24 +20,37 @@ const char* input_parameter2 = "state";
...
@@ -20,24 +20,37 @@ const char* input_parameter2 = "state";
#define PRESSUREPIN1 34
#define PRESSUREPIN1 34
#define PRESSUREPIN2 35
#define PRESSUREPIN2 35
#define motorIN1 33
#define motorIN2 32
#define motorIN3 26
#define motorIN4 27
#define PRESSURE1GOAL 1000
#define motor1IN1 33
#define PRESSURE2GOAL 2034
#define motor1IN2 32
#define motor1IN3 26
#define motor1IN4 27
Stepper
motor
(
200
,
motorIN1
,
motorIN2
,
motorIN3
,
motorIN4
);
#define motor2IN1 13
//AccelStepper motor(AccelStepper::FULL4WIRE, motorIN1, motorIN2, motorIN3, motorIN4);
#define motor2IN2 14
#define motor2IN3 15
#define motor2IN4 25
#define PRESSURE1GOAL 41
#define PRESSURE2GOAL 39
#define MOTOR1GOAL
#define MOTOR2GOAL
Stepper
motor1
(
200
,
motor1IN1
,
motor1IN2
,
motor1IN3
,
motor1IN4
);
Stepper
motor2
(
200
,
motor2IN1
,
motor2IN2
,
motor2IN3
,
motor2IN4
);
//AccelStepper motor1(AccelStepper::FULL4WIRE, motor1IN1, motor1IN2, motor1IN3, motor1IN4);
// current temperature & humidity, updated in loop()
// current temperature & humidity, updated in loop()
int
pressure1
=
0.0
;
int
pressure1
=
0.0
;
int
pressure2
=
0.0
;
int
pressure2
=
0.0
;
float
motor1Speed
=
0.0
;
float
motor1Speed
=
0.0
;
float
motor2Speed
=
0.0
;
String
pressure1status
=
"NOT YET..."
;
String
pressure1status
=
"NOT YET..."
;
String
pressure2status
=
"NOT YET..."
;
String
pressure2status
=
"NOT YET..."
;
String
motor1status
=
"just started"
;
String
motor1status
=
"just started"
;
String
motor2status
=
"just started"
;
// Create AsyncWebServer object on port 80
// Create AsyncWebServer object on port 80
AsyncWebServer
server
(
80
);
AsyncWebServer
server
(
80
);
...
@@ -105,8 +118,14 @@ const char index_html[] PROGMEM = R"rawliteral(
...
@@ -105,8 +118,14 @@ const char index_html[] PROGMEM = R"rawliteral(
</p>
</p>
<p>
<p>
<i class="fas fa-wrench" style="color:#4a32a8;"></i>
<i class="fas fa-wrench" style="color:#4a32a8;"></i>
<span class="sensorlabel">Motor Status</span>
<span class="sensorlabel">motor1 Status</span>
<span id="motor1status">%MOTOR1STATUS%</span>
<span id="motor1status">%motor1STATUS%</span>
<sup class="units">torque</sup>
</p>
<p>
<i class="fas fa-wrench" style="color:#4a32a8;"></i>
<span class="sensorlabel">motor2 Status</span>
<span id="motor2status">%motor2STATUS%</span>
<sup class="units">torque</sup>
<sup class="units">torque</sup>
</p>
</p>
%BUTTONPLACEHOLDER%
%BUTTONPLACEHOLDER%
...
@@ -173,6 +192,17 @@ setInterval(function ( ) {
...
@@ -173,6 +192,17 @@ setInterval(function ( ) {
xhttp.open("GET", "/motor1status", true);
xhttp.open("GET", "/motor1status", true);
xhttp.send();
xhttp.send();
}, 1000 ) ;
}, 1000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("motor2status").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/motor2status", true);
xhttp.send();
}, 1000 ) ;
</script>
</script>
</html>)rawliteral"
;
</html>)rawliteral"
;
...
@@ -200,13 +230,15 @@ String processor(const String& var){
...
@@ -200,13 +230,15 @@ String processor(const String& var){
else
if
(
var
==
"PRESSURE2STATUS"
){
else
if
(
var
==
"PRESSURE2STATUS"
){
return
String
(
pressure2status
);
return
String
(
pressure2status
);
}
}
else
if
(
var
==
"
MOTOR
1STATUS"
){
else
if
(
var
==
"
motor
1STATUS"
){
return
String
(
motor1status
);
return
String
(
motor1status
);
}
}
else
if
(
var
==
"motor2STATUS"
){
return
String
(
motor2status
);
}
else
if
(
var
==
"BUTTONPLACEHOLDER"
){
else
if
(
var
==
"BUTTONPLACEHOLDER"
){
String
buttons
=
""
;
String
buttons
=
""
;
buttons
+=
"<h4>Output - GPIO 2</h4><label class=
\"
switch
\"
><input type=
\"
checkbox
\"
onchange=
\"
toggleCheckbox(this)
\"
id=
\"
2
\"
"
+
outputState
(
2
)
+
"><span class=
\"
slider
\"
></span></label>"
;
buttons
+=
"<h4>Motor 1 Control</h4><label class=
\"
switch
\"
><input type=
\"
checkbox
\"
onchange=
\"
toggleCheckbox(this)
\"
id=
\"
2
\"
"
+
outputState
(
2
)
+
"><span class=
\"
slider
\"
></span></label>"
;
return
buttons
;
return
buttons
;
}
}
return
String
();
return
String
();
...
@@ -216,7 +248,6 @@ void setup(){
...
@@ -216,7 +248,6 @@ void setup(){
// Serial port for debugging purposes
// Serial port for debugging purposes
Serial
.
begin
(
115200
);
Serial
.
begin
(
115200
);
// motor.setSpeed(60);
// Connect to Wi-Fi
// Connect to Wi-Fi
...
@@ -252,6 +283,9 @@ void setup(){
...
@@ -252,6 +283,9 @@ void setup(){
server
.
on
(
"/motor1status"
,
HTTP_GET
,
[](
AsyncWebServerRequest
*
request
){
server
.
on
(
"/motor1status"
,
HTTP_GET
,
[](
AsyncWebServerRequest
*
request
){
request
->
send_P
(
200
,
"text/plain"
,
String
(
motor1status
).
c_str
());
request
->
send_P
(
200
,
"text/plain"
,
String
(
motor1status
).
c_str
());
});
});
server
.
on
(
"/motor2status"
,
HTTP_GET
,
[](
AsyncWebServerRequest
*
request
){
request
->
send_P
(
200
,
"text/plain"
,
String
(
motor2status
).
c_str
());
});
server
.
on
(
"/update"
,
HTTP_GET
,
[]
(
AsyncWebServerRequest
*
request
)
{
server
.
on
(
"/update"
,
HTTP_GET
,
[]
(
AsyncWebServerRequest
*
request
)
{
String
inputMessage1
;
String
inputMessage1
;
...
@@ -273,32 +307,34 @@ void setup(){
...
@@ -273,32 +307,34 @@ void setup(){
if
(
inputMessage2
.
toInt
()
==
1
){
if
(
inputMessage2
.
toInt
()
==
1
){
// delay(200);
// delay(200);
motor1status
=
"motor running"
;
// doesn't work idk why
motor1status
=
"motor1 running"
;
// doesn't work idk why
// motor.setSpeed(60);
motor2status
=
"awaiting..."
;
// motor.step(500);
// motor11111.setSpeed(60);
//// motor.setSpeed(0);
// motor11111.step(500);
// digitalWrite(motorIN1, LOW);
//// motor11111.setSpeed(0);
// digitalWrite(motorIN2, LOW);
// digitalWrite(motor11111IN1, LOW);
// digitalWrite(motorIN3, LOW);
// digitalWrite(motor11111IN2, LOW);
// digitalWrite(motorIN4, LOW);
// digitalWrite(motor11111IN3, LOW);
// digitalWrite(motor11111IN4, LOW);
// delay(200);
// delay(200);
// motor1status = "reset";
// motor1status = "reset";
// motor.setCurrentPosition(0);
// motor
11111
.setCurrentPosition(0);
// motor.setAcceleration(10);
// motor
11111
.setAcceleration(10);
//
//
// motor.moveTo(2000);
// motor
11111
.moveTo(2000);
//
//
// while(motor.distanceToGo() <= 1000) {
// while(motor
11111
.distanceToGo() <= 1000) {
// motor.setSpeed(80);
// motor
11111
.setSpeed(80);
// motor.runToPosition();
// motor
11111
.runToPosition();
// }
// }
// motor1status = "motor stop";
// motor1status = "motor
11111
stop";
}
}
//
//
if
(
inputMessage2
.
toInt
()
==
0
){
if
(
inputMessage2
.
toInt
()
==
0
){
// motor.setSpeed(0);
// motor
11111
.setSpeed(0);
motor1status
=
"reset"
;
motor1status
=
"reset"
;
motor2status
=
"reset"
;
}
}
...
@@ -322,15 +358,26 @@ void loop(){
...
@@ -322,15 +358,26 @@ void loop(){
int
intervals2
[
7
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
};
int
intervals2
[
7
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
};
int
intervalValues2
[
7
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
};
int
intervalValues2
[
7
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
};
if
(
motor1status
==
"motor running"
){
if
(
motor1status
==
"motor
1
running"
){
motor
.
setSpeed
(
60
);
motor
1
.
setSpeed
(
60
);
motor
.
step
(
500
);
motor
1
.
step
(
500
);
// motor.setSpeed(0);
// motor
11111
.setSpeed(0);
digitalWrite
(
motorIN1
,
LOW
);
digitalWrite
(
motor
1
IN1
,
LOW
);
digitalWrite
(
motorIN2
,
LOW
);
digitalWrite
(
motor
1
IN2
,
LOW
);
digitalWrite
(
motorIN3
,
LOW
);
digitalWrite
(
motor
1
IN3
,
LOW
);
digitalWrite
(
motorIN4
,
LOW
);
digitalWrite
(
motor
1
IN4
,
LOW
);
motor1status
=
"stop"
;
motor1status
=
"stop"
;
motor2status
=
"running..."
;
motor2
.
setSpeed
(
60
);
motor2
.
step
(
-
500
);
// motor11111.setSpeed(0);
digitalWrite
(
motor2IN1
,
LOW
);
digitalWrite
(
motor2IN2
,
LOW
);
digitalWrite
(
motor2IN3
,
LOW
);
digitalWrite
(
motor2IN4
,
LOW
);
motor2status
=
"stop"
;
}
}
...
@@ -365,7 +412,9 @@ void loop(){
...
@@ -365,7 +412,9 @@ void loop(){
}
}
}
}
pressure1
=
(
intervalValues1
[
maxIntervalIndex1
]
/
maxIntervalSize1
)
+
maxIntervalIndex1
*
600
;
pressure1
=
(
intervalValues1
[
maxIntervalIndex1
]
/
maxIntervalSize1
)
+
maxIntervalIndex1
*
600
;
pressure1
=
map
(
pressure1
,
0
,
4095
,
0
,
51.671
);
// max mmHg reading our FSR can take 406
pressure2
=
(
intervalValues2
[
maxIntervalIndex2
]
/
maxIntervalSize2
)
+
maxIntervalIndex2
*
600
;
pressure2
=
(
intervalValues2
[
maxIntervalIndex2
]
/
maxIntervalSize2
)
+
maxIntervalIndex2
*
600
;
pressure2
=
map
(
pressure2
,
0
,
4095
,
0
,
51.671
);
// max mmHg reading our FSR can take 406
if
(((
float
)
abs
(
pressure1
-
PRESSURE1GOAL
)
/
(
float
)
PRESSURE1GOAL
)
<=
0.15
){
if
(((
float
)
abs
(
pressure1
-
PRESSURE1GOAL
)
/
(
float
)
PRESSURE1GOAL
)
<=
0.15
){
pressure1status
=
"LEFT GOAL REACHED"
;
pressure1status
=
"LEFT GOAL REACHED"
;
...
@@ -382,4 +431,4 @@ void loop(){
...
@@ -382,4 +431,4 @@ void loop(){
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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