Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Calibratio
Manage
Activity
Members
Labels
Plan
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LuFG VR VIS
VR-Group
Unreal-Development
Tools
Calibratio
Commits
7ed70d7e
Commit
7ed70d7e
authored
1 year ago
by
Sebastian Pape
Browse files
Options
Downloads
Patches
Plain Diff
Code for Calibratio 1.1
parent
32743b7d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
MotionToPhotonMeter.ino
+184
-199
184 additions, 199 deletions
MotionToPhotonMeter.ino
MotionToPhotonServer.cpp
+20
-15
20 additions, 15 deletions
MotionToPhotonServer.cpp
MotionToPhotonServer.h
+12
-5
12 additions, 5 deletions
MotionToPhotonServer.h
data/index.html
+15
-16
15 additions, 16 deletions
data/index.html
with
231 additions
and
235 deletions
MotionToPhotonMeter.ino
+
184
−
199
View file @
7ed70d7e
#include
<ESP32Servo.h>
#include
"MotionToPhotonServer.h"
#include
"esp_task_wdt.h"
/* Enums */
enum
Status
{
Ready
=
0
,
Measuring
=
1
};
String
Status_Text
[
2
]
=
{
"Ready"
,
"Measuring"
};
enum
InternalStatus
{
DefaultReady
,
Moved
};
/* Forward Declarations */
void
startMeasure
ing
(
unsigned
int
numberOfSamples
);
void
startMeasure
ments
(
unsigned
int
numberOfSamples
);
unsigned
int
getPhotoDiodeReading
();
void
setThresholdValue
(
unsigned
int
newThreshold
);
unsigned
int
getDeflectionValue
();
void
setDeflectionValue
(
unsigned
int
newDeflection
);
unsigned
int
getThresholdValue
();
String
getStatus
();
unsigned
int
getCurrentNumberOfResults
();
void
zeroServo
();
void
setLEDExternal
(
bool
LedMoved
);
void
setLED
(
InternalStatus
Status
);
void
abortMeasurement
();
/* Enums */
enum
Status
{
Ready
=
0
,
Measuring
=
1
};
String
Status_Text
[
2
]
=
{
"Ready"
,
"Measuring"
};
enum
InternalStatus
{
Zeroed
,
NotZeroed
,
Stopping
};
/* Hardware */
Servo
rotation_servo
;
#define PhotoPin 33
#define ServoPin 12
#define SensePin 4
#define ButtonPin 23
#define PhotoPin 32
#define Marker1Pin 16
#define Marker2Pin 17
/* Global Values */
int
zeroValueForServo
=
0
;
unsigned
int
deflection
=
10
;
long
startTime
=
-
1
;
int
triggerValue
=
2500
;
#define Timeout 10000000L
unsigned
int
requested_measurements
=
-
1
;
Status
current_status
=
Status
::
Ready
;
InternalStatus
current_internal_status
=
InternalStatus
::
NotZeroed
;
InternalStatus
current_internal_status
=
InternalStatus
::
DefaultReady
;
/* Result Storage */
#define result_buffer_length 10000
...
...
@@ -42,7 +36,7 @@ unsigned long result_buffer[result_buffer_length];
unsigned
int
result_number
=
0
;
/* Server */
MotionToPhotonServer
server
(
result_buffer
,
result_buffer_length
,
getPhotoDiodeReading
,
getThresholdValue
,
setThresholdValue
,
getDeflectionValue
,
setDeflectionValue
,
getStatus
,
startMeasure
ing
,
getCurrentNumberOfResults
,
abortMeasurement
);
MotionToPhotonServer
server
(
result_buffer
,
result_buffer_length
,
getPhotoDiodeReading
,
getThresholdValue
,
setThresholdValue
,
getStatus
,
startMeasure
ments
,
getCurrentNumberOfResults
,
abortMeasurement
,
setLEDExternal
);
/* Multicore */
TaskHandle_t
TaskCore0
;
...
...
@@ -50,34 +44,32 @@ TaskHandle_t TaskCore1;
void
core1
(
void
*
pvParameters
){
while
(
true
){
if
(
current_status
!=
Status
::
Measuring
){
delay
(
5
);
//just small delay
//just small delay while not measuring to not spend to much power in idle
if
(
current_status
==
Status
::
Ready
){
delay
(
5
);
continue
;
}
if
(
current_internal_status
==
InternalStatus
::
NotZeroed
&&
result_number
<
requested_measurements
){
zeroServo
();
//Rearm
// Starting next measurement
if
(
current_internal_status
==
InternalStatus
::
DefaultReady
&&
result_number
<
requested_measurements
){
//Wait for screen to become black again and prevent false resets
for
(
int
i
=
0
;
i
<
10
;
i
++
){
do
{
delay
(
2000
+
random
(
1
,
11
));
// Two seconds + random delay
}
while
(
getPhotoDiodeReading
()
<
triggerValue
);
//Prevent false resets
rotation_servo
.
write
(
zeroValueForServo
-
deflection
);
//deflection movement
delay
(
100
+
random
(
1
,
20
));
}
while
(
getPhotoDiodeReading
()
<
triggerValue
);
}
if
((
current_internal_status
==
InternalStatus
::
Zeroed
||
current_internal_status
==
InternalStatus
::
Stopping
)
&&
digitalRead
(
SensePin
)){
current_internal_status
=
InternalStatus
::
Stopping
;
//Switch marker location and start clock
setLED
(
InternalStatus
::
Moved
);
startTime
=
micros
();
}
if
(
current_internal_status
==
InternalStatus
::
Stopping
&&
getPhotoDiodeReading
()
<
triggerValue
){
//Stop/Record measurement value
if
(
current_internal_status
==
InternalStatus
::
Moved
&&
getPhotoDiodeReading
()
<
triggerValue
){
result_buffer
[
result_number
]
=
micros
()
-
startTime
;
Serial
.
println
(
"Time: "
+
String
(
result_buffer
[
result_number
]));
result_number
++
;
current_i
nternal
_s
tatus
=
InternalStatus
::
NotZeroed
;
setLED
(
I
nternal
S
tatus
::
DefaultReady
);
//Reset to ready
//Finished Measurements
if
(
result_number
>=
requested_measurements
){
...
...
@@ -86,9 +78,9 @@ void core1( void * pvParameters ){
}
}
// Timeout
if
(
current_internal_status
==
InternalStatus
::
Stopping
&&
(
micros
()
-
startTime
)
>
Timeout
){
current_internal_status
=
InternalStatus
::
NotZeroed
;
// Timeout
, Reset without Measurement
if
(
current_internal_status
==
InternalStatus
::
Moved
&&
(
micros
()
-
startTime
)
>
Timeout
){
setLED
(
InternalStatus
::
DefaultReady
);
}
}
}
...
...
@@ -102,13 +94,11 @@ void core0( void * pvParameters ){
void
setup
()
{
Serial
.
begin
(
115200
);
rotation_servo
.
setPeriodHertz
(
50
);
// standard 50 hz servo
rotation_servo
.
attach
(
ServoPin
,
540
,
2470
);
rotation_servo
.
write
(
0
);
pinMode
(
PhotoPin
,
INPUT
);
pinMode
(
SensePin
,
INPUT_PULLDOWN
);
pinMode
(
Marker1Pin
,
OUTPUT
);
pinMode
(
Marker2Pin
,
OUTPUT
);
setLED
(
InternalStatus
::
DefaultReady
);
randomSeed
(
analogRead
(
PhotoPin
)
+
analogRead
(
0
));
//Initalize Random seed
...
...
@@ -139,11 +129,14 @@ void setup() {
void
loop
(){}
//Still needed for arduino core to work
void
startMeasure
ing
(
unsigned
int
numberOfSamples
){
void
startMeasure
ments
(
unsigned
int
numberOfSamples
){
if
(
numberOfSamples
>
result_buffer_length
)
return
;
memset
(
result_buffer
,
0l
,
result_buffer_length
*
sizeof
(
long
));
//clear buffer
result_number
=
0
;
requested_measurements
=
numberOfSamples
;
setLED
(
InternalStatus
::
DefaultReady
);
current_status
=
Status
::
Measuring
;
}
...
...
@@ -154,24 +147,32 @@ unsigned int getPhotoDiodeReading(){
void
abortMeasurement
(){
current_status
=
Status
::
Ready
;
requested_measurements
=
-
1
;
rotation_servo
.
write
(
0
);
current_internal_status
=
InternalStatus
::
NotZeroed
;
setLED
(
InternalStatus
::
DefaultReady
);
}
void
setThresholdValue
(
unsigned
int
newThreshold
){
triggerValue
=
newThreshold
;
}
unsigned
int
getThresholdValue
(){
return
triggerValue
;
void
setLED
(
InternalStatus
Status
){
if
(
Status
==
InternalStatus
::
DefaultReady
){
digitalWrite
(
Marker1Pin
,
HIGH
);
digitalWrite
(
Marker2Pin
,
LOW
);
}
else
{
digitalWrite
(
Marker1Pin
,
LOW
);
digitalWrite
(
Marker2Pin
,
HIGH
);
}
current_internal_status
=
Status
;
}
unsigned
int
getDeflectionValue
(){
return
deflection
;
void
setLEDExternal
(
bool
LedMoved
){
if
(
current_status
==
Status
::
Measuring
)
return
;
//Do not set while measuring
setLED
(
LedMoved
?
InternalStatus
::
Moved
:
InternalStatus
::
DefaultReady
);
}
void
setDeflectionValue
(
unsigned
int
newDeflection
){
deflection
=
newDeflection
;
unsigned
int
getThresholdValue
(
){
return
triggerValue
;
}
String
getStatus
(){
...
...
@@ -181,19 +182,3 @@ String getStatus(){
unsigned
int
getCurrentNumberOfResults
(){
return
max
(
result_number
,
0u
);
}
void
zeroServo
(){
//start a little lower than last time
zeroValueForServo
-=
5
;
rotation_servo
.
write
(
zeroValueForServo
);
delay
(
50
);
do
{
zeroValueForServo
++
;
rotation_servo
.
write
(
zeroValueForServo
);
delay
(
100
);
}
while
(
!
digitalRead
(
SensePin
));
Serial
.
println
(
"Servo zeroed at: "
+
String
(
zeroValueForServo
));
current_internal_status
=
InternalStatus
::
Zeroed
;
}
This diff is collapsed.
Click to expand it.
MotionToPhotonServer.cpp
+
20
−
15
View file @
7ed70d7e
...
...
@@ -2,16 +2,26 @@
/* Server Setup */
MotionToPhotonServer
::
MotionToPhotonServer
(
unsigned
long
*
result_buffer_
,
unsigned
int
result_buffer_length_
,
unsigned
int
(
*
getPhotodiodeReadingFunction
)(),
unsigned
int
(
*
getThresholdFunction
)(),
void
(
*
setThresholdFunction
)(
unsigned
int
),
unsigned
int
(
*
getDeflectionFunction
)(),
void
(
*
setDeflectionFunction
)(
unsigned
int
),
String
(
*
getStatusFunction
)(),
void
(
*
startMeasureFunction
)(
unsigned
int
),
unsigned
int
(
*
getCurrentNumberOfResultsFunction
)(),
void
(
*
abortMeasurementFunction
)())
{
MotionToPhotonServer
::
MotionToPhotonServer
(
unsigned
long
*
result_buffer_
,
unsigned
int
result_buffer_length_
,
unsigned
int
(
*
getPhotodiodeReadingFunction
)(),
unsigned
int
(
*
getThresholdFunction
)(),
void
(
*
setThresholdFunction
)(
unsigned
int
),
String
(
*
getStatusFunction
)(),
void
(
*
startMeasureFunction
)(
unsigned
int
),
unsigned
int
(
*
getCurrentNumberOfResultsFunction
)(),
void
(
*
abortMeasurementFunction
)(),
void
(
*
setLedMovedFunction
)(
bool
)
)
{
getPhotodiodeReading
=
getPhotodiodeReadingFunction
;
getThreshold
=
getThresholdFunction
;
setThreshold
=
setThresholdFunction
;
getDeflection
=
getDeflectionFunction
;
setDeflection
=
setDeflectionFunction
;
getStatus
=
getStatusFunction
;
startMeasure
=
startMeasureFunction
;
abortMeasurement
=
abortMeasurementFunction
;
getCurrentNumberOfResults
=
getCurrentNumberOfResultsFunction
;
setLedMoved
=
setLedMovedFunction
;
result_buffer
=
result_buffer_
;
result_buffer_length
=
result_buffer_length_
;
}
...
...
@@ -34,8 +44,8 @@
server
.
on
(
"/sensor"
,
[
this
](){
this
->
pageSensor
();});
server
.
on
(
"/setThreshold"
,
[
this
](){
this
->
pageSetThreshold
();});
server
.
on
(
"/getThreshold"
,
[
this
](){
this
->
pageGetThreshold
();});
server
.
on
(
"/set
Deflection
"
,
[
this
](){
this
->
pageSet
Deflection
();});
server
.
on
(
"/
g
et
Deflection
"
,
[
this
](){
this
->
page
G
et
Deflection
();});
server
.
on
(
"/set
LedDefault
"
,
[
this
](){
this
->
pageSet
LedDefault
();});
server
.
on
(
"/
s
et
LedMoved
"
,
[
this
](){
this
->
page
S
et
LedMoved
();});
server
.
on
(
"/abort"
,
[
this
](){
this
->
pageAbort
();});
server
.
onNotFound
([
this
](){
this
->
pageNotFound
();});
...
...
@@ -73,19 +83,14 @@
server
.
send
(
200
,
"text/plain"
,
String
(
getThreshold
()));
}
void
MotionToPhotonServer
::
pageSetDeflection
(){
if
(
server
.
args
()
<=
0
){
server
.
send
(
400
,
"text/plain"
,
"No parameters given. Give d=<deflection>"
);
return
;
}
unsigned
int
deflection
=
String
(
server
.
arg
(
0
)).
toInt
();
setDeflection
(
deflection
);
void
MotionToPhotonServer
::
pageSetLedDefault
(){
setLedMoved
(
false
);
server
.
send
(
200
,
"text/plain"
,
"Ok."
);
}
void
MotionToPhotonServer
::
pageGetDeflection
(){
server
.
send
(
200
,
"text/plain"
,
String
(
getDeflection
()));
void
MotionToPhotonServer
::
pageSetLedMoved
(){
setLedMoved
(
true
);
server
.
send
(
200
,
"text/plain"
,
"Ok."
);
}
void
MotionToPhotonServer
::
pageSensor
(){
...
...
This diff is collapsed.
Click to expand it.
MotionToPhotonServer.h
+
12
−
5
View file @
7ed70d7e
...
...
@@ -10,11 +10,10 @@ class MotionToPhotonServer
private:
unsigned
int
(
*
getPhotodiodeReading
)();
unsigned
int
(
*
getThreshold
)();
unsigned
int
(
*
getDeflection
)();
unsigned
int
(
*
getCurrentNumberOfResults
)();
String
(
*
getStatus
)();
void
(
*
setThreshold
)(
unsigned
int
);
void
(
*
set
Deflection
)(
unsigned
int
);
void
(
*
set
LedMoved
)(
bool
);
void
(
*
startMeasure
)(
unsigned
int
);
void
(
*
abortMeasurement
)();
...
...
@@ -41,8 +40,8 @@ class MotionToPhotonServer
void
pageStatus
();
void
pageSetThreshold
();
void
pageGetThreshold
();
void
pageSet
Deflection
();
void
page
G
et
Deflection
();
void
pageSet
LedDefault
();
void
page
S
et
LedMoved
();
void
pageMeasure
();
void
pageResults
();
void
pageIndex
();
...
...
@@ -54,7 +53,15 @@ class MotionToPhotonServer
public:
/* Server functions */
MotionToPhotonServer
(
unsigned
long
*
result_buffer_
,
unsigned
int
result_buffer_length_
,
unsigned
int
(
*
getPhotodiodeReadingFunction
)(),
unsigned
int
(
*
getThresholdFunction
)(),
void
(
*
setThresholdFunction
)(
unsigned
int
),
unsigned
int
(
*
getDeflectionFunction
)(),
void
(
*
setDeflectionFunction
)(
unsigned
int
),
String
(
*
getStatusFunction
)(),
void
(
*
startMeasureFunction
)(
unsigned
int
),
unsigned
int
(
*
getCurrentNumberOfResultsFunction
)(),
void
(
*
abortMeasurementFunction
)());
MotionToPhotonServer
(
unsigned
long
*
result_buffer_
,
unsigned
int
result_buffer_length_
,
unsigned
int
(
*
getPhotodiodeReadingFunction
)(),
unsigned
int
(
*
getThresholdFunction
)(),
void
(
*
setThresholdFunction
)(
unsigned
int
),
String
(
*
getStatusFunction
)(),
void
(
*
startMeasureFunction
)(
unsigned
int
),
unsigned
int
(
*
getCurrentNumberOfResultsFunction
)(),
void
(
*
abortMeasurementFunction
)(),
void
(
*
setLedMoved
)(
bool
));
void
setup
();
void
serve
();
...
...
This diff is collapsed.
Click to expand it.
data/index.html
+
15
−
16
View file @
7ed70d7e
...
...
@@ -2,6 +2,8 @@
<html>
<head>
<meta
charset=
"ISO-8859-1"
>
<title>
Calibratio V1.1
</title>
<!-- Hello you there, reading the code! This was coded by Sebastian Pape aka PapeCoding.de -->
<style>
*
{
font-family
:
Arial
,
Helvetica
,
sans-serif
;
...
...
@@ -65,6 +67,14 @@
document
.
getElementById
(
"
lightSensor
"
).
textContent
=
makeRequest
(
"
sensor
"
);
}
function
setLEDDefault
(){
makeRequest
(
"
setLedDefault
"
);
}
function
setLEDMoved
(){
makeRequest
(
"
setLedMoved
"
);
}
function
setThreshold
(){
if
(
document
.
getElementById
(
"
sensorThreshold
"
).
checkValidity
()){
makeRequest
(
'
setThreshold?t=
'
+
document
.
getElementById
(
"
sensorThreshold
"
).
value
);
...
...
@@ -75,16 +85,6 @@
document
.
getElementById
(
"
sensorThreshold
"
).
value
=
makeRequest
(
'
getThreshold
'
);
}
function
setDeflection
(){
if
(
document
.
getElementById
(
"
servoDeflection
"
).
checkValidity
()){
makeRequest
(
'
setDeflection?d=
'
+
document
.
getElementById
(
"
servoDeflection
"
).
value
);
}
}
function
getDeflection
(){
document
.
getElementById
(
"
servoDeflection
"
).
value
=
makeRequest
(
'
getDeflection
'
);
}
/* Statistics */
function
sum
(
array
)
{
var
num
=
0
;
...
...
@@ -132,7 +132,6 @@
document
.
addEventListener
(
'
DOMContentLoaded
'
,
(
event
)
=>
{
getThreshold
();
getDeflection
();
getStatus
();
getSensor
();
});
...
...
@@ -140,8 +139,8 @@
</head>
<body
style=
"display: flex; flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: center;"
>
<div
class=
"box niceBorder"
style=
"flex: 0 1 75%; text-align: center; padding: 20px;"
>
<div
style=
"font-size: 3em"
>
Calibratio
</div><br
/>
This device measures the movement to photon latency!
<div
style=
"font-size: 3em"
>
Calibratio
V1.1
</div><br
/>
This device measures the movement to photon latency
. No moving parts this time
!
</div>
<div
style=
"display: flex; flex-direction: column; align-items: stretch; flex-wrap: wrap; justify-content: center;"
>
<div
id=
"statistics"
class=
"box niceBorder"
style=
"width: 500px; height: 80px;"
></div>
...
...
@@ -164,9 +163,9 @@
<div
class=
"button"
onclick=
"setThreshold()"
>
Set!
</div>
</div>
<div
class=
"box niceBorder"
>
<div
style=
"padding: 5px;"
>
Servo Deflection
:
</div>
<
input
ty
p
e=
"
number"
id=
"servoDeflection"
min=
"1"
max=
"360"
>
<div
class=
"button"
onclick=
"setDeflection()"
>
Set!
</div>
<div
style=
"padding: 5px;"
>
Manual LED Setting
:
</div>
<
div
class=
"button"
s
ty
l
e=
"
display:inline-block"
onclick=
"setLEDDefault()"
>
Default
</div
>
<div
class=
"button"
style=
"display:inline-block"
onclick=
"setLEDMoved()"
>
Moved
</div>
</div>
<div
class=
"box niceBorder"
>
<div
style=
"padding: 5px;"
>
Times to Meassure:
</div>
...
...
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