-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Activate/Deactivate RPi depending on learning mode
- Loading branch information
Showing
2 changed files
with
62 additions
and
14 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,60 @@ | ||
#!/usr/bin/env python | ||
|
||
# fans_manager.py | ||
# Copyright (C) 2017 Niryo | ||
# All rights reserved. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import rospy | ||
from std_msgs.msg import Bool | ||
|
||
import RPi.GPIO as GPIO | ||
|
||
FAN_1_GPIO = 27 | ||
FAN_2_GPIO = 23 | ||
|
||
class FansManager: | ||
|
||
def setup_fans(self): | ||
GPIO.setwarnings(False) | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setup(FAN_1_GPIO, GPIO.OUT) | ||
GPIO.setup(FAN_2_GPIO, GPIO.OUT) | ||
rospy.sleep(0.05) | ||
rospy.loginfo("------ RPI FANS SETUP OK ------") | ||
|
||
def set_fans(self, activate): | ||
if activate: | ||
GPIO.output(FAN_1_GPIO, GPIO.HIGH) | ||
GPIO.output(FAN_2_GPIO, GPIO.HIGH) | ||
else: | ||
GPIO.output(FAN_1_GPIO, GPIO.LOW) | ||
GPIO.output(FAN_2_GPIO, GPIO.LOW) | ||
|
||
def __init__(self): | ||
self.setup_fans() | ||
self.learning_mode_on = True | ||
self.set_fans(not self.learning_mode_on) | ||
|
||
self.learning_mode_subscriber = rospy.Subscriber( | ||
'/niryo_one/learning_mode', Bool, self.callback_learning_mode) | ||
|
||
|
||
def callback_learning_mode(self, msg): | ||
if msg.data != self.learning_mode_on: | ||
self.learning_mode_on = msg.data | ||
self.set_fans(not self.learning_mode_on) | ||
|
||
|
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