-
Notifications
You must be signed in to change notification settings - Fork 1
/
hazretimahmut.py
1736 lines (1469 loc) · 57.2 KB
/
hazretimahmut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#/*
# @year: 2020/2021
# @authors: Sekomer, ubuntumevuz
# @touch: aksoz19@itu.edu.tr
# @touch: koseoglumu18@itu.edu.tr
#*/
import os
import sys
import csv
import math
import time
import rospy
import numba
import seaborn
import numpy as np
from numba import float32 as f32
from matplotlib import pyplot as plt
from rosserial_arduino.msg import Adc
from std_msgs.msg import String
from itertools import cycle
from sensor_msgs.msg import LaserScan, Joy
from numpy.lib.function_base import average
from geometry_msgs.msg import Point
#from pynput.keyboard import Key, Listener
np.seterr('raise')
# global variables #
TWO_THIRD_PARKING = True
REVERSE_PARKING = False
speed = 0
regen = 0
DURMAK = 0
steering_angle = 1800
speed_odometry = 0
brake_speed = 0
brake_motor_direction = 1
sol_laser = None
sag_laser = None
collecting_data = False
SOL = 0
ORTA = 1
SAG = 2
AUTONOMOUS_SPEED = 39 # never change this variable randomly!!!
AUTONOMOUS_SPEED_RECOVERY = AUTONOMOUS_SPEED
POT_CENTER = 1800
MAX_RPM_MODE_SPEED = 200
RPM_MODE = 1
CURRENT_MODE = 0
driving_mode = RPM_MODE
DORU = (1 == 1)
left_tracking = 0
right_tracking = 1
mid_tracking = 0
girildim_counter = 0
girildim_bool = True
NEUTRAL = 0
FORWARD = 1
REVERSE = 2
CAR_WIDTH = 1.5
CAR_LENGTH = 2.25
CURRENT = 0
BUS_VOLTAGE = 0
BICYCLE_LENGTH = 3.5
SOL_FIXED = 2.65
SAG_FIXED = 2.65
kararVerici = np.array([0, 1, 0])
recently_stopped = False
recently_stopped_kirmizi = False
orhandaldal = np.inf
mahmut_tuncer = np.inf
brake = False
brake_value = 0
roswtf = False
FULL_RIGHT = 0
FULL_LEFT = 3600
left_point_distance = 0
right_point_distance = 0
karar_verici_yakın_zamanda_calisti = False
kirmizida_dur_lan = False
ahaburasıdaboşmuşıheahıeah = False
olceriz_sıkıntı_yog = np.inf
YOLCU = 37
hazreticounter = 0
experimental_park_stage_1 = False
experimental_park_stage_2 = False
mahmutapozisyonçeşitliliği = np.array([.0, .0, .0])
igotthepose = False
yesil_gorundu = False
büllük = False
güllük = np.array([.0,.0,.0])
# durak experimental #
first_stop_counter = False
first_stop = False
second_stop_counter = False
second_stop = False
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-#
arduino_odometry = {
'speed': .0,
'steering_angle': .0,
'bus_voltage': .0,
'bus_current': .0
}
# terminal colors #
class bcolors:
HEADER = '\033[95m' #mor
OKBLUE = '\033[94m' #mavi
OKCYAN = '\033[96m' #turkuaz
OKGREEN = '\033[92m' #yeşil
WARNING = '\033[93m' #sarı
FAIL = '\033[91m' #kırmızı
ENDC = '\033[0m' #beyaz
BOLD = '\033[1m' #kalın beyaz
UNDERLINE = '\033[4m' #aktı çizili beyaz
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*#
# controller #
def gen():
gears = [NEUTRAL, FORWARD, NEUTRAL, REVERSE]
for i in cycle(gears):
yield i
gear_generator = gen()
AUTONOMOUS = False
GEAR = next(gear_generator)
DIRECTION = True
LIGHTS = False
EMERGENCY = False
CRUISE_CONTROL = False
YAVIZ = False
SEKO = False
TERMINATOR = False
l_left_right = 0
l_up_down = 0
r_left_right = 0
r_up_down = 0
left_trigger = 1
right_trigger = 1
BUTTON_A = 0
BUTTON_B = 0
BUTTON_X = 0
BUTTON_Y = 0
BUTTON_LB = 0
BUTTON_RB = 0
BUTTON_BACK = 0
BUTTON_START = 0
BUTTON_STICK_LEFT = 0
BUTTON_STICK_RIGHT = 0
stage1 = True
stage2 = False
stage3 = False
stage4 = False
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-#
# parking
is_parking_mode = False
is_curve_parking = False
is_durak_mode = False
park_coordinate = None
zed_x = None
zed_y = None
zed_z = None
durak_dik_start = None
denk_coef = None
closest_point = None
is_curve_created = False
CRITICAL_PARKING_DISTANCE = 15
CALCULATE_PARKING_SIGN_DISTANCE = 10
locked_on_target = False
parking_sign_current_distance = None
park_left_not_started = True
ACKERMAN_RADIUS = 4
LABEL_OFFSET = 9.
ERROR_ACCEPTANCE = .3
karsiya_geciyorum = False
DIKEY = 0 # 0->(dikey / x)
YATAY = 1 # 1->(yatay / y)
twothird = 1400
park_distance = np.inf
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-#
# helper funcs #
global_radius = None
@numba.jit(f32(f32, f32, f32), nopython=True, fastmath=True)
def ackermann(fi, L, t):
toa = math.tan(math.radians(fi))
radius = (L + (t/2 * toa)) / toa
return radius
@numba.jit(f32(f32, f32, f32, f32, f32), nopython=True, fastmath=True, cache=True)
def mapper(value, in_min, in_max, out_min, out_max):
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
@numba.jit(f32(f32, f32), nopython=True, fastmath=True, cache=True)
def potingen_straße(desired, difference):
return (desired + 0.5 + difference) * 3600
@numba.jit(f32(f32, f32, f32, f32, f32, f32), nopython=True, fastmath=True, cache=True)
def fast_pid(p_error, Kp, i_error, Ki, d_error, Kd):
return (p_error * Kp) + (i_error * Ki) + (d_error * Kd)
@numba.jit(nopython=True, fastmath=True, cache=True)
def fast_pp(right_point_distance, left_point_distance, bicycle_length = BICYCLE_LENGTH):
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
hipotenus = math.sqrt(math.pow(right_point_distance,2) + math.pow(left_point_distance,2))
lookahead_distance = hipotenus / 2
theta = math.degrees(math.atan(right_point_distance / left_point_distance))
target_direction_angle = 90 - (2 * theta)
formula = (2 * bicycle_length * math.sin(math.radians(target_direction_angle))) / lookahead_distance
return math.degrees(math.atan(formula)) / 180
@numba.jit(nopython=True, fastmath=True, cache=True)
def fast_pp2(right_point_distance, left_point_distance, bicycle_length = BICYCLE_LENGTH):
hipotenus = math.sqrt(math.pow(right_point_distance,2) + math.pow(left_point_distance,2))
lookahead_distance = hipotenus / 2
theta = math.degrees(math.atan(right_point_distance / left_point_distance))
target_direction_angle = 90 - (2 * theta)
formula = (2 * bicycle_length * math.sin(math.radians(target_direction_angle))) / lookahead_distance
return math.degrees(math.atan(formula)) / 180
def control_mahmut(data):
# speed
if (data.adc0 > 1000):
data.adc0 = 1000
elif (data.adc0 < 0):
data.adc0 = 0
# steer
if (data.adc1 > 3600):
data.adc1 = 3600
elif (data.adc1 < 0):
data.adc1 = 0
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*#
class Steering_Algorithms:
class PID(object):
def __init__(self, kp, ki, kd):
self.Kp = kp
self.Ki = ki
self.Kd = kd
self.p_error = 0.0
self.d_error = 0.0
self.i_error = 0.0
self.prev_cte = 0.0
self.pidError = 0.0
self.teta = 0.0
self.error = 0.0
def calculate(self, distance):
self.error = distance - self.teta
self.p_error = self.error
self.i_error += self.error
self.d_error = self.error - self.prev_cte
self.prev_cte = self.error
if distance < 0.15:
self.i_error = 0
self.pidError = fast_pid(self.p_error, self.Kp, self.i_error, self.Ki, self.d_error, self.Kd)
self.teta += self.pidError
if self.teta < -0.5:
self.teta = -0.5
elif self.teta > 0.5:
self.teta = 0.5
print("teta: {:.2f}".format(self.teta))
return self.teta
class Pure_Pursuit_Controller():
def __init__(self, bicycle_length, lookahead_distance, target_direction_angle):
self.bicycle_length = bicycle_length
self.lookahead_distance = lookahead_distance
self.target_direction_angle = target_direction_angle
self.steering = 0
def target_finder(self, laser):
right_point_distance = np.average(laser.ranges[1080:1260])
left_point_distance = np.average(laser.ranges[180:360])
print("distance")
print(right_point_distance)
print(left_point_distance)
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
hipotenus = math.sqrt(math.pow(right_point_distance,2) + math.pow(left_point_distance,2))
self.lookahead_distance = hipotenus / 2
theta = math.degrees(math.atan(right_point_distance / left_point_distance))
self.target_direction_angle = 90 - 2 * theta
self.steering_calculator()
def steering_calculator(self):
formula = ((2 * self.bicycle_length * math.sin(math.radians(self.target_direction_angle))) / self.lookahead_distance)
self.steering = (math.degrees(math.atan((formula))))
print("steering")
print(self.steering)
print(self.steering / 180)
if self.steering < -.5:
self.steering = -.5
elif self.steering > .5:
self.steering = .5
#####################################################################################################################
"""
@future
Requires positional knowledge
"""
class park_seko(object):
def __init__(self, ackermann_radius, label_offset, error_acceptance = 0.5):
self.__target = []
self.__margin = np.inf
self.__destiny = False
self.__current_pos = []
self.__label_offset = label_offset
self.__error_acceptance = error_acceptance
self.__ackermann_radius = ackermann_radius
def __eval__(self):
# offset x mi y mi kontrol et
#@ZED değiştirilecek!
ackermann_target_x = self.__target[0] - ACKERMAN_RADIUS - LABEL_OFFSET # @!!!
ackermann_target_y = self.__target[1] - ACKERMAN_RADIUS # @!!!
xd = math.pow(ackermann_target_x - self.__current_pos[0], 2)
yd = math.pow(ackermann_target_y - self.__current_pos[1], 2)
self.__margin = math.sqrt(xd + yd)
if self.__margin < self.__error_acceptance:
self.__destiny = True
"""
Deprecated
"""
class serhatos(object):
def __init__(self):
self.coefficents = []
self.steering_angle = 0
self.CP = list()
def find_curve(self, x, y, degree):
self.coefficents = np.polyfit(x, y, degree)
return self.coefficents
def find_all_point_on_the_curve(self,coef,park_y):
all_y = np.zeros(shape=(10,))
all_x = np.linspace(-3,park_y,10)
for a,x in enumerate(all_x):
tot = 0
for i,j in enumerate(reversed(coef)):
tot += (x **i) * j
all_y[a] = tot
for i, j in zip(all_x,all_y):
#self.CP.append(CurvePoint(i, j))
print(i, j)
def choose_closest_point(self, x, y):
min_error = np.inf
return_obj = None
for obj in self.CP:
if obj.visited: continue
error_x = obj.x - x
error_y = obj.y - y
error = math.pow(error_x, 2) + math.pow(error_y, 2)
if error < min_error:
return_obj = obj
min_error = error
return return_obj
def is_that_point(self,p1,p2_x,p2_y):
if not p1 or not p2_x: return
error_x = p1.x-p2_x
error_y = p1.y-p2_y
error = math.sqrt(pow(error_x, 2) + pow(error_y, 2))
if error<5:
return True
else:
return False
def point2pointAngle(self,p1,p2):
error_x = p1.x-p2[0]
error_y = p1.y-p2[1]
angle = math.degrees(math.atan(error_x/error_y))
return angle
def distance_calculator(self,p1,p2):
distance_x = p1[0]-p2[0]
distance_y = p1[1]-p2[1]
distance = ((distance_x)**2+(distance_y)**2)**1/2
return distance
#####################################################################################################################
düz_gitmek = True
mid_start = np.array([.0, .0, .0], dtype=np.float32)
# main function #
def lidar_data(veri_durak):
global YOLCU
global DURMAK
global speed
global regen
global steering_angle
global is_parking_mode
global is_durak_mode
global park_coordinate
global speed_odometry
global AUTONOMOUS_SPEED
global FULL_RIGHT
global brake_speed
global brake_motor_direction
global stage1
global left_tracking
global right_tracking
global mid_tracking
global driving_mode
global pürşit
global is_curve_parking
# PARK #
global zed_x
global zed_y
global zed_z
global park_distance
global durak_dik_start
global denk_coef
global closest_point
global recently_stopped
####################################
# YAPAY ZEKA DUNYAYI ELE GECIRECEK #
####################################
global arduino_odometry
global sol_laser
global sag_laser
global collecting_data
global brake
global brake_value
global roswtf
global orhandaldal
global recently_stopped_kirmizi
global mahmut_tuncer
global parking_sign_current_distance
global right_point_distance
global left_point_distance
global kirmizida_dur_lan
global karar_verici_yakın_zamanda_calisti
global ahaburasıdaboşmuşıheahıeah
global olceriz_sıkıntı_yog
global sol_array
global right_array
global hazreticounter
global güllük
global büllük
global mahmutapozisyonçeşitliliği
global igotthepose
global TWO_THIRD_PARKING
global REVERSE_PARKING
global stage1
global stage2
global stage3
global stage4
global experimental_park_stage_1
global experimental_park_stage_2
global yesil_gorundu
global kirmizi_distance
global mid_start # array
global düz_gitmek # bool
global girildim_counter
global girildim_bool
global karsiya_geciyorum
#sol_laser = np.array(veri_durak.ranges[0:369], dtype=np.float32)
#sag_laser = np.array(veri_durak.ranges[1079:1439], dtype=np.float32)
#sol_laser[sol_laser>25] = 25
#sag_laser[sag_laser>25] = 25
print("trackings:", left_tracking, mid_tracking, right_tracking)
if ahaburasıdaboşmuşıheahıeah:
pass
# TUNE ET
"""
while olceriz_sıkıntı_yog + 3 > time.time():
mahmut.adc0 = AUTONOMOUS_SPEED
mahmut.adc1 = 1800
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = driving_mode
"""
while olceriz_sıkıntı_yog + 4 > time.time():
print("ahaburası da bosmus yav")
zol = np.array(veri_durak.ranges[560:672])
zag = np.array(veri_durak.ranges[224:336])
solumsu = zol[zol > 2.78] = 2.78
sagimsi = zag[zag > 2.78] = 2.78
xd = fast_pp(average(sagimsi), average(solumsu))
mahmut.adc0 = AUTONOMOUS_SPEED
mahmut.adc1 = int(xd)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = driving_mode
time.sleep(1/20)
arduino.publish(mahmut)
ahaburasıdaboşmuşıheahıeah = False
"""
if roswtf:
mahmut.adc0 = 0
mahmut.adc2 = 11000
arduino.publish(mahmut)
print(bcolors.WARNING+"Hoş geldiğiz!"+bcolors.ENDC)
start = time.time()
while time.time() - start < 10:
arduino.publish(mahmut)
mahmut.adc0 = AUTONOMOUS_SPEED_RECOVERY
mahmut.adc2 = 0
roswtf = False
orhandaldal = time.time()
print(bcolors.WARNING+"BBBBBB!"+bcolors.ENDC)
"""
if orhandaldal + 15 < time.time():
recently_stopped = False
#if roswtf and abs(math.sqrt(math.pow(durak_dik_start[0] - zed_x, 2) + math.pow(durak_dik_start[1] - zed_z, 2))) > 4:
if roswtf:
print(bcolors.WARNING+"DURAK START"+bcolors.ENDC)
start = time.time()
if not igotthepose:
mahmutapozisyonçeşitliliği[0] = zed_x
mahmutapozisyonçeşitliliği[1] = zed_y
mahmutapozisyonçeşitliliği[2] = zed_z
igotthepose = True
print("duraktan beri gittiğim yol: ", math.sqrt(math.pow(mahmutapozisyonçeşitliliği[0] - zed_x, 2) + math.pow(mahmutapozisyonçeşitliliği[2] - zed_z, 2)))
# pose difference
if math.sqrt(math.pow(mahmutapozisyonçeşitliliği[0] - zed_x, 2) + math.pow(mahmutapozisyonçeşitliliği[2] - zed_z, 2)) > 3.5:
while time.time() < start + YOLCU:
mahmut.adc0 = 0
mahmut.adc1 = 1800
mahmut.adc2 = 11000
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = driving_mode
arduino.publish(mahmut)
qoıwheqdw = round(time.time() - start, 2)
print(bcolors.WARNING + f"{qoıwheqdw} saniyedir DURAKTAYIZZZZ" + bcolors.ENDC)
time.sleep(1/20)
orhandaldal = time.time()
roswtf = False
igotthepose = False
left_tracking = True
right_tracking = False
mid_tracking = False
print(bcolors.WARNING+"DURAK FINISH!"+bcolors.ENDC)
if collecting_data:
writer.writerow([sol_laser, sag_laser, arduino_odometry['steering_angle']])
print(bcolors.WARNING + "COLLECTING DATA" + bcolors.ENDC)
#######
# END #
#######
""" sol_x = np.array(veri_durak.ranges[300:360])
sol_y = np.array(veri_durak.ranges[240:300])
sol_z = np.array(veri_durak.ranges[180:240])
sag_x = np.array(veri_durak.ranges[1080:1140])
sag_y = np.array(veri_durak.ranges[1140:1200])
sag_z = np.array(veri_durak.ranges[1200:1260]) """
on_array = np.array(veri_durak.ranges[440:456])
sol_array = np.array(veri_durak.ranges[560:672])
right_array = np.array(veri_durak.ranges[224:336])
sol_array[sol_array > 5] = 5
right_array[right_array > 5] = 5
distances = {
'right': np.average(right_array),
'left': np.average(sol_array),
'on' : np.average(on_array)
}
print(bcolors.WARNING + "ON MESAFE: " + bcolors.ENDC, distances['on'])
print(bcolors.WARNING + "park distance:" + bcolors.ENDC, park_distance)
print(bcolors.WARNING + "park coord: " + bcolors.ENDC, park_coordinate)
print("GIRILMEZ COUNTER", girildim_counter)
if TERMINATOR:
if AUTONOMOUS:
print(bcolors.WARNING + "AUTONOMOUS" + bcolors.ENDC)
driving_mode = RPM_MODE
if kirmizida_dur_lan:
print(bcolors.WARNING + "KIRMIZIYA GELDİM SANKİ" + bcolors.ENDC)
mahmut.adc0 = AUTONOMOUS_SPEED
mahmut.adc1 = int(1800)
mahmut.adc2 = 11000
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = driving_mode
elif mid_tracking == True:
if düz_gitmek:
mid_start[0] = zed_x
mid_start[1] = zed_y
mid_start[2] = zed_z
düz_gitmek = False
print(bcolors.FAIL + "MID_TRACKING" + bcolors.ENDC)
#
# CHECK THE DIRECTION
#pürşit.target_finder(laser=veri_durak)
mid_sol_array = np.array(veri_durak.ranges[399:435])
mid_sag_array = np.array(veri_durak.ranges[462:498])
right_point_distance = np.average(mid_sol_array)
left_point_distance = np.average(mid_sag_array)
if(right_point_distance > 25):
right_point_distance = 25
if(left_point_distance > 25):
left_point_distance = 25
print("right point distance", right_point_distance)
print("left point distance", left_point_distance)
steering = fast_pp2(right_point_distance, left_point_distance)
print("steering:", steering)
#pid method
#steering = pid_controller.calculate(distances['left'] - distances['right'])
if steering < -.5:
steering = -.5
elif steering > .5:
steering = .5
angle = potingen_straße(steering, POT_CENTER-1800)
print("aci:", angle)
print("desired direction angle:", angle)
# doldur
mahmut.adc0 = int(AUTONOMOUS_SPEED)
mahmut.adc1 = int(angle)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(RPM_MODE)
right_point_distance = np.average(right_array)
left_point_distance = np.average(sol_array)
anlık_fark = math.sqrt(math.pow(mid_start[0] - zed_x, 2) + math.pow(mid_start[2] - zed_z, 2))
print("ANLIKKKKK FARKKKK:::::", anlık_fark)
print("GIRLDIM BOOl", girildim_bool)
if right_point_distance < 3.0 and anlık_fark > 7:
left_tracking = True
mid_tracking = False
right_tracking = False
düz_gitmek = True
print(bcolors.FAIL + "ARANIYORUM HER YERDE KIRMIZI BULTENLE" + bcolors.ENDC)
girildim_bool = True
girildim_counter += 1
karsiya_geciyorum = False
elif left_point_distance < 3.0 and anlık_fark > 7:
left_tracking = True
mid_tracking = False
right_tracking = False
düz_gitmek = True
print(bcolors.FAIL + "ARANIYORUM HER YERDE KIRMIZI BULTENLE" + bcolors.ENDC)
girildim_bool = True
girildim_counter += 1
karsiya_geciyorum = False
elif left_tracking == DORU:
print(bcolors.FAIL + "LEFT_TRACKING" + bcolors.ENDC) #
# CHECK THE DIRECTION
#
right_point_distance = np.average(right_array)
left_point_distance = np.average(sol_array)
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
steering = fast_pp(SAG_FIXED, left_point_distance)
#pid method
#steering = pid_controller.calculate(distances['left'] - distances['right'])
if steering < -.5:
steering = -.5
elif steering > .5:
steering = .5
angle = potingen_straße(steering, POT_CENTER-1800)
# doldur
mahmut.adc0 = int(AUTONOMOUS_SPEED)
mahmut.adc1 = int(angle)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
elif right_tracking == DORU:
print(bcolors.FAIL + "RIGHT_TRACKING" + bcolors.ENDC)
right_point_distance = np.average(right_array)
left_point_distance = np.average(sol_array)
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
steering = fast_pp(right_point_distance, SOL_FIXED)
#pid method
#steering = pid_controller.calculate(distances['left'] - distances['right'])
if steering < -.5:
steering = -.5
elif steering > .5:
steering = .5
angle = potingen_straße(steering, POT_CENTER-1800)
# doldur
mahmut.adc0 = int(AUTONOMOUS_SPEED)
mahmut.adc1 = int(angle)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
# <Parking Autonomous>
elif is_parking_mode: #elif is_parking_mode:
print(bcolors.WARNING + 10 * '-' + "PARKING MODE \n" + 10 * '-' + bcolors.ENDC)
# full sag, ortalanınca middle takip park modu
if 0:
if park_distance > 10 and not experimental_park_stage_1:
right_point_distance = np.average(right_array)
left_point_distance = np.average(sol_array)
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
# !!!!!!!! 1.5 !!!!!!!!!!
steering = fast_pp(1.5 , left_point_distance)
if steering < -.5:
steering = -.5
elif steering > .5:
steering = .5
angle = potingen_straße(steering, POT_CENTER-1800)
if park_coordinate > 1600:
experimental_park_stage_1 = True
mahmut.adc0 = int(0)
mahmut.adc1 = int(angle)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
elif experimental_park_stage_1 and not experimental_park_stage_2:
mahmut.adc0 = int(AUTONOMOUS_SPEED)
mahmut.adc1 = int(FULL_RIGHT) # ölümüne sağ
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
if abs(850 - park_coordinate) < 100:
experimental_park_stage_2 = True
else:
print("EXPERiMENTAL PARKiNG LasT StaGE")
target_diff = (850 - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
mahmut.adc0 = int(AUTONOMOUS_SPEED)
mahmut.adc1 = int(steer) # face your destiny mahmut
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
if distances['on'] < 1.5:
while True:
mahmut.adc0 = DURMAK
mahmut.adc1 = 1800
mahmut.adc2 = 11000
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
arduino.publish(mahmut)
print("DURDUM \m/!")
time.sleep(1/20)
# raw two third mode
elif 0:
if distances['on'] > 7.5:
print("TWO THIRD PARK")
target_diff = (twothird - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
else:
print("MIDDLE PARk")
target_diff = (850 - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
if distances['on'] < 1.5:
while True:
mahmut.adc0 = DURMAK
mahmut.adc1 = 1800
mahmut.adc2 = 11000
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
arduino.publish(mahmut)
print("DURDUM \m/!")
time.sleep(1/20)
mahmut.adc0 = AUTONOMOUS_SPEED
mahmut.adc1 = int(steer)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
# first left track, düzgün park distance sonrası two_third/mid tracking
elif 1:
#stagei buradan kaldır ya da adını degistir xd
if stage1:
print(bcolors.FAIL+"ONEMLİ BURAYA GİRİYOR MU 1, sollu"+bcolors.ENDC)
right_point_distance = np.average(right_array)
left_point_distance = np.average(sol_array)
if(right_point_distance > 5):
right_point_distance = 5
if(left_point_distance > 5):
left_point_distance = 5
parksagdistance = 1.55
steering = fast_pp(parksagdistance, left_point_distance)
if steering < -.5:
steering = -.5
elif steering > .5:
steering = .5
angle = potingen_straße(steering, POT_CENTER-1800)
if park_coordinate > 1500:
stage1 = False
# doldur
mahmut.adc0 = int(37)
mahmut.adc1 = int(angle)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
else:
print("stage1 in else kısmı")
if park_distance > 6.1 and yavizseko: #yaviz
print("TWO THIRD PARK")
target_diff = (twothird - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
else:
print("MIDDLE PARk")
target_diff = (850 - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
mahmut.adc0 = int(37)
mahmut.adc1 = int(steer)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
if distances['on'] < 2.5:
mahmut.adc0 = DURMAK
mahmut.adc1 = 1900
mahmut.adc2 = 11000
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
print(bcolors.FAIL+"DURMAK \m/!"+bcolors.ENDC)
elif distances['on'] < 3.1:
mahmut.adc0 = int(37)
mahmut.adc1 = 2000
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
print(bcolors.FAIL+"YAVASLAMAK \m/!"+bcolors.ENDC)
# two third, mid, geri 2x, geri x, düz
elif 0:
if stage1:
if park_distance > 8:
print("TWO THIRD PARK")
target_diff = (twothird - park_coordinate) / 1700
steer = (target_diff + 0.5) * 3600
mahmut.adc0 = 25
mahmut.adc1 = int(steer)
mahmut.adc2 = 0
mahmut.adc3 = FORWARD
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
if distances['on'] < 3.5:
stage1 = False
stage2 = True
elif stage2:
mahmut.adc0 = 25
mahmut.adc1 = FULL_LEFT
mahmut.adc2 = 0
mahmut.adc3 = REVERSE
mahmut.adc4 = True
mahmut.adc5 = int(driving_mode)
if distances['on'] < 6.0:
stage2 = False
stage3 = True
elif stage3: