create relais control node
This commit is contained in:
Submodule src/px4_msgs updated: ffc3a4cd57...b64ef0475c
@@ -3,9 +3,10 @@
|
|||||||
<package format="3">
|
<package format="3">
|
||||||
<name>relais_control</name>
|
<name>relais_control</name>
|
||||||
<version>0.0.0</version>
|
<version>0.0.0</version>
|
||||||
<description>TODO: Package description</description>
|
<description>package to control the relais that enables Pixhawk RX and TX communication</description>
|
||||||
<maintainer email="semmer99@gmail.com">ubuntu</maintainer>
|
<maintainer email="semmer99@gmail.com">ubuntu</maintainer>
|
||||||
<license>TODO: License declaration</license>
|
<license>Apache License 2.0</license>
|
||||||
|
<exec_depend>rclpy</exec_depend>
|
||||||
|
|
||||||
<test_depend>ament_copyright</test_depend>
|
<test_depend>ament_copyright</test_depend>
|
||||||
<test_depend>ament_flake8</test_depend>
|
<test_depend>ament_flake8</test_depend>
|
||||||
|
|||||||
48
src/relais_control/relais_control/relais_controller.py
Normal file
48
src/relais_control/relais_control/relais_controller.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import rclpy
|
||||||
|
from rclpy.node import Node
|
||||||
|
try:
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
except RuntimeError:
|
||||||
|
print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")
|
||||||
|
|
||||||
|
class RelaisController(Node):
|
||||||
|
def __init(self):
|
||||||
|
super().__init__('relais_controller')
|
||||||
|
self.relais1_pin = 17
|
||||||
|
self.relais2_pin = 27
|
||||||
|
self.init_gpio()
|
||||||
|
self.turn_relais_on()
|
||||||
|
|
||||||
|
def init_gpio(self):
|
||||||
|
GPIO.setwarnings(False)
|
||||||
|
|
||||||
|
self.get_logger().info(GPIO.RPI_INFO)
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
GPIO.setup(self.relais1_pin, GPIO.OUT)
|
||||||
|
GPIO.setup(self.relais2_pin, GPIO.OUT)
|
||||||
|
self.get_logger().info("GPIO initialized")
|
||||||
|
|
||||||
|
def turn_relais_on(self):
|
||||||
|
GPIO.output(self.relais1_pin, GPIO.HIGH)
|
||||||
|
GPIO.output(self.relais2_pin, GPIO.HIGH)
|
||||||
|
self.get_logger().info("Relais turned on")
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=None):
|
||||||
|
rclpy.init(args=args)
|
||||||
|
|
||||||
|
relais_controller = RelaisController()
|
||||||
|
|
||||||
|
relais_controller.spin()
|
||||||
|
|
||||||
|
# Destroy the node explicitly
|
||||||
|
# (optional - otherwise it will be done automatically
|
||||||
|
# when the garbage collector destroys the node object)
|
||||||
|
relais_controller.destroy_node()
|
||||||
|
rclpy.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -20,6 +20,7 @@ setup(
|
|||||||
tests_require=['pytest'],
|
tests_require=['pytest'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
'relais_controller = relais_control.relais_controller:main'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user