Skip to content

Commit 5d9e677

Browse files
committed
haftalik degisim
0 parents  commit 5d9e677

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+12216
-0
lines changed

Button.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import RPi.GPIO as GPIO
2+
from time import sleep
3+
GPIO.setmode(GPIO.BCM)
4+
5+
BUTTON = 12
6+
LED = 20
7+
GPIO.setup(BUTTON, GPIO.IN)
8+
GPIO.setup(LED, GPIO.OUT)
9+
GPIO.output(LED, GPIO.LOW)
10+
11+
try:
12+
while True:
13+
GPIO.wait_for_edge(BUTTON, GPIO.RISING)
14+
GPIO.output(LED, GPIO.HIGH)
15+
sleep(2)
16+
GPIO.output(LED, GPIO.LOW)
17+
except KeyboardInterrupt:
18+
GPIO.output(LED, GPIO.LOW)
19+
GPIO.cleanup()
20+
raise
1.83 KB
Binary file not shown.
866 Bytes
Binary file not shown.

__pycache__/config.cpython-310.pyc

369 Bytes
Binary file not shown.
4.09 KB
Binary file not shown.
8.74 KB
Binary file not shown.

__pycache__/game.cpython-310.pyc

3.11 KB
Binary file not shown.
Binary file not shown.

cardreader.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from time import sleep, time
2+
import sys
3+
from mfrc522 import SimpleMFRC522
4+
import RPi.GPIO as GPIO
5+
6+
readers = []
7+
poll_list = list()
8+
curr_poll_list = list()
9+
RESET_PIN = 21 # In BCM pin number. See: https://pinout.xyz
10+
11+
12+
def read_init():
13+
rfid_count = 18
14+
for i in range(0, rfid_count):
15+
poll_list.append(i)
16+
curr_poll_list = poll_list.copy()
17+
18+
GPIO.setmode(GPIO.BCM)
19+
20+
for i in range(0, rfid_count):
21+
# Parameters are bus and device number respectively. Device number is allias to
22+
# Chip Select (Slave Select) in SPI Protocol.
23+
# /dev/spidev<bus>.<device>
24+
# Pin association to the device numbers configured by device tree object.
25+
# See: /home/alarm/spi-cs-extend.dts
26+
# See: https://gist.github.com/mcbridejc/d060602e892f6879e7bc8b93aa3f85be
27+
readers.append(SimpleMFRC522(0, i, 800000))
28+
29+
# Its recommended to reset MFRC522 after each polling. Pulling Reset_Pin to low
30+
# (by setting the ping to low mode in out settings) turns off the sensors until
31+
# the pin is high again.
32+
GPIO.setup(RESET_PIN, GPIO.OUT)
33+
34+
GPIO.output(RESET_PIN, GPIO.LOW)
35+
sleep(0.01)
36+
37+
GPIO.output(RESET_PIN, GPIO.HIGH)
38+
sleep(0.01)
39+
40+
41+
def read_process():
42+
reads = dict()
43+
poll_duration_in_s = 2.5
44+
try:
45+
# One-shot reads might miss. So its better to poll multiple times.
46+
old_time = 0
47+
total_read = 0
48+
while True:
49+
if time() - old_time < poll_duration_in_s:
50+
for i, v in enumerate(curr_poll_list):
51+
readers[v].READER.MFRC522_Init();
52+
# print(v)
53+
id, text = readers[v].read_no_block()
54+
if id:
55+
reads[v + 1] = id
56+
txt = "0x001"
57+
#readers[v].write(txt) # RFID TAg eklemek istersek bu komutu çalýþtýracaðýz.
58+
curr_poll_list.remove(v)
59+
print("%d ID: %s %s" % (i, id, text))
60+
61+
#print(list(str(text).encode('ascii')))
62+
total_read += 1
63+
# print(curr_poll_list)
64+
65+
else:
66+
if total_read != 0:
67+
return reads
68+
for number, id in sorted(reads.items()):
69+
print("RFID NUMBER: %d KEY ID: %d" % (number, id))
70+
71+
reads.clear()
72+
print("Total Read = %d.\tReading the devices..." % (total_read))
73+
total_read = 0
74+
old_time = time()
75+
curr_poll_list = poll_list.copy()
76+
GPIO.output(RESET_PIN, GPIO.LOW)
77+
sleep(0.05)
78+
79+
GPIO.output(RESET_PIN, GPIO.HIGH)
80+
sleep(0.05)
81+
82+
83+
except KeyboardInterrupt:
84+
GPIO.cleanup()
85+
raise
86+
87+
88+
def to_ascii(text):
89+
ascii_values = [ord(character) for character in text]
90+
return ascii_values

cardreader2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from time import sleep, time
2+
3+
def read_process():
4+
# Resim kimlik kartları listesi
5+
resim_id_listesi = [1, 2, 3, 4, 5]
6+
7+
try:
8+
reads = dict()
9+
for i in range(5):
10+
resim_id = resim_id_listesi[i]
11+
reads[i] = resim_id
12+
return reads
13+
14+
except KeyboardInterrupt:
15+
raise
16+
17+
if __name__ == "__main__":
18+
reads = read_process()
19+
print("reads:", reads)
20+

cemgame.service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Service for the game
3+
4+
[Install]
5+
WantedBy=multi-user.target
6+
7+
[Service]
8+
User=root
9+
Type=simple
10+
ExecStart=/usr/bin/python3 /home/alarm/project/src/main.py
11+
WorkingDirectory=/home/alarm/project/src
12+
Restart=always
13+
RestartSec=5

config.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cfg = {
2+
########### ROTATION ###########
3+
# Initialization configuration.
4+
# pitch_degree is the degree from which the pitch will be rotated down to.
5+
"pitch_degree": 13,
6+
########### ROTATION ###########
7+
# Rotations to right or left, clockwise or counter-clockwise in respectively.
8+
# rotate_degree controls the degree of the turn.
9+
# rotate_speed controls the speed in degrees of the turn.
10+
"rotate_degree": 90,
11+
"rotate_speed": 90,
12+
"yaw_speed": 120,
13+
14+
########### MOVING ###########
15+
# Movement to forward, backward, left, right or fastforward.
16+
# "move_distance" in meters to control the distance.
17+
# "move_gain" will be added to move_distance to calculate final distance to be inputted to robot.
18+
# Change it to particularize for different surfaces.
19+
# "move_speed" controls the speed for forward, backward, left and right movements.
20+
# "move_fastspeed" controls the speed for fastforward.
21+
"move_distance": 0.75,
22+
"move_gain": 0.05,
23+
"move_speed": 1,
24+
"move_fastspeed": 1,
25+
26+
########### DANCE ###########
27+
# Dance movement. Dance movement rotates chassis to right and left repeatedly in place.
28+
# The dance will start with an half of the specified degree to a side then will be followed by
29+
# full degree rotations back and forth. To finish at the center, a final half degree movement will
30+
# be made.
31+
# "dance_angle" specifies the full degree of the dance movement. The half degree wil be calculated not specified.
32+
# "dance_speed" is the speed in degrees in which all the rotation will be made.
33+
# "dance_iter" is the number of full degree iterations.
34+
"dance_angle": 90,
35+
"dance_speed": 120,
36+
"dance_iter": 4,
37+
}
38+

controller.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import time
2+
import curses
3+
from robomaster import robot,config,chassis,gimbal,blaster,led
4+
from game import *
5+
from config import cfg
6+
import pygame
7+
8+
ep_robot = robot.Robot()
9+
ep_chassis : chassis.Chassis
10+
ep_gimbal : gimbal.Gimbal
11+
ep_blaster : blaster.Blaster
12+
ep_led : led.Led
13+
14+
15+
16+
pitch_degree = cfg["pitch_degree"]
17+
def controller_con_test():
18+
if ep_robot.get_version() is None:
19+
exit(1)
20+
21+
def controller_init():
22+
global ep_chassis
23+
global ep_gimbal
24+
global ep_blaster
25+
global ep_led
26+
if not ep_robot.initialize(conn_type="sta", proto_type='udp'):
27+
print("Robot initialization failed")
28+
exit(1)
29+
#ep_robot.initialize(conn_type="sta", proto_type='udp')
30+
ep_chassis = ep_robot.chassis
31+
ep_gimbal = ep_robot.gimbal
32+
ep_blaster = ep_robot.blaster
33+
ep_led = ep_robot.led
34+
ep_led.set_led(r=0,g=0,b=255)
35+
# move pitch to the max
36+
# ep_gimbal.move(pitch=120, pitch_speed=90).wait_for_completed()
37+
# get it down to a certain degree
38+
ep_gimbal.moveto(yaw=0, pitch=pitch_degree, pitch_speed=90, yaw_speed=90).wait_for_completed()
39+
controller_sound(2)
40+
ep_led.set_led(r=255,g=255,b=0)
41+
42+
#Upload sound files
43+
# upload_file = "/python/sdk_audio_9.wav"
44+
# ep_robot._ftp.upload("gameover.wav", upload_file)
45+
# ep_robot.play_sound(0xE0 + 9, times=1).wait_for_completed()
46+
47+
# ep_robot._audio_id = (ep_robot._audio_id + 1) % 10
48+
# upload_file = "/python/sdk_audio_{0}.wav".format(ep_robot._audio_id)
49+
# ep_robot._ftp.upload(filename, upload_file)
50+
# logger.info("upload file {0} to target {1}".format(filename, upload_file))
51+
# sound_id = 0xE0 + (ep_robot._audio_id % 10)
52+
53+
54+
### Actions ###
55+
56+
def controller_test():
57+
for i in range(25):
58+
print(i)
59+
time.sleep(1)
60+
controller_sound(i)
61+
# controller_fire()
62+
pass
63+
# controller_dance()
64+
# controller_crotate()
65+
# controller_sound()
66+
# controller_crotate()
67+
# controller_sound()
68+
# controller_powerforward()
69+
# controller_fire()
70+
# pass
71+
72+
def controller_close():
73+
ep_robot.close()
74+
75+
def _controller_brake():
76+
ep_chassis.drive_wheels(w1=0, w2=0, w3=0, w4=0)
77+
78+
rotate_degree = cfg["rotate_degree"]
79+
rotate_speed = cfg["rotate_speed"]
80+
yaw_speed = cfg["yaw_speed"]
81+
82+
# clockwise rotate
83+
def controller_rotate():
84+
ep_chassis.move(z=-rotate_degree,z_speed=rotate_speed).wait_for_completed()
85+
ep_gimbal.move(yaw=rotate_degree,yaw_speed=yaw_speed).wait_for_completed()
86+
87+
# counter-clockwise rotate
88+
def controller_crotate():
89+
ep_chassis.move(z=rotate_degree,z_speed=rotate_speed).wait_for_completed()
90+
ep_gimbal.move(yaw=-rotate_degree,yaw_speed=yaw_speed).wait_for_completed()
91+
92+
move_distance = cfg["move_distance"] + cfg["move_gain"]
93+
move_speed = cfg["move_speed"]
94+
move_fastspeed = cfg["move_fastspeed"]
95+
96+
def controller_forward():
97+
ep_chassis.move(x=move_distance,xy_speed=move_speed).wait_for_completed()
98+
_controller_brake()
99+
100+
def controller_backward():
101+
ep_chassis.move(x=-move_distance,xy_speed=move_speed).wait_for_completed()
102+
_controller_brake()
103+
104+
def controller_left():
105+
ep_chassis.move(y=-move_distance,xy_speed=move_speed).wait_for_completed()
106+
_controller_brake()
107+
108+
def controller_right():
109+
ep_chassis.move(y=move_distance,xy_speed=move_speed).wait_for_completed()
110+
_controller_brake()
111+
112+
def controller_fastforward():
113+
ep_chassis.move(x=move_distance,xy_speed=move_fastspeed).wait_for_completed()
114+
_controller_brake()
115+
116+
dance_angle = cfg["dance_angle"]
117+
dance_half_angle = dance_angle / 2
118+
dance_speed = cfg["dance_speed"]
119+
dance_iter = cfg["dance_iter"]
120+
121+
def controller_dance():
122+
# ep_chassis.move(z=-90,z_speed=120)
123+
# ep_gimbal.move(yaw=-90,yaw_speed=120)
124+
ep_robot.play_audio("destiny.wav")
125+
#
126+
pygame.mixer.init()
127+
pygame.mixer.music.load("destiny.wav")
128+
pygame.mixer.music.play()
129+
while pygame.mixer.music.get_busy():
130+
continue
131+
#
132+
ep_led.set_led(r=255,g=0,b=255,effect="flash")
133+
ep_chassis.move(z=dance_half_angle,z_speed=dance_speed).wait_for_completed()
134+
for _ in range(dance_iter):
135+
ep_chassis.move(z=-dance_angle,z_speed=dance_speed).wait_for_completed()
136+
ep_chassis.move(z=dance_angle,z_speed=dance_speed).wait_for_completed()
137+
ep_chassis.move(z=-dance_half_angle,z_speed=dance_speed).wait_for_completed()
138+
time.sleep(2)
139+
ep_led.set_led(r=255,g=255,b=0)
140+
141+
# ep_gimbal.move(yaw=45,yaw_speed=120).wait_for_completed()
142+
# for _ in range(3):
143+
# ep_gimbal.move(yaw=-90,yaw_speed=120).wait_for_completed()
144+
# ep_gimbal.move(yaw=90,yaw_speed=120).wait_for_completed()
145+
# ep_gimbal.move(yaw=-45,yaw_speed=120).wait_for_completed()
146+
147+
# ep_gimbal.move(yaw=, yaw_speed=120)
148+
# robot_ctrl.set_mode(rm_define.robot_mode_free)
149+
# chassis_ctrl.set_rotate_speed(120)
150+
# gimbal_ctrl.set_rotate_speed(120)
151+
# gun_ctrl.fire_continuous()
152+
# # while True:
153+
154+
# gimbal_ctrl.rotate(rm_define.gimbal_right)
155+
# chassis_ctrl.rotate_with_time(rm_define.anticlockwise, 0.2)
156+
# gimbal_ctrl.rotate(rm_define.gimbal_left)
157+
# chassis_ctrl.rotate_with_time(rm_define.clockwise, 0.4)
158+
# gimbal_ctrl.rotate(rm_define.gimbal_right)
159+
# chassis_ctrl.rotate_with_time(rm_define.anticlockwise, 0.2)
160+
pass
161+
162+
def controller_music():
163+
ep_robot.play_audio("shark.wav").wait_for_completed()
164+
pass
165+
166+
def controller_sound(sound_id):
167+
ep_robot.play_sound(sound_id, times=1).wait_for_completed()
168+
169+
def controller_fire():
170+
ep_led.set_led(r=255,g=0,b=0)
171+
for i in [8, 15, 25]:
172+
for j in [-20, 0, 20]:
173+
ep_gimbal.moveto(yaw=j, pitch=i, pitch_speed=90, yaw_speed=90).wait_for_completed()
174+
ep_blaster.fire()
175+
ep_gimbal.moveto(yaw=0, pitch=pitch_degree, pitch_speed=90, yaw_speed=90).wait_for_completed()
176+
ep_led.set_led(r=255,g=255,b=0)
177+

0 commit comments

Comments
 (0)