diff --git a/src/pi/temp_sensor/temp_sensor/temp_sensor.py b/src/pi/temp_sensor/temp_sensor/temp_sensor.py index 503617ce..936bafa4 100644 --- a/src/pi/temp_sensor/temp_sensor/temp_sensor.py +++ b/src/pi/temp_sensor/temp_sensor/temp_sensor.py @@ -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() diff --git a/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py b/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py index bb7dc2ce..debb5eea 100644 --- a/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py +++ b/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py @@ -1,5 +1,6 @@ -import tsys01 -# https://github.com/bluerobotics/tsys01-python +from time import sleep + +import tsys01 # https://github.com/bluerobotics/tsys01-python def debug_log() -> None: @@ -7,9 +8,14 @@ def debug_log() -> None: 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__": diff --git a/src/rov_msgs/CMakeLists.txt b/src/rov_msgs/CMakeLists.txt index 786534e4..422f3034 100644 --- a/src/rov_msgs/CMakeLists.txt +++ b/src/rov_msgs/CMakeLists.txt @@ -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" diff --git a/src/rov_msgs/msg/Temperature.msg b/src/rov_msgs/msg/Temperature.msg new file mode 100644 index 00000000..72f08d4c --- /dev/null +++ b/src/rov_msgs/msg/Temperature.msg @@ -0,0 +1 @@ +float64 reading \ No newline at end of file