Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
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
Sara Savanovic Djordjevic
PROG2900
Commits
874970fd
Commit
874970fd
authored
11 months ago
by
Hoa Ben The Nguyen
Browse files
Options
Downloads
Patches
Plain Diff
update: arduino code
parent
7f8e7378
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
droneCode/lidar_setup/lidar_setup.ino
+52
-44
52 additions, 44 deletions
droneCode/lidar_setup/lidar_setup.ino
with
52 additions
and
44 deletions
droneCode/lidar_setup/lidar_setup.ino
+
52
−
44
View file @
874970fd
...
...
@@ -4,54 +4,55 @@
#include
<TinyGPS++.h>
#include
<SoftwareSerial.h>
// #include <TimerOne.h>
#include
<Wire.h>
#include
<LIDARLite.h>
#include
<SD.h>
#include
<SPI.h>
LIDARLite
myLidarLite
;
// LiDar object
TinyGPSPlus
gps
;
// GPS object
SoftwareSerial
ss
(
RXPin
,
TXPin
);
// serial connection to GPS device
// structrue of each measurement in waterbody
struct
WaterBody
{
int
measurementID
;
const
char
*
name
;
float
latitude
;
float
longitude
;
};
// if new coordinates or body of water is added then add it here
//
NB:
if new coordinates or body of water is added then add it here
// define an array of waterbody structures
WaterBody
waterCoords
=
{
{
"mjosa"
,
60.000000
,
1
0
.000000
},
{
"mjosa"
,
6
0
.000000
,
1
0
.000000
},
{
"mjosa"
,
60
.000000
,
1
0
.000000
},
{
"mjosa"
,
6
0
.000000
,
1
0
.000000
},
{
"mjosa"
,
60.000000
,
1
2
.000000
,
1
},
{
"mjosa"
,
6
5
.000000
,
1
1
.000000
,
2
},
{
"mjosa"
,
59
.000000
,
1
2
.000000
,
3
},
{
"mjosa"
,
6
3
.000000
,
1
3
.000000
,
4
},
};
// #define DIR_PIN 2
// #define STEP_PIN 3
#define CHIP_SELECT_PIN 10 \\ Pin connected to the CS pin of SD card moudle
#define MAX_READING 1000 \\ Maximum number of LIDAR readings to store
#define RXPIN 2
#define TXPIN 3
static
const
int
RXPin
=
4
,
TXPin
=
3
;
static
const
uint32_t
GPSBaoud
=
9600
;
// baud rate
const
float
maxRadius
=
5
;
// max distance from location to gps coordinates
// volatile int stepCount = 0;
// volatile int roundCount = 0;
void
setup
()
{
Serial
.
begin
(
GPSBaud
);
// Initialize serial connection to display distances readings
pinMode
(
CHIP_SELECT_PIN
,
OUTPUT
);
if
(
!
SD
.
begin
(
CHIP_SELECT_PIN
)){
Serial
.
println
(
"SD card initialization failed"
);
return
;
}
Serial
.
println
(
"SD card initialized"
);
myLidarLite
.
begin
(
0
,
true
);
// Start sensor and I2C
myLidarLite
.
configure
(
0
);
// set to default mode, balanced performance
ss
.
begin
(
GPSBaud
);
// Start GPS tracking
// pinMode(DIR_PIN, OUTPUT);
// pinMode(STEP_PIN, OUTPUT);
// digitalWrite(DIR_PIN, HIGH);
// Timer1.initialize();
// Timer1.attachInterrupt(tick, 1000000.0f / (3200 * 1));
}
// extra: Reciever bias correction is performed 1 out of every 100 readings
...
...
@@ -60,15 +61,36 @@ void loop() {
while
(
ss
.
available
()
>
0
){
gps
.
encode
(
ss
.
read
());
if
(
gps
.
location
.
isUpdated
()){
for
(
int
i
=
0
;
i
<
waterCoor
s
.
size
(
);
i
++
){
for
(
int
i
=
0
;
i
<
sizeof
(
waterCoor
ds
)
/
sizeof
(
waterCoords
[
0
]
);
i
++
){
// scan after lidar reached designated location
if
withinRadius
(
gps
.
location
.
lat
,
gps
.
location
.
lng
,
waterCoordinates
[
i
][
1
],
waterCoordinates
[
i
][
2
],
maxRadius
)
{
// Take a measurement with receiver bias correction and print to serial terminal
receive
(
true
);
// Take 99 measurement without receiver bias correction and print to serial terminal
for
(
int
i
=
0
;
i
<
99
;
i
++
){
receive
(
false
);
if
withinRadius
(
gps
.
location
.
lat
,
gps
.
location
.
lng
,
waterCoords
[
i
].
latitude
,
waterCoords
[
i
].
longitude
,
maxRadius
)
{
String
filename
=
String
(
waterCoords
[
i
].
name
)
+
"_ID_"
+
String
(
waterCoords
[
i
].
measurementID
)
+
".txt"
;
if
(
SD
.
exist
(
filename
)){
SD
.
remove
(
filename
);
Serial
.
println
(
"File deleted:"
+
filename
);
}
// Create a new file on the SD card
File
dataFile
=
SD
.
open
(
filename
,
FILE_WRITE
);
if
(
!
dataFile
){
Serial
.
println
(
"SD card initialized"
);
// Take 99 measurement without receiver bias correction and print to file
for
(
int
i
=
0
;
i
<
10
;
i
++
){
// convert it to (XYZ) format
sprintf
(
coordinate
,
"%d %d %d
\n\0
"
,(
int
)(
0
,
0
,
myLidarLite
.
distance
(
false
));
datafile
.
println
(
coordinate
);
}
dataFile
.
close
();
// Convert and send them
Serial
.
print
(
s
);
Serial
.
println
(
"File created."
,
filename
);
}
else
{
Serial
.
println
(
"Error opening file for writing: "
,
filename
);
}
}
}
...
...
@@ -87,18 +109,4 @@ void receive(bool bias)
bool
withinRadius
(
float
x1
,
float
y1
,
float
x2
,
float
y2
,
float
radius
){
float
distance
=
sqrt
(
pow
((
x1
-
x2
),
2
)
+
pow
((
y1
-
y2
),
2
));
return
(
distance
<=
radius
);
}
// void tick()
// {
// digitalWrite(STEP_PIN, HIGH);
// //delay(1);
// digitalWrite(STEP_PIN, LOW);
// stepCount++;
// if(stepCount >= 3200)
// {
// stepCount = 0;
// roundCount++;
// }
// }
\ No newline at end of file
}
\ 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