Skip to content

Commit

Permalink
Merge branch 'temp-sensor' of github.com:cwruRobotics/rov-24 into tem…
Browse files Browse the repository at this point in the history
…p-sensor
  • Loading branch information
ROV Laptop committed Jun 8, 2024
2 parents b76c37c + 68c888e commit bd2e794
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
31 changes: 15 additions & 16 deletions src/pi/temp_sensor/temp_sensor/temp_sensor.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import rclpy
from rclpy.node import Node
from rov_msgs.msg import Temperature

# Pins used for GPIO
DETECT_PIN = 17
import tsys01


class FloodDetector(Node):
class TempSensor(Node):

def __init__(self) -> None:
super().__init__('gpio_reader', parameter_overrides=[])
self.publisher = self.create_publisher(Flooding, 'flooding', 10)
self.gpio_chip = lgpio.gpiochip_open(0)
lgpio.gpio_claim_input(self.gpio_chip, DETECT_PIN)
super().__init__('temp_sensor', parameter_overrides=[])
self.publisher = self.create_publisher(Temperature, 'temperature', 10)
self.sensor = tsys01.TSYS01()
self.sensor.init()

timer_period = 0.1 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)

def timer_callback(self) -> None:
# If any of the sensors detect water, send true to /tether/flooding
flood_reading = lgpio.gpio_read(self.gpio_chip, DETECT_PIN)
self.sensor.read()
temp_reading = self.sensor.temperature()

# If any of the sensors detect water, send true to /tether/flooding
msg = Flooding()
msg.flooding = (flood_reading == lgpio.HIGH)
if msg.flooding:
self.get_logger().error("The ebay is flooding")
msg = Temperature()
msg.reading = temp_reading
self.publisher.publish(msg)


def main(args: None = None) -> None:
rclpy.init()
flood_detector = FloodDetector()
rclpy.spin(flood_detector)
flood_detector.destroy_node()
temp_sensor = TempSensor()
rclpy.spin(temp_sensor)
temp_sensor.destroy_node()
rclpy.shutdown()


Expand Down
16 changes: 11 additions & 5 deletions src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import tsys01
# https://github.com/bluerobotics/tsys01-python
from time import sleep

import tsys01 # https://github.com/bluerobotics/tsys01-python


def debug_log() -> None:
sensor = tsys01.TSYS01() # Use default I2C bus 1

sensor.init()

sensor.read()

sensor.temperature() # Get temperature in default units (Centigrade)
while True:
sensor.read()
print(
sensor.temperature(), # Get temperature in default units (Centigrade)
'\t',
sensor.temperature(tsys01.UNITS_Farenheit)
)
sleep(1)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions src/rov_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Manip.msg"
"msg/CameraControllerSwitch.msg"
"msg/Flooding.msg"
"msg/Temperature.msg"
"msg/IPAddress.msg"
"msg/VehicleState.msg"
"msg/ValveManip.msg"
Expand Down
1 change: 1 addition & 0 deletions src/rov_msgs/msg/Temperature.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
float64 reading

0 comments on commit bd2e794

Please sign in to comment.