-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f115551
commit 9123b81
Showing
4 changed files
with
191 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
https://github.com/LouisKimDev/AutoAC | ||
|
||
- master.py | ||
- 라즈베리파이의 GPIO 라이브러리 이용 | ||
- 서보모터 stop시 떨림현상 | ||
- GPIO를 IN으로 설정해서 해결 | ||
|
||
- 3시간마다 4분 대기하고 메인 전원을 켠다 | ||
- Time함수로 현재 시간 받는다 | ||
- 30분을 기다린뒤 test모드를 켠다 | ||
- 중복을 막기위해 매 30분 마다 20초씩 누적해서 대기한다 | ||
|
||
|
||
- test.py | ||
- pigpio 라이브러리 이용 | ||
- 서보모터 Idle시 안정적 | ||
- 함수 각도 테스트 필요 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import RPi.GPIO as GPIO | ||
import time | ||
|
||
''' | ||
duty clycle (degree) | ||
10 : 160 | ||
7.5 : 120 | ||
5 : 80 | ||
2.5 : 40 | ||
''' | ||
|
||
class motorz: | ||
def __init__(self): | ||
self.SERVO_1 = 18 | ||
self.SERVO_2 = 23 | ||
self.MOVE_TIME = 0.3 | ||
self.COUNT = 1 | ||
|
||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setup(self.SERVO_1, GPIO.OUT) | ||
GPIO.setup(self.SERVO_2, GPIO.OUT) | ||
self.pwm1 = GPIO.PWM(self.SERVO_1, 50) | ||
self.pwm2 = GPIO.PWM(self.SERVO_2, 50) | ||
self.pwm1.start(0) | ||
self.pwm2.start(0) | ||
GPIO.setwarnings(False) | ||
|
||
|
||
def Servo1Routine(self, iterations): | ||
GPIO.setup(self.SERVO_1, GPIO.OUT) | ||
for i in range(iterations): | ||
self.pwm1.ChangeDutyCycle(7.5) | ||
time.sleep(self.MOVE_TIME) | ||
self.pwm1.ChangeDutyCycle(10) | ||
time.sleep(self.MOVE_TIME) | ||
|
||
self.pwm1.ChangeDutyCycle(7.5) | ||
time.sleep(self.MOVE_TIME) | ||
GPIO.setup(self.SERVO_1, GPIO.IN) | ||
print(f'servo1 activated for {iterations} times') | ||
|
||
|
||
def Servo2Routine(self, iterations): | ||
for i in range(iterations): | ||
GPIO.setup(self.SERVO_2, GPIO.OUT) | ||
self.pwm2.ChangeDutyCycle(7.5) | ||
time.sleep(self.MOVE_TIME) | ||
self.pwm2.ChangeDutyCycle(10) | ||
time.sleep(self.MOVE_TIME) | ||
|
||
self.pwm2.ChangeDutyCycle(7.5) | ||
time.sleep(self.MOVE_TIME) | ||
GPIO.setup(self.SERVO_2, GPIO.IN) | ||
print(f'servo2 activated for {iterations} times') | ||
|
||
|
||
def PrintTime(self): | ||
print(time.strftime('%H:%M:%S')) | ||
|
||
|
||
def test(self): | ||
try: | ||
while True: | ||
if time.localtime().tm_sec % 1 == 0: | ||
print('test routine start') | ||
|
||
self.Servo1Routine(1) | ||
self.Servo2Routine(4) | ||
|
||
print('test routine ended') | ||
|
||
except KeyboardInterrupt: | ||
self.pwm1.stop() | ||
self.pwm2.stop() | ||
print('End') | ||
GPIO.cleanup() | ||
|
||
|
||
def main(self): | ||
try: | ||
while True: | ||
if (time.localtime().tm_hour == \ | ||
23 or 2 or 3 or 8 or 11 or 14 or 17 or 20) \ | ||
and time.localtime().tm_min == 0 : | ||
|
||
time.sleep(240) | ||
|
||
self.PrintTime() | ||
self.Servo1Routine(1) # 00:04:00 | ||
self.Servo2Routine(4) | ||
time.sleep(1820) | ||
|
||
self.PrintTime() | ||
self.Servo2Routine(4) # 00:34:20 | ||
time.sleep(1840) | ||
|
||
self.PrintTime() | ||
self.Servo2Routine(4) # 01:05:00 | ||
time.sleep(1860) | ||
|
||
self.PrintTime() | ||
self.Servo2Routine(4) # 01:36:00 | ||
time.sleep(1880) | ||
|
||
self.PrintTime() | ||
self.Servo2Routine(4) # 02:07:20 | ||
time.sleep(1900) | ||
|
||
self.PrintTime() | ||
self.Servo2Routine(4) # 02:39:00 | ||
|
||
# print('3hr routine ended') | ||
|
||
# elif time.localtime().tm_min % 30 == 0 and \ | ||
# time.localtime().tm_sec == 0: | ||
|
||
# self.PrintTime() | ||
# time.sleep(240 + self.COUNT * 20) | ||
|
||
# self.Servo2Routine(4) | ||
|
||
# self.COUNT += 1 | ||
|
||
# print('30min routine ended') | ||
|
||
except KeyboardInterrupt: | ||
self.pwm1.stop() | ||
self.pwm2.stop() | ||
print('End') | ||
GPIO.cleanup() | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
a = motorz() | ||
a.main() | ||
else: | ||
print('Excution Failed') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pigpio | ||
import time | ||
|
||
# pigpio 라이브러리를 이용 | ||
''' | ||
set_servo_pulsewidth(user_gpio, pulsewidth) | ||
Parameter: | ||
1. user_gpio = 0~31 | ||
2. pulsewidth = 0(off), 500(0-degree) ~ 2500(180-degree) | ||
pulsewidth를 500, 2500로 쓰면 서보모터에 데미지 줄 수 있다. | ||
그래서 600 ~ 2400사이 권장 | ||
각도 공식 | ||
f(x) = 600 + 10x | ||
''' | ||
|
||
pi = pigpio.pi() | ||
pi.set_servo_pulsewidth(18, 0) # 18번 채널에연결된 서보모터를 꺼줍니다. | ||
|
||
sleep(1) | ||
|
||
pi.set_servo_pulsewidth(18, 500) # 18번채널에 연결된 서보모터를 0도로 이동 | ||
|
||
sleep(1) | ||
|
||
pi.set_servo_pulsewidth(18, 1500) # 가운데로 이동 90도 | ||
|
||
sleep(1) | ||
|
||
pi.set_servo_pulsewidth(18, 2500) # 180도 끝으로 이동. | ||
|
||
sleep(1) |