Skip to content

Commit 742cdb3

Browse files
author
mahbubur.rahman
committed
[Testing] Final testing
- Did final testing on every file. - Edited documentation of each file. - Added documentation in some file. Task #3.4
1 parent 09ee16c commit 742cdb3

8 files changed

+216
-79
lines changed

CsvHelper.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
class CsvHelper:
44
def __init__(self,lidar_file,flight_file):
55
"""
6-
@param lidar_file: given or generated LIDARPoint.csv file's path
7-
@param flight_file: given or generated FlightPath.csv file's path
6+
This function is the constructor of CsvHelper Class.
87
9-
Constructor of CsvHelper Class
8+
@param lidar_file: given or generated LIDARPoint.csv file's path.
9+
@param flight_file: given or generated FlightPath.csv file's path.
1010
"""
1111
self.lidar_file=lidar_file
1212
self.flight_file=flight_file
1313

1414
def make_list(self,x,y):
1515
"""
16+
This function creates a list of two element.
17+
1618
@param x: An integer or float element
1719
@param y: An integer or float element
18-
1920
@Return: return a list whose elements are x,y
2021
"""
2122
result_list = []
@@ -25,9 +26,11 @@ def make_list(self,x,y):
2526

2627
def read_lidar_element(self):
2728
"""
28-
Read given or pre-generated lidar points
29+
This function reads given or pre-generated lidar points and create
30+
a two dimensional list of lidar point. Each row contains the point
31+
of a distinct sweep.
32+
2933
@Return lidar_points: Return a two dimensional list of lidar point.
30-
Each row contains the point of a distinct sweep
3134
"""
3235
with open(self.lidar_file) as lidar_reader:
3336
read_lidar_point = csv.reader(lidar_reader, delimiter=',')
@@ -49,9 +52,11 @@ def read_lidar_element(self):
4952

5053
def read_flight_path_element(self):
5154
"""
52-
Read given or pre-generated flight path co-oridnates
55+
This function reads given or pre-generated flight path co-oridnates
56+
and make a two dimensional list of flight points. Each row contains
57+
the points of a distinct sweep
58+
5359
@Return flight_points: Return a two dimensional list of flight points.
54-
Each row contains the points of a distinct sweep
5560
"""
5661
with open(self.flight_file) as flight_reader:
5762
read_flight_point = csv.reader(flight_reader, delimiter=',')
@@ -67,11 +72,29 @@ def read_flight_path_element(self):
6772

6873

6974
def write_csv(self,data,file_name_csv):
70-
with open(file_name_csv, "wb") as f:
71-
writer = csv.writer(f)
75+
"""
76+
This function writes data on csv format in a csv file .
77+
78+
@param data: Given data which is going to be written in csv file.
79+
@param file_name_csv: Csv file name in which data will be written.
80+
"""
81+
with open(file_name_csv, "w") as file:
82+
writer = csv.writer(file)
7283
writer.writerows(data)
7384

7485
def write_flight_path(self,flight_path,output_flight_csv):
86+
"""
87+
This function pre-process the flight path points and call
88+
the write_csv function to write data on a given csv file.
89+
In the given flight_path list, only the co-ordinates
90+
are given. Sweep number are not included. So this function
91+
add one additional line/list [sweep number,1] before each flight
92+
co-ordinate and call write_csv to write these data on the file.
93+
94+
@param flight_path: Flight path points/co-ordinates
95+
@param output_flight_csv: File name in which flight path points
96+
will be written.
97+
"""
7598
output_flight_path=[]
7699
for point in range(len(flight_path)):
77100
output_flight_path.append(self.make_list(point,1))

DisplayUtil.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
class DisplayUtil:
44
def __init__(self,sweep_points,flight_points):
55
"""
6-
@param sweep_points: angle and distance of each sweep
7-
@param flight_points: Collection of the flight points
8-
96
Constructor of DisplayUtil class
7+
8+
@param sweep_points: A list with angle and distance of all sweep.
9+
@param flight_points: Collection of the flight points.
1010
"""
1111
self.sweep_points=sweep_points
1212
self.flight_points=flight_points
1313

1414
def plot_sweep(self,x_axis_list,y_axis_list,sweep_number):
1515

1616
"""
17-
Plot a sweep points as well as that sweep's lidar point
18-
plot the lidar position with green color
19-
plot the sweep's points with red color
17+
This function plot a sweep boundary points as well as that sweep's lidar
18+
point. Plot the lidar position with green color and Plot the sweep's points
19+
with red color.
20+
21+
@param x_axis_list: List of x axis points of the sweep boundary points.
22+
@param y_axis_list: List of y axis points of the sweep boundary points.
23+
@param sweep_number: Sweep number which boundary is to be plotted.
2024
"""
2125
plot.figure(sweep_number)
2226
plot.scatter(x_axis_list, y_axis_list, c='r')
@@ -27,15 +31,15 @@ def display_sweep(self):
2731

2832

2933
"""
30-
Calculate all co-ordinates of each sweep using angle and distance based on the lidar's position
31-
1. Convert the angle from degree to redian using the following formula
34+
Calculate all co-ordinates(xi,yi) of each sweep boundary using angle and distance
35+
based on the lidar's position(x,y).
36+
1. Convert the angle from degree to redian using the following formula.
3237
redian= (pi* degree)/180
33-
2. then find the co-ordinate at distance d and angle e using formula
34-
x1=x+d * cos(e)
35-
y1=y+d * sin(e)
36-
where (x,y) is current lidar position.
37-
3. Final divide
38-
Then plot these co-ordinates
38+
2. Then find the co-ordinate at distance d and angle e using formula.
39+
xi=x+d * cos(e)
40+
yi=y+d * sin(e)
41+
where (x,y) is current lidar's position.
42+
3. Finally call the plot sweep function to plot these co-ordinates.
3943
"""
4044
for sweep in range(len(self.sweep_points)):
4145
lidar_x_coordinate=self.flight_points[sweep][0]

MathUtil.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,52 @@
33
from math import pi
44

55
def length(v):
6+
"""
7+
This function calculates the length of a given vector.
8+
9+
@param v: Vector representation of a 2-d coordinates
10+
@Return: Returns the length of the vector.
11+
"""
612
return sqrt(v[0]**2+v[1]**2)
13+
714
def dot_product(v,w):
815
"""
9-
Calculate the dot product of two vector v and w
16+
This function calculate the dot product of two vector v and w.
17+
18+
@param v: Vector representation of a 2-d coordinates.
19+
@param w: Vector representation of a 2-d coordinates.
20+
@Return: Return the dot product of v and w.
1021
"""
1122
return v[0]*w[0]+v[1]*w[1]
23+
1224
def determinant(v,w):
1325
"""
14-
Calculate the determinant of v an w
26+
This function calculate the determinant of two vector v and w.
27+
28+
@param v: Vector representation of a 2-d coordinates.
29+
@param w: Vector representation of a 2-d coordinates.
30+
@Return: Return the determinant of v and w.
1531
"""
1632
return v[0]*w[1]-v[1]*w[0]
1733
def inner_angle(v,w):
1834
"""
19-
Calculate the angle between A and B
35+
This function calculate the inner angle between v and w.
36+
37+
@param v: Vector representation of a 2-d coordinates.
38+
@param w: Vector representation of a 2-d coordinates.
39+
@Return: Return the inner angle of v and w.
2040
"""
2141
cosx=dot_product(v,w)/(length(v)*length(w))
2242
rad=acos(cosx) # in radians
2343
return rad*180/pi # returns degrees
2444

2545
def angle_anti_clockwise(A, B):
2646
"""
27-
Calculate the anti clock-wise angle between A and B
47+
Calculate the anti clock-wise angle between A and B.
48+
49+
@param A: Given 2-d coordinate.
50+
@param B: Given 2-d coordinate.
51+
@Return: Return the anti-clockwise angle between A and B.
2852
"""
2953
inner=inner_angle(A,B)
3054
det = determinant(A,B)
@@ -35,7 +59,10 @@ def angle_anti_clockwise(A, B):
3559

3660
def distance_a_to_b(point_A, point_B):
3761
"""
38-
Calculate the distance between A and B
62+
Calculate the distance between A and B.
63+
@param A: Given 2-d coordinate.
64+
@param B: Given 2-d coordinate.
65+
@Return: Return the distance between A and B.
3966
"""
4067
difference_of_x = (point_A[0] - point_B[0])
4168
difference_of_y = (point_A[1] - point_B[1])

Optimization.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
class Optimization:
44
def __init__(self, sweep_points, flight_points):
55
"""
6-
@param sweep_points: angle and distance of each sweep
7-
@param flight_points: Collection of the flight points
6+
Constructor of DisplayUtil class.
87
9-
Constructor of DisplayUtil class
8+
@param sweep_points: A list of angle and distance of all sweep.
9+
@param flight_points: A list of the flight points.
1010
"""
1111
self.sweep_points = sweep_points
1212
self.flight_points = flight_points
1313

1414
def make_list(self,x,y):
1515
"""
16+
This function creates a list of two element.
17+
1618
@param x: An integer or float element
1719
@param y: An integer or float element
18-
1920
@Return: return a list whose elements are x,y
2021
"""
2122
result_list = []
@@ -28,12 +29,18 @@ def make_list(self,x,y):
2829
def is_possible_a_to_b(self,boundary_point, point_a, point_b):
2930

3031
"""
31-
@param boundary_point: Boundary point of a sweep calculated using given data
32-
@param point_a: Current position of drone
33-
@param point_b: Next position of drone
32+
This function checks whether it is possible to go from point_a to point_b by
33+
straight line. It first calculate the angle between point_a and point_b, then
34+
checks the boundary_point for that angle and also check the boundary for that
35+
angle. If the boundary distance is greater then the distance between point_a
36+
and point_b then it is considered that we can go straightly from point_a to
37+
point_b.
3438
35-
@Return: return 1 if there is no obstacle from point point_a to point_b when it is considered as straight line
36-
otherwise return 0
39+
@param boundary_point: Boundary point of a sweep calculated using given data.
40+
@param point_a: Current position of drone/lidar.
41+
@param point_b: Next position of drone/lidar.
42+
@Return: return 1 if there is no obstacle from point point_a to point_b when it is
43+
considered as straight line otherwise return 0
3744
"""
3845
angle= MathUtil.angle_anti_clockwise(point_a, point_b)
3946
# print(angle)
@@ -51,17 +58,27 @@ def is_possible_a_to_b(self,boundary_point, point_a, point_b):
5158
def optimization(self):
5259

5360
"""
54-
@Return: returns optimized flightPath and for each sweep of that
55-
flight path coordinates return LIDARPoint
61+
Traverse through the path. When I am at position of index i,
62+
I tried to find whether is there any way to go at position of
63+
index j (all j such that j>i) by straight line. For each i, we
64+
check continuously up to the last ending position. When I find any
65+
position of index j which is not reachable from position of index
66+
i, I don't check for the rest position after j. If position of index
67+
j is not reachable by straight line, then I consider that position
68+
of index (j+1) is not reachable by straight line. After position of
69+
index i, I directly go to position of index position of index j as
70+
position of index j is reachable from position of index i. So I just
71+
ommit all the position between index i and j. After that I update i
72+
using j. I insert the position of each i in a list and finally return
73+
that list.
74+
75+
@Return: returns optimized flightPath.
5676
57-
finds a better flight path that will result in the shortest possible
58-
travel time but still goes through the existing rooms.
5977
"""
6078
optimized_sweep_points = []
6179
optimized_flight_points = []
6280
current_sweep = 0
6381
while current_sweep < len(self.flight_points):
64-
print(current_sweep)
6582
optimized_flight_points.append(self.flight_points[current_sweep])
6683
optimized_sweep_points.append(self.sweep_points[current_sweep])
6784
next_sweep =current_sweep + 1

OutputOptimizeFlightPath.csv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
0,1
2+
12.87234,3.62299
3+
1,1
4+
15.9823,6.766453
5+
2,1
6+
17.1553,12.15622
7+
3,1
8+
13.29576,14.33377
9+
4,1
10+
8.850136,7.513073
11+
5,1
12+
7.71862,6.38156
13+
6,1
14+
5.883137,6.75139

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ My main target here is to provide an appropriate visualization of drone's path a
3535
- Read LIDAR data and flight path data from csv file.
3636
- Convert LIDAR data to two dimensional list such that each row contains the data of one sweep.
3737
- I traverse through the path.
38-
- When I am at position of index i, I tried to find wheather is there any way to go at position
38+
- When I am at position of index i, I tried to find whether is there any way to go at position
3939
of index j (all j such that j>i) by straight line.
40-
- For each i, we check continously upto the last ending position.
40+
- For each i, we check continuously upto the last ending position.
4141
- When I find any position of index j which is not reachable from position of index i, I don't
4242
check for the rest position after j. If position of index j is not reachable by straight line,
4343
then I consider that position of index (j+1) is not reachable by straight line.
@@ -61,10 +61,24 @@ My main target here is to provide an appropriate visualization of drone's path a
6161
- python droneflight.py --dis "LIDARDPoints.csv" "FlightPath.csv"
6262

6363
Here please put your own LIDARDPoints.csv and FlightPath.csv file.
64+
To show each sweep please click cross button after showing each sweep.
65+
If we click on the cross button of the figure, current sweep figure will disappear and then next one
66+
will display.
67+
6468
2. To optimize the path please run the following command:
6569

6670
- python droneflight.py --op "LIDARDPoints.csv" "FlightPath.csv" "OutputFlightPath.csv"
6771

6872
Output will be stored in file "OutputFlightPath.csv". Here please put your own LIDARDPoints.csv,
6973
FlightPath.csv and OutputFlightPath.csv file name.
70-
74+
75+
2. To test the optimize the path, please run the following command. It will display the optimized path
76+
after optimization.
77+
78+
- python droneflight.py --test "LIDARDPoints.csv" "FlightPath.csv"
79+
80+
Here please put your own LIDARDPoints.csv and FlightPath.csv file.
81+
To show each sweep please click cross button after showing each sweep.
82+
If we click on the cross button of the figure, current sweep figure will disappear and then next one
83+
will display.
84+

Test.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
from CsvHelper import CsvHelper
22
from DisplayUtil import DisplayUtil
33
from Optimization import Optimization
4-
csv_helper=CsvHelper("points.csv","path.csv")
5-
flight_path=csv_helper.read_flight_path_element()
6-
if len(flight_path)!=34:
7-
print("Number of sweep is not 34!Please check ! May be wrong flight path file included")
8-
else:
9-
for point in range(len(flight_path)):
10-
print(flight_path[point][0],flight_path[point][1])
114

12-
lidar_points=csv_helper.read_lidar_element()
13-
if len(lidar_points)!=34:
14-
print("Number of sweep is not 34!Please check ! May be wrong lidar points file included")
15-
else:
16-
for length in range(len(lidar_points)):
17-
print(length,len(lidar_points[length]))
18-
optimization=Optimization(lidar_points,flight_path)
19-
optimized_lidar_points,optimized_flight_path=optimization.optimization()
20-
display_helper=DisplayUtil(optimized_lidar_points,optimized_flight_path)
21-
display_helper.display_sweep()
5+
def test_optimization(lidar_points_file_name,flight_path_file_name):
6+
"""
7+
This function is used to display each sweep one by one of the optimized
8+
flight path. This function first read_lidar_element() and read_flight_element()
9+
functions from CsvHelper class to read the lidar's point and flight path points
10+
from given csv file. Then it calls optimization function from Optimization class
11+
to optimize the flight path. After that it calls display_sweep function from
12+
DisplayUtil class to display each sweep one by one of the optimized flight path.
13+
14+
@param lidar_points_file_name: Given file name of lidar's point.
15+
@param flight_path_file_name: Given file name of flight path points.
16+
"""
17+
csv_helper=CsvHelper(lidar_points_file_name,flight_path_file_name)
18+
flight_path=csv_helper.read_flight_path_element()
19+
lidar_points=csv_helper.read_lidar_element()
20+
if len(flight_path)!=len(lidar_points):
21+
print("Wrong given data! Number of sweep in booth file is not equal")
22+
else:
23+
optimization=Optimization(lidar_points,flight_path)
24+
optimized_lidar_points,optimized_flight_path=optimization.optimization()
25+
display_helper=DisplayUtil(optimized_lidar_points,optimized_flight_path)
26+
display_helper.display_sweep()
2227

0 commit comments

Comments
 (0)